Skip to content

Commit

Permalink
Support KUBECON env.
Browse files Browse the repository at this point in the history
Signed-off-by: Klaus Ma <mada3@huawei.com>
  • Loading branch information
Klaus Ma committed Oct 20, 2019
1 parent afc20c7 commit 58be2c0
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 22 deletions.
15 changes: 7 additions & 8 deletions pkg/cli/job/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ limitations under the License.
package job

import (
"os"
"path/filepath"

"github.com/spf13/cobra"
Expand All @@ -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")
}
14 changes: 0 additions & 14 deletions pkg/cli/job/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 58be2c0

Please sign in to comment.