Skip to content

Commit

Permalink
Support passing of Service Account to tkn-results
Browse files Browse the repository at this point in the history
User can pass flag --sa for serviceaccount name and --sa-ns for
serviceaccount namespace. Latter is optional. If not given, then
namespace from current context is assumed.
  • Loading branch information
khrm committed Aug 24, 2023
1 parent f0d1c53 commit bfa8a4d
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 0 deletions.
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.AddCommand(ListCommand(params), records.Command(params))
Expand Down
7 changes: 7 additions & 0 deletions tools/tkn-results/internal/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,13 @@ func NewDefaultFactory() (*ClientFactory, error) {
if err != nil {
return nil, err
}
if 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
6 changes: 6 additions & 0 deletions tools/tkn-results/internal/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,12 @@ func setConfig() error {
if s := viper.GetString("authtoken"); s != "" {
cfg.Token = viper.GetString("authtoken")
}
if s := viper.GetString("sa"); s != "" {
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")
return nil
}
Expand Down

0 comments on commit bfa8a4d

Please sign in to comment.