Use tristate for provideclusterinfo to manage provided flag

Kubernetes-commit: 38c67af789bc62b88275e6a12facfe3f7881208c
This commit is contained in:
Arda Güçlü 2023-11-29 08:58:59 +03:00 committed by Kubernetes Publisher
parent 2f794d398e
commit cb3e3dd9f6
1 changed files with 6 additions and 3 deletions

View File

@ -51,7 +51,7 @@ type setCredentialsOptions struct {
execCommand cliflag.StringFlag execCommand cliflag.StringFlag
execAPIVersion cliflag.StringFlag execAPIVersion cliflag.StringFlag
execInteractiveMode cliflag.StringFlag execInteractiveMode cliflag.StringFlag
execProvideClusterInfo bool execProvideClusterInfo cliflag.Tristate
execArgs []string execArgs []string
execEnv map[string]string execEnv map[string]string
execEnvToRemove []string execEnvToRemove []string
@ -187,7 +187,8 @@ func newCmdConfigSetCredentials(out io.Writer, options *setCredentialsOptions) *
cmd.Flags().Var(&options.execCommand, flagExecCommand, "Command for the exec credential plugin for the user entry in kubeconfig") cmd.Flags().Var(&options.execCommand, flagExecCommand, "Command for the exec credential plugin for the user entry in kubeconfig")
cmd.Flags().Var(&options.execAPIVersion, flagExecAPIVersion, "API version of the exec credential plugin for the user entry in kubeconfig") cmd.Flags().Var(&options.execAPIVersion, flagExecAPIVersion, "API version of the exec credential plugin for the user entry in kubeconfig")
cmd.Flags().Var(&options.execInteractiveMode, flagExecInteractiveMode, "InteractiveMode of the exec credentials plugin for the user entry in kubeconfig") cmd.Flags().Var(&options.execInteractiveMode, flagExecInteractiveMode, "InteractiveMode of the exec credentials plugin for the user entry in kubeconfig")
cmd.Flags().BoolVar(&options.execProvideClusterInfo, flagExecProvideClusterInfo, options.execProvideClusterInfo, "ProvideClusterInfo of the exec credentials plugin for the user entry in kubeconfig") flagClusterInfo := cmd.Flags().VarPF(&options.execProvideClusterInfo, flagExecProvideClusterInfo, "", "ProvideClusterInfo of the exec credentials plugin for the user entry in kubeconfig")
flagClusterInfo.NoOptDefVal = "true"
cmd.Flags().StringSlice(flagExecArg, nil, "New arguments for the exec credential plugin command for the user entry in kubeconfig") cmd.Flags().StringSlice(flagExecArg, nil, "New arguments for the exec credential plugin command for the user entry in kubeconfig")
cmd.Flags().StringArray(flagExecEnv, nil, "'key=value' environment values for the exec credential plugin") cmd.Flags().StringArray(flagExecEnv, nil, "'key=value' environment values for the exec credential plugin")
f := cmd.Flags().VarPF(&options.embedCertData, clientcmd.FlagEmbedCerts, "", "Embed client cert/key for the user entry in kubeconfig") f := cmd.Flags().VarPF(&options.embedCertData, clientcmd.FlagEmbedCerts, "", "Embed client cert/key for the user entry in kubeconfig")
@ -319,7 +320,9 @@ func (o *setCredentialsOptions) modifyAuthInfo(existingAuthInfo clientcmdapi.Aut
modifiedAuthInfo.Exec.InteractiveMode = clientcmdapi.ExecInteractiveMode(o.execInteractiveMode.Value()) modifiedAuthInfo.Exec.InteractiveMode = clientcmdapi.ExecInteractiveMode(o.execInteractiveMode.Value())
} }
modifiedAuthInfo.Exec.ProvideClusterInfo = o.execProvideClusterInfo if o.execProvideClusterInfo.Provided() {
modifiedAuthInfo.Exec.ProvideClusterInfo = o.execProvideClusterInfo.Value()
}
// iterate over the existing exec env values and remove the specified // iterate over the existing exec env values and remove the specified
if o.execEnvToRemove != nil { if o.execEnvToRemove != nil {