forked from openshift/origin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
loader.go
54 lines (46 loc) · 1.63 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
51
52
53
54
package config
import (
"os"
"path"
"github.com/GoogleCloudPlatform/kubernetes/pkg/client/clientcmd"
)
const (
OpenShiftConfigPathEnvVar = "OPENSHIFTCONFIG"
OpenShiftConfigFlagName = "config"
OpenShiftConfigFileName = ".openshiftconfig"
OpenShiftConfigHomeDir = ".config/openshift"
OpenShiftConfigHomeFileName = ".config"
OpenShiftConfigHomeDirFileName = OpenShiftConfigHomeDir + "/" + OpenShiftConfigHomeFileName
KubeConfigPathEnvVar = clientcmd.RecommendedConfigPathEnvVar
KubeConfigFileName = ".kubeconfig"
KubeConfigHomeDir = ".kube"
)
// Set up the rules and priorities for loading config files.
func NewOpenShiftClientConfigLoadingRules() *clientcmd.ClientConfigLoadingRules {
return &clientcmd.ClientConfigLoadingRules{Precedence: FullClientConfigFilePriority()}
}
// File priority loading rules for OpenShift.
// 1. OPENSHIFTCONFIG env var
// 2. .openshiftconfig file in current directory
// 3. ~/.config/openshift/.config file
func OpenShiftClientConfigFilePriority() []string {
return []string{
os.Getenv(OpenShiftConfigPathEnvVar),
OpenShiftConfigFileName,
path.Join(os.Getenv("HOME"), OpenShiftConfigHomeDirFileName),
}
}
// File priority loading rules for Kube.
// 1. KUBECONFIG env var
// 2. .kubeconfig file in current directory
// 3. ~/.kube/.kubeconfig file
func KubeClientConfigFilePriority() []string {
return []string{
os.Getenv(KubeConfigPathEnvVar),
KubeConfigFileName,
path.Join(os.Getenv("HOME"), KubeConfigHomeDir, KubeConfigFileName),
}
}
func FullClientConfigFilePriority() []string {
return append(OpenShiftClientConfigFilePriority(), KubeClientConfigFilePriority()...)
}