forked from openshift/origin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
loader.go
59 lines (48 loc) · 1.9 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
55
56
57
58
59
package config
import (
"os"
"path"
"path/filepath"
"github.com/spf13/cobra"
"github.com/GoogleCloudPlatform/kubernetes/pkg/client/clientcmd"
kclientcmd "github.com/GoogleCloudPlatform/kubernetes/pkg/client/clientcmd"
kubecmdconfig "github.com/GoogleCloudPlatform/kubernetes/pkg/kubectl/cmd/config"
cmdutil "github.com/GoogleCloudPlatform/kubernetes/pkg/kubectl/cmd/util"
)
const (
OpenShiftConfigPathEnvVar = "OPENSHIFTCONFIG"
OpenShiftConfigFlagName = "config"
OpenShiftConfigHomeDir = ".config/openshift"
OpenShiftConfigHomeFileName = "config"
OpenShiftConfigHomeDirFileName = OpenShiftConfigHomeDir + "/" + OpenShiftConfigHomeFileName
)
var OldRecommendedHomeFile = path.Join(os.Getenv("HOME"), ".config/openshift/.config")
var RecommendedHomeFile = path.Join(os.Getenv("HOME"), OpenShiftConfigHomeDirFileName)
// File priority loading rules for OpenShift.
// 1. --config value
// 2. if OPENSHIFTCONFIG env var has a value, use it. Otherwise, ~/.config/openshift/config file
func NewOpenShiftClientConfigLoadingRules() *clientcmd.ClientConfigLoadingRules {
chain := []string{}
migrationRules := map[string]string{}
envVarFile := os.Getenv(OpenShiftConfigPathEnvVar)
if len(envVarFile) != 0 {
chain = append(chain, filepath.SplitList(envVarFile)...)
} else {
chain = append(chain, RecommendedHomeFile)
migrationRules[RecommendedHomeFile] = OldRecommendedHomeFile
}
return &clientcmd.ClientConfigLoadingRules{
Precedence: chain,
MigrationRules: migrationRules,
}
}
func NewPathOptions(cmd *cobra.Command) *kubecmdconfig.PathOptions {
return &kubecmdconfig.PathOptions{
GlobalFile: path.Join(os.Getenv("HOME"), OpenShiftConfigHomeDirFileName),
EnvVar: OpenShiftConfigPathEnvVar,
ExplicitFileFlag: OpenShiftConfigFlagName,
LoadingRules: &kclientcmd.ClientConfigLoadingRules{
ExplicitPath: cmdutil.GetFlagString(cmd, OpenShiftConfigFlagName),
},
}
}