From cc2802d9bb11a9193a48ccf5f89d727504fd8fb2 Mon Sep 17 00:00:00 2001 From: navist2020 Date: Wed, 13 Oct 2021 15:52:22 +0800 Subject: [PATCH] validate flag cfgPath to make sure it is not empty --- cmd/kubeadm/app/cmd/kubeconfig.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/cmd/kubeadm/app/cmd/kubeconfig.go b/cmd/kubeadm/app/cmd/kubeconfig.go index 81bc6896a08..59595825a2f 100644 --- a/cmd/kubeadm/app/cmd/kubeconfig.go +++ b/cmd/kubeadm/app/cmd/kubeconfig.go @@ -20,6 +20,7 @@ import ( "io" "time" + "github.com/pkg/errors" "github.com/spf13/cobra" "k8s.io/klog/v2" @@ -78,6 +79,9 @@ func newCmdUserKubeConfig(out io.Writer) *cobra.Command { Long: userKubeconfigLongDesc, Example: userKubeconfigExample, RunE: func(cmd *cobra.Command, args []string) error { + if len(cfgPath) == 0 { + return errors.New("the kubeadm configuration path cannot be empty") + } // This call returns the ready-to-use configuration based on the defaults populated by flags internalCfg, err := configutil.LoadOrDefaultInitConfiguration(cfgPath, initCfg, clusterCfg) if err != nil {