From 885d88f274cd84ca7ee8754a3396ebc2ab2fb06e Mon Sep 17 00:00:00 2001 From: deads2k Date: Fri, 20 Feb 2015 09:27:34 -0500 Subject: [PATCH] prevent default merging when specifying a specific kubeconfig for config view --- pkg/kubectl/cmd/config/view.go | 28 ++++++++++++++++++++++------ 1 file changed, 22 insertions(+), 6 deletions(-) diff --git a/pkg/kubectl/cmd/config/view.go b/pkg/kubectl/cmd/config/view.go index 738746d9896..95f13c6dcc6 100644 --- a/pkg/kubectl/cmd/config/view.go +++ b/pkg/kubectl/cmd/config/view.go @@ -26,12 +26,13 @@ import ( "github.com/GoogleCloudPlatform/kubernetes/pkg/client/clientcmd" clientcmdapi "github.com/GoogleCloudPlatform/kubernetes/pkg/client/clientcmd/api" - "github.com/GoogleCloudPlatform/kubernetes/pkg/kubectl/cmd/util" + cmdutil "github.com/GoogleCloudPlatform/kubernetes/pkg/kubectl/cmd/util" + "github.com/GoogleCloudPlatform/kubernetes/pkg/util" ) type viewOptions struct { pathOptions *pathOptions - merge bool + merge util.BoolFlag } func NewCmdConfigView(out io.Writer, pathOptions *pathOptions) *cobra.Command { @@ -48,7 +49,9 @@ Examples: // Show only local ./.kubeconfig settings $ kubectl config view --local`, Run: func(cmd *cobra.Command, args []string) { - printer, _, err := util.PrinterForCommand(cmd) + options.complete() + + printer, _, err := cmdutil.PrinterForCommand(cmd) if err != nil { glog.FatalDepth(1, err) } @@ -63,13 +66,26 @@ Examples: }, } - util.AddPrinterFlags(cmd) + cmdutil.AddPrinterFlags(cmd) // Default to yaml cmd.Flags().Set("output", "yaml") - cmd.Flags().BoolVar(&options.merge, "merge", true, "merge together the full hierarchy of .kubeconfig files") + + options.merge.Default(true) + cmd.Flags().Var(&options.merge, "merge", "merge together the full hierarchy of .kubeconfig files") return cmd } +func (o *viewOptions) complete() bool { + // if --kubeconfig, --global, or --local is specified, then merging doesn't make sense since you're declaring precise intent + if (len(o.pathOptions.specifiedFile) > 0) || o.pathOptions.global || o.pathOptions.local { + if !o.merge.Provided() { + o.merge.Set("false") + } + } + + return true +} + func (o viewOptions) loadConfig() (*clientcmdapi.Config, error) { err := o.validate() if err != nil { @@ -87,7 +103,7 @@ func (o viewOptions) validate() error { // getStartingConfig returns the Config object built from the sources specified by the options, the filename read (only if it was a single file), and an error if something goes wrong func (o *viewOptions) getStartingConfig() (*clientcmdapi.Config, string, error) { switch { - case o.merge: + case o.merge.Value(): loadingRules := clientcmd.NewClientConfigLoadingRules() loadingRules.EnvVarPath = os.Getenv("KUBECONFIG") loadingRules.CommandLinePath = o.pathOptions.specifiedFile