forked from openshift/origin
-
Notifications
You must be signed in to change notification settings - Fork 1
/
loader.go
50 lines (39 loc) · 1.38 KB
/
loader.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
package config
import (
"os"
"path/filepath"
"github.com/spf13/cobra"
"k8s.io/client-go/tools/clientcmd"
kclientcmd "k8s.io/client-go/tools/clientcmd"
kcmdutil "k8s.io/kubernetes/pkg/kubectl/cmd/util"
"github.com/openshift/origin/pkg/client/config"
)
// NewOpenShiftClientConfigLoadingRules returns file priority loading rules for OpenShift.
// 1. --config value
// 2. if KUBECONFIG env var has a value, use it. Otherwise, ~/.kube/config file
func NewOpenShiftClientConfigLoadingRules() *clientcmd.ClientConfigLoadingRules {
chain := []string{}
envVarFile := os.Getenv(config.OpenShiftConfigPathEnvVar)
if len(envVarFile) != 0 {
chain = append(chain, filepath.SplitList(envVarFile)...)
} else {
chain = append(chain, config.RecommendedHomeFile)
}
return &clientcmd.ClientConfigLoadingRules{
Precedence: chain,
MigrationRules: config.CurrentMigrationRules(),
}
}
func NewPathOptions(cmd *cobra.Command) *kclientcmd.PathOptions {
return NewPathOptionsWithConfig(kcmdutil.GetFlagString(cmd, config.OpenShiftConfigFlagName))
}
func NewPathOptionsWithConfig(configPath string) *kclientcmd.PathOptions {
return &kclientcmd.PathOptions{
GlobalFile: config.RecommendedHomeFile,
EnvVar: config.OpenShiftConfigPathEnvVar,
ExplicitFileFlag: config.OpenShiftConfigFlagName,
LoadingRules: &kclientcmd.ClientConfigLoadingRules{
ExplicitPath: configPath,
},
}
}