diff --git a/pkg/cli/job/common.go b/pkg/cli/job/common.go index eab5139429..c493d97fd5 100644 --- a/pkg/cli/job/common.go +++ b/pkg/cli/job/common.go @@ -17,6 +17,7 @@ limitations under the License. package job import ( + "os" "path/filepath" "github.com/spf13/cobra" @@ -30,13 +31,11 @@ type commonFlags struct { func initFlags(cmd *cobra.Command, cf *commonFlags) { cmd.Flags().StringVarP(&cf.Master, "master", "s", "", "the address of apiserver") - if defaultKubeConfigFile := filepath.Join(homeDir(), ".kube", "config"); checkFileExist(defaultKubeConfigFile) { - cmd.Flags().StringVarP(&cf.Kubeconfig, "kubeconfig", "k", defaultKubeConfigFile, "(optional) absolute path to the kubeconfig file") - } else if kubeConfig := kubeConfig(); kubeConfig != "" { - //Default kubeconfig file is located in $HOME/.kube/config . In case this file does not exist, it will look for $KUBECONFIG instead. - cmd.Flags().StringVarP(&cf.Kubeconfig, "kubeconfig", "k", kubeConfig, "(optional) absolute path to the kubeconfig file") - } else { - cmd.Flags().StringVarP(&cf.Kubeconfig, "kubeconfig", "k", "", "(optional) absolute path to the kubeconfig file") + kubeConfFile := os.Getenv("KUBECONFIG") + if kubeConfFile == "" { + if home := homeDir(); home != "" { + kubeConfFile = filepath.Join(home, ".kube", "config") + } } - + cmd.Flags().StringVarP(&cf.Kubeconfig, "kubeconfig", "k", kubeConfFile, "(optional) absolute path to the kubeconfig file") } diff --git a/pkg/cli/job/util.go b/pkg/cli/job/util.go index 9e5d77a669..db5ee6290e 100644 --- a/pkg/cli/job/util.go +++ b/pkg/cli/job/util.go @@ -35,20 +35,6 @@ import ( "volcano.sh/volcano/pkg/client/clientset/versioned" ) -func checkFileExist(filePath string) bool { - if file, err := os.Stat(filePath); err == nil && !file.IsDir() { - return true - } - return false -} - -func kubeConfig() string { - if config := os.Getenv("KUBECONFIG"); config != "" { - return config - } - return "" -} - func homeDir() string { if h := os.Getenv("HOME"); h != "" { return h