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] Support passing of Service Account to tkn-results #575

Merged
merged 1 commit into from
Sep 3, 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: 2 additions & 0 deletions tools/tkn-results/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,8 @@ func Root() *cobra.Command {

cmd.PersistentFlags().StringP("addr", "a", "", "Result API server address. If not specified, tkn-result would port-forward to service/tekton-results-api-service automatically")
cmd.PersistentFlags().StringP("authtoken", "t", "", "authorization bearer token to use for authenticated requests")
cmd.PersistentFlags().String("sa", "", "ServiceAccount to use instead of token for authorization and authentication")
cmd.PersistentFlags().String("sa-ns", "", "ServiceAccount Namespace, if not given, it will be taken from current context")
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")

Expand Down
6 changes: 4 additions & 2 deletions tools/tkn-results/docs/tkn-results.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,15 @@ Config:
-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
-h, --help help for tkn-results
--insecure insecure GRPC tls request (default true)
--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 list](tkn-results_list.md) - List Results
* [tkn-results records](tkn-results_records.md) - Command sub-group for querying Records

###### Auto generated by spf13/cobra on 24-Aug-2023
###### Auto generated by spf13/cobra on 31-Aug-2023
6 changes: 4 additions & 2 deletions tools/tkn-results/docs/tkn-results_list.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,14 @@ tkn-results list [flags] <parent>
```
-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 insecure GRPC tls request (default true)
--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

###### Auto generated by spf13/cobra on 24-Aug-2023
###### Auto generated by spf13/cobra on 31-Aug-2023
6 changes: 4 additions & 2 deletions tools/tkn-results/docs/tkn-results_records.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,15 @@ Command sub-group for querying Records
```
-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 insecure GRPC tls request (default true)
--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 records list](tkn-results_records_list.md) - List Records

###### Auto generated by spf13/cobra on 24-Aug-2023
###### Auto generated by spf13/cobra on 31-Aug-2023
6 changes: 4 additions & 2 deletions tools/tkn-results/docs/tkn-results_records_list.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,14 @@ tkn-results records list [flags] <result parent>
```
-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 insecure GRPC tls request (default true)
--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 records](tkn-results_records.md) - Command sub-group for querying Records

###### Auto generated by spf13/cobra on 24-Aug-2023
###### Auto generated by spf13/cobra on 31-Aug-2023
8 changes: 8 additions & 0 deletions tools/tkn-results/internal/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,14 @@ func NewDefaultFactory() (*ClientFactory, error) {
if err != nil {
return nil, err
}
if cfg.ServiceAccount != nil && cfg.ServiceAccount.Name != "" &&
cfg.ServiceAccount.Namespace == "" {
ns, _, err := kubeconfig.Namespace()
if err != nil {
return nil, err
}
cfg.ServiceAccount.Namespace = ns
}
client, err := kubernetes.NewForConfig(clientconfig)
if err != nil {
return nil, err
Expand Down
9 changes: 9 additions & 0 deletions tools/tkn-results/internal/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,15 @@ func setConfig() error {
if s := viper.GetString("authtoken"); s != "" {
cfg.Token = viper.GetString("authtoken")
}
if s := viper.GetString("sa"); s != "" {
cfg.ServiceAccount = &ServiceAccount{}
cfg.ServiceAccount.Name = viper.GetString("sa")
if s := viper.GetString("sa-ns"); s != "" {
cfg.ServiceAccount.Namespace = viper.GetString("sa-ns")
}

}

cfg.Portforward = viper.GetBool("portforward")
cfg.Insecure = viper.GetBool("insecure")
return nil
Expand Down