Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[CLI] Update CLI with Log command #453

Merged
merged 4 commits into from
Sep 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion tools/tkn-results/cmd/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ func ListCommand(params *flags.Params) *cobra.Command {
Short: "List Results",
RunE: func(cmd *cobra.Command, args []string) error {

resp, err := params.Client.ListResults(cmd.Context(), &pb.ListResultsRequest{
resp, err := params.ResultsClient.ListResults(cmd.Context(), &pb.ListResultsRequest{
Parent: args[0],
Filter: opts.Filter,
PageSize: opts.Limit,
Expand Down
59 changes: 59 additions & 0 deletions tools/tkn-results/cmd/logs/get_log.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
// Copyright 2023 The Tekton Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package logs

import (
"fmt"
"os"

"github.com/spf13/cobra"
pb "github.com/tektoncd/results/proto/v1alpha2/results_go_proto"
"github.com/tektoncd/results/tools/tkn-results/internal/flags"
"github.com/tektoncd/results/tools/tkn-results/internal/format"
)

func GetLogCommand(params *flags.Params) *cobra.Command {
opts := &flags.GetOptions{}

cmd := &cobra.Command{
Use: `get [flags] <log>

<log path>: Log full name to query. This is typically "<namespace>/results/<result name>/logs/<log name>".`,
Short: "Get Log",
RunE: func(cmd *cobra.Command, args []string) error {
resp, err := params.LogsClient.GetLog(cmd.Context(), &pb.GetLogRequest{
Name: args[0],
})
if err != nil {
fmt.Printf("GetLog: %v\n", err)
return err
}
data, err := resp.Recv()
if err != nil {
fmt.Printf("Get Log Client Resp: %v\n", err)
return err
khrm marked this conversation as resolved.
Show resolved Hide resolved
}
return format.PrintProto(os.Stdout, data, opts.Format)
},
Args: cobra.ExactArgs(1),
Annotations: map[string]string{
"commandType": "main",
},
}

flags.AddGetFlags(opts, cmd)

return cmd
}
57 changes: 57 additions & 0 deletions tools/tkn-results/cmd/logs/list.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
// Copyright 2023 The Tekton Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package logs

import (
"fmt"
"os"

"github.com/spf13/cobra"
pb "github.com/tektoncd/results/proto/v1alpha2/results_go_proto"
"github.com/tektoncd/results/tools/tkn-results/internal/flags"
"github.com/tektoncd/results/tools/tkn-results/internal/format"
)

func ListCommand(params *flags.Params) *cobra.Command {
opts := &flags.ListOptions{}

cmd := &cobra.Command{
Use: `list [flags] <result parent>

<result parent>: Result parent name to query. This is typically "<namespace>/results/<result name>", but may vary depending on the API Server. "-" may be used as <result name> to query all Logs for a given parent.`,
Short: "List Logs",
RunE: func(cmd *cobra.Command, args []string) error {
resp, err := params.LogsClient.ListLogs(cmd.Context(), &pb.ListRecordsRequest{
Parent: args[0],
Filter: opts.Filter,
PageSize: opts.Limit,
PageToken: opts.PageToken,
})
if err != nil {
fmt.Printf("List Logs: %v\n", err)
return err
}
return format.PrintProto(os.Stdout, resp, opts.Format)
},
Args: cobra.ExactArgs(1),
Annotations: map[string]string{
"commandType": "main",
},
}

flags.AddListFlags(opts, cmd)

return cmd
}
34 changes: 34 additions & 0 deletions tools/tkn-results/cmd/logs/logs.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
// Copyright 2023 The Tekton Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package logs

import (
"github.com/spf13/cobra"
"github.com/tektoncd/results/tools/tkn-results/internal/flags"
)

func Command(params *flags.Params) *cobra.Command {
cmd := &cobra.Command{
Use: "logs",
Short: "Commands for finding and retrieving logs",
Annotations: map[string]string{
"commandType": "main",
},
}

cmd.AddCommand(ListCommand(params), GetLogCommand(params))

return cmd
}
54 changes: 54 additions & 0 deletions tools/tkn-results/cmd/records/get_record.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
// Copyright 2023 The Tekton Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package records

import (
"fmt"
"os"

"github.com/spf13/cobra"
pb "github.com/tektoncd/results/proto/v1alpha2/results_go_proto"
"github.com/tektoncd/results/tools/tkn-results/internal/flags"
"github.com/tektoncd/results/tools/tkn-results/internal/format"
)

func GetRecordCommand(params *flags.Params) *cobra.Command {
opts := &flags.GetOptions{}

cmd := &cobra.Command{
Use: `get [flags] <record_path>

<record name>: Fully qualified name of the record. This is typically "<namespace>/results/<result name>/records/<record uid>".`,
Short: "Get Record",
RunE: func(cmd *cobra.Command, args []string) error {
resp, err := params.ResultsClient.GetRecord(cmd.Context(), &pb.GetRecordRequest{
Name: args[0],
})
if err != nil {
fmt.Printf("GetRecord: %v\n", err)
return err
}
return format.PrintProto(os.Stdout, resp, opts.Format)
},
Args: cobra.ExactArgs(1),
Annotations: map[string]string{
"commandType": "main",
},
}

flags.AddGetFlags(opts, cmd)

return cmd
}
2 changes: 1 addition & 1 deletion tools/tkn-results/cmd/records/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ func ListCommand(params *flags.Params) *cobra.Command {
<result parent>: Result parent name to query. This is typically "<namespace>/results/<result name>", but may vary depending on the API Server. "-" may be used as <result name> to query all Results for a given parent.`,
Short: "List Records",
RunE: func(cmd *cobra.Command, args []string) error {
resp, err := params.Client.ListRecords(cmd.Context(), &pb.ListRecordsRequest{
resp, err := params.ResultsClient.ListRecords(cmd.Context(), &pb.ListRecordsRequest{
Parent: args[0],
Filter: opts.Filter,
PageSize: opts.Limit,
Expand Down
2 changes: 1 addition & 1 deletion tools/tkn-results/cmd/records/records.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ func Command(params *flags.Params) *cobra.Command {
},
}

cmd.AddCommand(ListCommand(params))
cmd.AddCommand(ListCommand(params), GetRecordCommand(params))

return cmd
}
15 changes: 12 additions & 3 deletions tools/tkn-results/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"github.com/spf13/cobra"
"github.com/spf13/pflag"
"github.com/spf13/viper"
"github.com/tektoncd/results/tools/tkn-results/cmd/logs"
"github.com/tektoncd/results/tools/tkn-results/cmd/records"
"github.com/tektoncd/results/tools/tkn-results/internal/client"
"github.com/tektoncd/results/tools/tkn-results/internal/config"
Expand Down Expand Up @@ -51,13 +52,21 @@ func Root() *cobra.Command {
}
}

apiClient, err := client.DefaultClient(cmd.Context(), overrideApiAdr)
apiClient, err := client.DefaultResultsClient(cmd.Context(), overrideApiAdr)

if err != nil {
return err
}

params.Client = apiClient
params.ResultsClient = apiClient

logClient, err := client.DefaultLogsClient(cmd.Context(), overrideApiAdr)

if err != nil {
return err
}

params.LogsClient = logClient

return nil
},
Expand All @@ -78,7 +87,7 @@ func Root() *cobra.Command {
cmd.PersistentFlags().Bool("portforward", true, "enable auto portforwarding to tekton-results-api-service, when addr is set and portforward is true, tkn-results will portforward tekton-results-api-service automatically")
cmd.PersistentFlags().Bool("insecure", false, "determines whether to run insecure GRPC tls request")

cmd.AddCommand(ListCommand(params), records.Command(params))
cmd.AddCommand(ListCommand(params), records.Command(params), logs.Command(params))

pflag.CommandLine.AddGoFlagSet(flag.CommandLine)
viper.BindPFlags(cmd.PersistentFlags())
Expand Down
3 changes: 2 additions & 1 deletion tools/tkn-results/docs/tkn-results.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ Config:
### SEE ALSO

* [tkn-results list](tkn-results_list.md) - List Results
* [tkn-results logs](tkn-results_logs.md) - Commands for finding and retrieving logs
* [tkn-results records](tkn-results_records.md) - Command sub-group for querying Records

###### Auto generated by spf13/cobra on 31-Aug-2023
###### Auto generated by spf13/cobra on 4-Sep-2023
2 changes: 1 addition & 1 deletion tools/tkn-results/docs/tkn-results_list.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,4 @@ tkn-results list [flags] <parent>

* [tkn-results](tkn-results.md) - tkn CLI plugin for Tekton Results API

###### Auto generated by spf13/cobra on 31-Aug-2023
###### Auto generated by spf13/cobra on 4-Sep-2023
28 changes: 28 additions & 0 deletions tools/tkn-results/docs/tkn-results_logs.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
## tkn-results logs

Commands for finding and retrieving logs

### Options

```
-h, --help help for logs
```

### Options inherited from parent commands

```
-a, --addr string Result API server address. If not specified, tkn-result would port-forward to service/tekton-results-api-service automatically
-t, --authtoken string authorization bearer token to use for authenticated requests
--insecure determines whether to run insecure GRPC tls request
--portforward enable auto portforwarding to tekton-results-api-service, when addr is set and portforward is true, tkn-results will portforward tekton-results-api-service automatically (default true)
--sa string ServiceAccount to use instead of token for authorization and authentication
--sa-ns string ServiceAccount Namespace, if not given, it will be taken from current context
```

### SEE ALSO

* [tkn-results](tkn-results.md) - tkn CLI plugin for Tekton Results API
* [tkn-results logs get](tkn-results_logs_get.md) - Get Log
* [tkn-results logs list](tkn-results_logs_list.md) - List Logs

###### Auto generated by spf13/cobra on 4-Sep-2023
33 changes: 33 additions & 0 deletions tools/tkn-results/docs/tkn-results_logs_get.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
## tkn-results logs get

Get Log

```
tkn-results logs get [flags] <log>

<log path>: Log full name to query. This is typically "<namespace>/results/<result name>/logs/<log name>".
```

### Options

```
-h, --help help for get
-o, --output string output format. Valid values: textproto|json (default "json")
```

### Options inherited from parent commands

```
-a, --addr string Result API server address. If not specified, tkn-result would port-forward to service/tekton-results-api-service automatically
-t, --authtoken string authorization bearer token to use for authenticated requests
--insecure determines whether to run insecure GRPC tls request
--portforward enable auto portforwarding to tekton-results-api-service, when addr is set and portforward is true, tkn-results will portforward tekton-results-api-service automatically (default true)
--sa string ServiceAccount to use instead of token for authorization and authentication
--sa-ns string ServiceAccount Namespace, if not given, it will be taken from current context
```

### SEE ALSO

* [tkn-results logs](tkn-results_logs.md) - Commands for finding and retrieving logs

###### Auto generated by spf13/cobra on 4-Sep-2023
36 changes: 36 additions & 0 deletions tools/tkn-results/docs/tkn-results_logs_list.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
## tkn-results logs list

List Logs

```
tkn-results logs list [flags] <result parent>

<result parent>: Result parent name to query. This is typically "<namespace>/results/<result name>", but may vary depending on the API Server. "-" may be used as <result name> to query all Logs for a given parent.
```

### Options

```
-f, --filter string CEL Filter
-h, --help help for list
-l, --limit int32 number of items to return. Response may be truncated due to server limits.
-o, --output string output format. Valid values: tab|textproto|json (default "tab")
-p, --page string pagination token to use for next page
```

### Options inherited from parent commands

```
-a, --addr string Result API server address. If not specified, tkn-result would port-forward to service/tekton-results-api-service automatically
-t, --authtoken string authorization bearer token to use for authenticated requests
--insecure determines whether to run insecure GRPC tls request
--portforward enable auto portforwarding to tekton-results-api-service, when addr is set and portforward is true, tkn-results will portforward tekton-results-api-service automatically (default true)
--sa string ServiceAccount to use instead of token for authorization and authentication
--sa-ns string ServiceAccount Namespace, if not given, it will be taken from current context
```

### SEE ALSO

* [tkn-results logs](tkn-results_logs.md) - Commands for finding and retrieving logs

###### Auto generated by spf13/cobra on 4-Sep-2023
3 changes: 2 additions & 1 deletion tools/tkn-results/docs/tkn-results_records.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ Command sub-group for querying Records
### SEE ALSO

* [tkn-results](tkn-results.md) - tkn CLI plugin for Tekton Results API
* [tkn-results records get](tkn-results_records_get.md) - Get Record
* [tkn-results records list](tkn-results_records_list.md) - List Records

###### Auto generated by spf13/cobra on 31-Aug-2023
###### Auto generated by spf13/cobra on 4-Sep-2023
Loading