From 131a58c25220ed2e66e490046e375353e1cb9a84 Mon Sep 17 00:00:00 2001 From: brianpursley Date: Sun, 6 Feb 2022 21:31:13 -0500 Subject: [PATCH] Renamed create_authinfo.go, create_cluster.go, and create_context.go to match their kubectl config subcommand names and reflect that they are used for setting values, not just creating. Deprecated NewCmdConfigSetAuthInfo in favor of NewCmdConfigSetCredentials. Did some minor refactoring of one of the complete functions to eliminate an unused argument and not wrap returned errors that do not add detail. Kubernetes-commit: 48007fc32bb473d1d0d7d7c24b9daa2157e433d1 --- pkg/cmd/config/config.go | 2 +- .../{create_cluster.go => set_cluster.go} | 23 +++++---- ...te_cluster_test.go => set_cluster_test.go} | 16 +++--- .../{create_context.go => set_context.go} | 20 ++++---- ...te_context_test.go => set_context_test.go} | 10 ++-- ...{create_authinfo.go => set_credentials.go} | 49 ++++++++++--------- ...thinfo_test.go => set_credentials_test.go} | 46 ++++++++--------- 7 files changed, 85 insertions(+), 81 deletions(-) rename pkg/cmd/config/{create_cluster.go => set_cluster.go} (90%) rename pkg/cmd/config/{create_cluster_test.go => set_cluster_test.go} (96%) rename pkg/cmd/config/{create_context.go => set_context.go} (88%) rename pkg/cmd/config/{create_context_test.go => set_context_test.go} (96%) rename pkg/cmd/config/{create_authinfo.go => set_credentials.go} (91%) rename pkg/cmd/config/{create_authinfo_test.go => set_credentials_test.go} (92%) diff --git a/pkg/cmd/config/config.go b/pkg/cmd/config/config.go index abd15be9..8d75c2c1 100644 --- a/pkg/cmd/config/config.go +++ b/pkg/cmd/config/config.go @@ -57,7 +57,7 @@ func NewCmdConfig(pathOptions *clientcmd.PathOptions, streams genericclioptions. // TODO(juanvallejo): update all subcommands to work with genericclioptions.IOStreams cmd.AddCommand(NewCmdConfigView(streams, pathOptions)) cmd.AddCommand(NewCmdConfigSetCluster(streams.Out, pathOptions)) - cmd.AddCommand(NewCmdConfigSetAuthInfo(streams.Out, pathOptions)) + cmd.AddCommand(NewCmdConfigSetCredentials(streams.Out, pathOptions)) cmd.AddCommand(NewCmdConfigSetContext(streams.Out, pathOptions)) cmd.AddCommand(NewCmdConfigSet(streams.Out, pathOptions)) cmd.AddCommand(NewCmdConfigUnset(streams.Out, pathOptions)) diff --git a/pkg/cmd/config/create_cluster.go b/pkg/cmd/config/set_cluster.go similarity index 90% rename from pkg/cmd/config/create_cluster.go rename to pkg/cmd/config/set_cluster.go index 9d450451..4ed92589 100644 --- a/pkg/cmd/config/create_cluster.go +++ b/pkg/cmd/config/set_cluster.go @@ -33,7 +33,7 @@ import ( "k8s.io/kubectl/pkg/util/templates" ) -type createClusterOptions struct { +type setClusterOptions struct { configAccess clientcmd.ConfigAccess name string server cliflag.StringFlag @@ -45,19 +45,19 @@ type createClusterOptions struct { } var ( - createClusterLong = templates.LongDesc(i18n.T(` + setClusterLong = templates.LongDesc(i18n.T(` Set a cluster entry in kubeconfig. Specifying a name that already exists will merge new fields on top of existing values for those fields.`)) - createClusterExample = templates.Examples(` + setClusterExample = templates.Examples(` # Set only the server field on the e2e cluster entry without touching other values kubectl config set-cluster e2e --server=https://1.2.3.4 # Embed certificate authority data for the e2e cluster entry kubectl config set-cluster e2e --embed-certs --certificate-authority=~/.kube/e2e/kubernetes.ca.crt - # Disable cert checking for the dev cluster entry + # Disable cert checking for the e2e cluster entry kubectl config set-cluster e2e --insecure-skip-tls-verify=true # Set custom TLS server name to use for validation for the e2e cluster entry @@ -69,14 +69,14 @@ var ( // NewCmdConfigSetCluster returns a Command instance for 'config set-cluster' sub command func NewCmdConfigSetCluster(out io.Writer, configAccess clientcmd.ConfigAccess) *cobra.Command { - options := &createClusterOptions{configAccess: configAccess} + options := &setClusterOptions{configAccess: configAccess} cmd := &cobra.Command{ Use: fmt.Sprintf("set-cluster NAME [--%v=server] [--%v=path/to/certificate/authority] [--%v=true] [--%v=example.com]", clientcmd.FlagAPIServer, clientcmd.FlagCAFile, clientcmd.FlagInsecure, clientcmd.FlagTLSServerName), DisableFlagsInUseLine: true, Short: i18n.T("Set a cluster entry in kubeconfig"), - Long: createClusterLong, - Example: createClusterExample, + Long: setClusterLong, + Example: setClusterExample, Run: func(cmd *cobra.Command, args []string) { cmdutil.CheckErr(options.complete(cmd)) cmdutil.CheckErr(options.run()) @@ -99,7 +99,7 @@ func NewCmdConfigSetCluster(out io.Writer, configAccess clientcmd.ConfigAccess) return cmd } -func (o createClusterOptions) run() error { +func (o setClusterOptions) run() error { err := o.validate() if err != nil { return err @@ -124,8 +124,7 @@ func (o createClusterOptions) run() error { return nil } -// cluster builds a Cluster object from the options -func (o *createClusterOptions) modifyCluster(existingCluster clientcmdapi.Cluster) clientcmdapi.Cluster { +func (o *setClusterOptions) modifyCluster(existingCluster clientcmdapi.Cluster) clientcmdapi.Cluster { modifiedCluster := existingCluster if o.server.Provided() { @@ -169,7 +168,7 @@ func (o *createClusterOptions) modifyCluster(existingCluster clientcmdapi.Cluste return modifiedCluster } -func (o *createClusterOptions) complete(cmd *cobra.Command) error { +func (o *setClusterOptions) complete(cmd *cobra.Command) error { args := cmd.Flags().Args() if len(args) != 1 { return helpErrorf(cmd, "Unexpected args: %v", args) @@ -179,7 +178,7 @@ func (o *createClusterOptions) complete(cmd *cobra.Command) error { return nil } -func (o createClusterOptions) validate() error { +func (o setClusterOptions) validate() error { if len(o.name) == 0 { return errors.New("you must specify a non-empty cluster name") } diff --git a/pkg/cmd/config/create_cluster_test.go b/pkg/cmd/config/set_cluster_test.go similarity index 96% rename from pkg/cmd/config/create_cluster_test.go rename to pkg/cmd/config/set_cluster_test.go index 9021e029..0054c72d 100644 --- a/pkg/cmd/config/create_cluster_test.go +++ b/pkg/cmd/config/set_cluster_test.go @@ -26,7 +26,7 @@ import ( clientcmdapi "k8s.io/client-go/tools/clientcmd/api" ) -type createClusterTest struct { +type setClusterTest struct { description string config clientcmdapi.Config args []string @@ -37,7 +37,7 @@ type createClusterTest struct { func TestCreateCluster(t *testing.T) { conf := clientcmdapi.Config{} - test := createClusterTest{ + test := setClusterTest{ description: "Testing 'kubectl config set-cluster' with a new cluster", config: conf, args: []string{"my-cluster"}, @@ -57,7 +57,7 @@ func TestCreateCluster(t *testing.T) { func TestCreateClusterWithProxy(t *testing.T) { conf := clientcmdapi.Config{} - test := createClusterTest{ + test := setClusterTest{ description: "Testing 'kubectl config set-cluster' with a new cluster", config: conf, args: []string{"my-cluster"}, @@ -86,7 +86,7 @@ func TestModifyCluster(t *testing.T) { "my-cluster": {Server: "https://192.168.0.1", TLSServerName: "to-be-cleared"}, }, } - test := createClusterTest{ + test := setClusterTest{ description: "Testing 'kubectl config set-cluster' with an existing cluster", config: conf, args: []string{"my-cluster"}, @@ -110,7 +110,7 @@ func TestModifyClusterWithProxy(t *testing.T) { "my-cluster": {Server: "https://192.168.0.1", TLSServerName: "to-be-cleared"}, }, } - test := createClusterTest{ + test := setClusterTest{ description: "Testing 'kubectl config set-cluster' with an existing cluster", config: conf, args: []string{"my-cluster"}, @@ -140,7 +140,7 @@ func TestModifyClusterWithProxyOverride(t *testing.T) { }, }, } - test := createClusterTest{ + test := setClusterTest{ description: "Testing 'kubectl config set-cluster' with an existing cluster", config: conf, args: []string{"my-cluster"}, @@ -164,7 +164,7 @@ func TestModifyClusterServerAndTLS(t *testing.T) { "my-cluster": {Server: "https://192.168.0.1"}, }, } - test := createClusterTest{ + test := setClusterTest{ description: "Testing 'kubectl config set-cluster' with an existing cluster", config: conf, args: []string{"my-cluster"}, @@ -182,7 +182,7 @@ func TestModifyClusterServerAndTLS(t *testing.T) { test.run(t) } -func (test createClusterTest) run(t *testing.T) { +func (test setClusterTest) run(t *testing.T) { fakeKubeFile, err := ioutil.TempFile(os.TempDir(), "") if err != nil { t.Fatalf("unexpected error: %v", err) diff --git a/pkg/cmd/config/create_context.go b/pkg/cmd/config/set_context.go similarity index 88% rename from pkg/cmd/config/create_context.go rename to pkg/cmd/config/set_context.go index fd636b5a..b5fd94fa 100644 --- a/pkg/cmd/config/create_context.go +++ b/pkg/cmd/config/set_context.go @@ -32,7 +32,7 @@ import ( "k8s.io/kubectl/pkg/util/templates" ) -type createContextOptions struct { +type setContextOptions struct { configAccess clientcmd.ConfigAccess name string currContext bool @@ -42,26 +42,26 @@ type createContextOptions struct { } var ( - createContextLong = templates.LongDesc(i18n.T(` + setContextLong = templates.LongDesc(i18n.T(` Set a context entry in kubeconfig. Specifying a name that already exists will merge new fields on top of existing values for those fields.`)) - createContextExample = templates.Examples(` + setContextExample = templates.Examples(` # Set the user field on the gce context entry without touching other values kubectl config set-context gce --user=cluster-admin`) ) // NewCmdConfigSetContext returns a Command instance for 'config set-context' sub command func NewCmdConfigSetContext(out io.Writer, configAccess clientcmd.ConfigAccess) *cobra.Command { - options := &createContextOptions{configAccess: configAccess} + options := &setContextOptions{configAccess: configAccess} cmd := &cobra.Command{ Use: fmt.Sprintf("set-context [NAME | --current] [--%v=cluster_nickname] [--%v=user_nickname] [--%v=namespace]", clientcmd.FlagClusterName, clientcmd.FlagAuthInfoName, clientcmd.FlagNamespace), DisableFlagsInUseLine: true, Short: i18n.T("Set a context entry in kubeconfig"), - Long: createContextLong, - Example: createContextExample, + Long: setContextLong, + Example: setContextExample, ValidArgsFunction: util.ContextCompletionFunc, Run: func(cmd *cobra.Command, args []string) { cmdutil.CheckErr(options.complete(cmd)) @@ -83,7 +83,7 @@ func NewCmdConfigSetContext(out io.Writer, configAccess clientcmd.ConfigAccess) return cmd } -func (o createContextOptions) run() (string, bool, error) { +func (o setContextOptions) run() (string, bool, error) { err := o.validate() if err != nil { return "", false, err @@ -116,7 +116,7 @@ func (o createContextOptions) run() (string, bool, error) { return name, exists, nil } -func (o *createContextOptions) modifyContext(existingContext clientcmdapi.Context) clientcmdapi.Context { +func (o *setContextOptions) modifyContext(existingContext clientcmdapi.Context) clientcmdapi.Context { modifiedContext := existingContext if o.cluster.Provided() { @@ -132,7 +132,7 @@ func (o *createContextOptions) modifyContext(existingContext clientcmdapi.Contex return modifiedContext } -func (o *createContextOptions) complete(cmd *cobra.Command) error { +func (o *setContextOptions) complete(cmd *cobra.Command) error { args := cmd.Flags().Args() if len(args) > 1 { return helpErrorf(cmd, "Unexpected args: %v", args) @@ -143,7 +143,7 @@ func (o *createContextOptions) complete(cmd *cobra.Command) error { return nil } -func (o createContextOptions) validate() error { +func (o setContextOptions) validate() error { if len(o.name) == 0 && !o.currContext { return errors.New("you must specify a non-empty context name or --current") } diff --git a/pkg/cmd/config/create_context_test.go b/pkg/cmd/config/set_context_test.go similarity index 96% rename from pkg/cmd/config/create_context_test.go rename to pkg/cmd/config/set_context_test.go index f75a6dd7..2422d020 100644 --- a/pkg/cmd/config/create_context_test.go +++ b/pkg/cmd/config/set_context_test.go @@ -26,7 +26,7 @@ import ( clientcmdapi "k8s.io/client-go/tools/clientcmd/api" ) -type createContextTest struct { +type setContextTest struct { description string testContext string // name of the context being modified config clientcmdapi.Config //initiate kubectl config @@ -38,7 +38,7 @@ type createContextTest struct { func TestCreateContext(t *testing.T) { conf := clientcmdapi.Config{} - test := createContextTest{ + test := setContextTest{ testContext: "shaker-context", description: "Testing for create a new context", config: conf, @@ -61,7 +61,7 @@ func TestModifyContext(t *testing.T) { Contexts: map[string]*clientcmdapi.Context{ "shaker-context": {AuthInfo: "blue-user", Cluster: "big-cluster", Namespace: "saw-ns"}, "not-this": {AuthInfo: "blue-user", Cluster: "big-cluster", Namespace: "saw-ns"}}} - test := createContextTest{ + test := setContextTest{ testContext: "shaker-context", description: "Testing for modify a already exist context", config: conf, @@ -86,7 +86,7 @@ func TestModifyCurrentContext(t *testing.T) { Contexts: map[string]*clientcmdapi.Context{ "shaker-context": {AuthInfo: "blue-user", Cluster: "big-cluster", Namespace: "saw-ns"}, "not-this": {AuthInfo: "blue-user", Cluster: "big-cluster", Namespace: "saw-ns"}}} - test := createContextTest{ + test := setContextTest{ testContext: "shaker-context", description: "Testing for modify a current context", config: conf, @@ -106,7 +106,7 @@ func TestModifyCurrentContext(t *testing.T) { test.run(t) } -func (test createContextTest) run(t *testing.T) { +func (test setContextTest) run(t *testing.T) { fakeKubeFile, err := ioutil.TempFile(os.TempDir(), "") if err != nil { t.Fatalf("unexpected error: %v", err) diff --git a/pkg/cmd/config/create_authinfo.go b/pkg/cmd/config/set_credentials.go similarity index 91% rename from pkg/cmd/config/create_authinfo.go rename to pkg/cmd/config/set_credentials.go index f94cfd01..4140c07e 100644 --- a/pkg/cmd/config/create_authinfo.go +++ b/pkg/cmd/config/set_credentials.go @@ -35,7 +35,7 @@ import ( "k8s.io/kubectl/pkg/util/templates" ) -type createAuthInfoOptions struct { +type setCredentialsOptions struct { configAccess clientcmd.ConfigAccess name string clientCertificate cliflag.StringFlag @@ -67,7 +67,7 @@ const ( ) var ( - createAuthInfoLong = fmt.Sprintf(templates.LongDesc(i18n.T(` + setCredentialsLong = fmt.Sprintf(templates.LongDesc(i18n.T(` Set a user entry in kubeconfig. Specifying a name that already exists will merge new fields on top of existing values. @@ -83,7 +83,7 @@ var ( Bearer token and basic auth are mutually exclusive.`)), clientcmd.FlagCertFile, clientcmd.FlagKeyFile, clientcmd.FlagBearerToken, clientcmd.FlagUsername, clientcmd.FlagPassword) - createAuthInfoExample = templates.Examples(` + setCredentialsExample = templates.Examples(` # Set only the "client-key" field on the "cluster-admin" # entry, without touching other values kubectl config set-credentials cluster-admin --client-key=~/.kube/admin.key @@ -116,13 +116,19 @@ var ( kubectl config set-credentials cluster-admin --exec-env=var-to-remove-`) ) -// NewCmdConfigSetAuthInfo returns an Command option instance for 'config set-credentials' sub command -func NewCmdConfigSetAuthInfo(out io.Writer, configAccess clientcmd.ConfigAccess) *cobra.Command { - options := &createAuthInfoOptions{configAccess: configAccess} - return newCmdConfigSetAuthInfo(out, options) +// NewCmdConfigSetCredentials returns a Command instance for 'config set-credentials' sub command +func NewCmdConfigSetCredentials(out io.Writer, configAccess clientcmd.ConfigAccess) *cobra.Command { + options := &setCredentialsOptions{configAccess: configAccess} + return newCmdConfigSetCredentials(out, options) } -func newCmdConfigSetAuthInfo(out io.Writer, options *createAuthInfoOptions) *cobra.Command { +// NewCmdConfigSetAuthInfo returns a Command instance for 'config set-credentials' sub command +// DEPRECATED: Use NewCmdConfigSetCredentials instead +func NewCmdConfigSetAuthInfo(out io.Writer, configAccess clientcmd.ConfigAccess) *cobra.Command { + return NewCmdConfigSetCredentials(out, configAccess) +} + +func newCmdConfigSetCredentials(out io.Writer, options *setCredentialsOptions) *cobra.Command { cmd := &cobra.Command{ Use: fmt.Sprintf( "set-credentials NAME [--%v=path/to/certfile] "+ @@ -150,10 +156,10 @@ func newCmdConfigSetAuthInfo(out io.Writer, options *createAuthInfoOptions) *cob ), DisableFlagsInUseLine: true, Short: i18n.T("Set a user entry in kubeconfig"), - Long: createAuthInfoLong, - Example: createAuthInfoExample, + Long: setCredentialsLong, + Example: setCredentialsExample, Run: func(cmd *cobra.Command, args []string) { - err := options.complete(cmd, out) + err := options.complete(cmd) if err != nil { cmd.Help() cmdutil.CheckErr(err) @@ -182,7 +188,7 @@ func newCmdConfigSetAuthInfo(out io.Writer, options *createAuthInfoOptions) *cob return cmd } -func (o createAuthInfoOptions) run() error { +func (o setCredentialsOptions) run() error { err := o.validate() if err != nil { return err @@ -207,8 +213,7 @@ func (o createAuthInfoOptions) run() error { return nil } -// authInfo builds an AuthInfo object from the options -func (o *createAuthInfoOptions) modifyAuthInfo(existingAuthInfo clientcmdapi.AuthInfo) clientcmdapi.AuthInfo { +func (o *setCredentialsOptions) modifyAuthInfo(existingAuthInfo clientcmdapi.AuthInfo) clientcmdapi.AuthInfo { modifiedAuthInfo := existingAuthInfo var setToken, setBasic bool @@ -356,21 +361,21 @@ func (o *createAuthInfoOptions) modifyAuthInfo(existingAuthInfo clientcmdapi.Aut return modifiedAuthInfo } -func (o *createAuthInfoOptions) complete(cmd *cobra.Command, out io.Writer) error { +func (o *setCredentialsOptions) complete(cmd *cobra.Command) error { args := cmd.Flags().Args() if len(args) != 1 { - return fmt.Errorf("Unexpected args: %v", args) + return fmt.Errorf("unexpected args: %v", args) } authProviderArgs, err := cmd.Flags().GetStringSlice(flagAuthProviderArg) if err != nil { - return fmt.Errorf("Error: %s", err) + return err } if len(authProviderArgs) > 0 { newPairs, removePairs, err := cmdutil.ParsePairs(authProviderArgs, flagAuthProviderArg, true) if err != nil { - return fmt.Errorf("Error: %s", err) + return err } o.authProviderArgs = newPairs o.authProviderArgsToRemove = removePairs @@ -378,7 +383,7 @@ func (o *createAuthInfoOptions) complete(cmd *cobra.Command, out io.Writer) erro execArgs, err := cmd.Flags().GetStringSlice(flagExecArg) if err != nil { - return fmt.Errorf("Error: %s", err) + return err } if len(execArgs) > 0 { o.execArgs = execArgs @@ -386,12 +391,12 @@ func (o *createAuthInfoOptions) complete(cmd *cobra.Command, out io.Writer) erro execEnv, err := cmd.Flags().GetStringArray(flagExecEnv) if err != nil { - return fmt.Errorf("Error: %s", err) + return err } if len(execEnv) > 0 { newPairs, removePairs, err := cmdutil.ParsePairs(execEnv, flagExecEnv, true) if err != nil { - return fmt.Errorf("Error: %s", err) + return err } o.execEnv = newPairs o.execEnvToRemove = removePairs @@ -401,7 +406,7 @@ func (o *createAuthInfoOptions) complete(cmd *cobra.Command, out io.Writer) erro return nil } -func (o createAuthInfoOptions) validate() error { +func (o setCredentialsOptions) validate() error { if len(o.name) == 0 { return errors.New("you must specify a non-empty user name") } diff --git a/pkg/cmd/config/create_authinfo_test.go b/pkg/cmd/config/set_credentials_test.go similarity index 92% rename from pkg/cmd/config/create_authinfo_test.go rename to pkg/cmd/config/set_credentials_test.go index 45299050..2eafcb27 100644 --- a/pkg/cmd/config/create_authinfo_test.go +++ b/pkg/cmd/config/set_credentials_test.go @@ -34,7 +34,7 @@ func stringFlagFor(s string) cliflag.StringFlag { return f } -func TestCreateAuthInfoOptions(t *testing.T) { +func TestSetCredentialsOptions(t *testing.T) { tests := []struct { name string flags []string @@ -42,14 +42,14 @@ func TestCreateAuthInfoOptions(t *testing.T) { wantCompleteErr bool wantValidateErr bool - wantOptions *createAuthInfoOptions + wantOptions *setCredentialsOptions }{ { name: "test1", flags: []string{ "me", }, - wantOptions: &createAuthInfoOptions{ + wantOptions: &setCredentialsOptions{ name: "me", }, }, @@ -59,7 +59,7 @@ func TestCreateAuthInfoOptions(t *testing.T) { "me", "--token=foo", }, - wantOptions: &createAuthInfoOptions{ + wantOptions: &setCredentialsOptions{ name: "me", token: stringFlagFor("foo"), }, @@ -71,7 +71,7 @@ func TestCreateAuthInfoOptions(t *testing.T) { "--username=jane", "--password=bar", }, - wantOptions: &createAuthInfoOptions{ + wantOptions: &setCredentialsOptions{ name: "me", username: stringFlagFor("jane"), password: stringFlagFor("bar"), @@ -96,7 +96,7 @@ func TestCreateAuthInfoOptions(t *testing.T) { "--auth-provider-arg=client-secret=bar", "me", }, - wantOptions: &createAuthInfoOptions{ + wantOptions: &setCredentialsOptions{ name: "me", authProvider: stringFlagFor("oidc"), authProviderArgs: map[string]string{ @@ -114,7 +114,7 @@ func TestCreateAuthInfoOptions(t *testing.T) { "--auth-provider-arg=client-secret-", "me", }, - wantOptions: &createAuthInfoOptions{ + wantOptions: &setCredentialsOptions{ name: "me", authProvider: stringFlagFor("oidc"), authProviderArgs: map[string]string{}, @@ -131,7 +131,7 @@ func TestCreateAuthInfoOptions(t *testing.T) { "--auth-provider-arg=client-secret-", "me", }, - wantOptions: &createAuthInfoOptions{ + wantOptions: &setCredentialsOptions{ name: "me", authProviderArgs: map[string]string{}, authProviderArgsToRemove: []string{ @@ -162,7 +162,7 @@ func TestCreateAuthInfoOptions(t *testing.T) { "--exec-command=example-client-go-exec-plugin", "me", }, - wantOptions: &createAuthInfoOptions{ + wantOptions: &setCredentialsOptions{ name: "me", execCommand: stringFlagFor("example-client-go-exec-plugin"), }, @@ -175,7 +175,7 @@ func TestCreateAuthInfoOptions(t *testing.T) { "--exec-arg=arg2", "me", }, - wantOptions: &createAuthInfoOptions{ + wantOptions: &setCredentialsOptions{ name: "me", execCommand: stringFlagFor("example-client-go-exec-plugin"), execArgs: []string{"arg1", "arg2"}, @@ -191,7 +191,7 @@ func TestCreateAuthInfoOptions(t *testing.T) { "--exec-env=env-remove2-", "me", }, - wantOptions: &createAuthInfoOptions{ + wantOptions: &setCredentialsOptions{ name: "me", execCommand: stringFlagFor("example-client-go-exec-plugin"), execEnv: map[string]string{"key1": "val1", "key2": "val2"}, @@ -204,8 +204,8 @@ func TestCreateAuthInfoOptions(t *testing.T) { t.Run(tt.name, func(t *testing.T) { buff := new(bytes.Buffer) - opts := new(createAuthInfoOptions) - cmd := newCmdConfigSetAuthInfo(buff, opts) + opts := new(setCredentialsOptions) + cmd := newCmdConfigSetCredentials(buff, opts) if err := cmd.ParseFlags(tt.flags); err != nil { if !tt.wantParseErr { t.Errorf("case %s: parsing error for flags %q: %v: %s", tt.name, tt.flags, err, buff) @@ -217,7 +217,7 @@ func TestCreateAuthInfoOptions(t *testing.T) { return } - if err := opts.complete(cmd, buff); err != nil { + if err := opts.complete(cmd); err != nil { if !tt.wantCompleteErr { t.Errorf("case %s: complete() error for flags %q: %s", tt.name, tt.flags, buff) } @@ -381,8 +381,8 @@ func TestModifyExistingAuthInfo(t *testing.T) { t.Run(tt.name, func(t *testing.T) { buff := new(bytes.Buffer) - opts := new(createAuthInfoOptions) - cmd := newCmdConfigSetAuthInfo(buff, opts) + opts := new(setCredentialsOptions) + cmd := newCmdConfigSetCredentials(buff, opts) if err := cmd.ParseFlags(tt.flags); err != nil { if !tt.wantParseErr { t.Errorf("case %s: parsing error for flags %q: %v: %s", tt.name, tt.flags, err, buff) @@ -394,7 +394,7 @@ func TestModifyExistingAuthInfo(t *testing.T) { return } - if err := opts.complete(cmd, buff); err != nil { + if err := opts.complete(cmd); err != nil { if !tt.wantCompleteErr { t.Errorf("case %s: complete() error for flags %q: %s", tt.name, tt.flags, buff) } @@ -426,7 +426,7 @@ func TestModifyExistingAuthInfo(t *testing.T) { } } -type createAuthInfoTest struct { +type setCredentialsTest struct { description string config clientcmdapi.Config args []string @@ -435,10 +435,10 @@ type createAuthInfoTest struct { expectedConfig clientcmdapi.Config } -func TestCreateAuthInfo(t *testing.T) { +func TestSetCredentials(t *testing.T) { conf := clientcmdapi.Config{} - test := createAuthInfoTest{ - description: "Testing for create aythinfo", + test := setCredentialsTest{ + description: "Testing set credentials", config: conf, args: []string{"cluster-admin"}, flags: []string{ @@ -453,7 +453,7 @@ func TestCreateAuthInfo(t *testing.T) { } test.run(t) } -func (test createAuthInfoTest) run(t *testing.T) { +func (test setCredentialsTest) run(t *testing.T) { fakeKubeFile, err := ioutil.TempFile(os.TempDir(), "") if err != nil { t.Fatalf("unexpected error: %v", err) @@ -468,7 +468,7 @@ func (test createAuthInfoTest) run(t *testing.T) { pathOptions.GlobalFile = fakeKubeFile.Name() pathOptions.EnvVar = "" buf := bytes.NewBuffer([]byte{}) - cmd := NewCmdConfigSetAuthInfo(buf, pathOptions) + cmd := NewCmdConfigSetCredentials(buf, pathOptions) cmd.SetArgs(test.args) cmd.Flags().Parse(test.flags) if err := cmd.Execute(); err != nil {