Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support KUBECON env. #485

Merged
merged 1 commit into from
Oct 21, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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")
}
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

kubeConfFile := os.Getenv("KUBECONFIG")
if kubeConfFile == "" {
kubeConfFile = filepath.Join(homeDir(), ".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