@@ -10,26 +10,22 @@ import (
10
10
// empty, the kube config will be loaded from KUBECONFIG, and if KUBECONFIG
11
11
// isn't set, the in-cluster config will be used.
12
12
func LoadRESTConfig (path string ) (* rest.Config , error ) {
13
- switch path {
13
+ loadingrules := clientcmd .NewDefaultClientConfigLoadingRules ()
14
+
15
+ // If the kubeconfig path is provided, use that file and fail if it does
16
+ // not exist.
14
17
// If the kubeconfig path is not provided, use the default loading rules
15
18
// so we read the regular KUBECONFIG variable or create a non-interactive
16
19
// client for agents running in cluster
17
- case "" :
18
- loadingrules := clientcmd .NewDefaultClientConfigLoadingRules ()
19
- cfg , err := clientcmd .NewNonInteractiveDeferredLoadingClientConfig (
20
- loadingrules , & clientcmd.ConfigOverrides {}).ClientConfig ()
21
- if err != nil {
22
- return nil , errors .WithStack (err )
23
- }
24
- return cfg , nil
25
- // Otherwise use the explicitly named kubeconfig file.
26
- default :
27
- cfg , err := clientcmd .NewNonInteractiveDeferredLoadingClientConfig (
28
- & clientcmd.ClientConfigLoadingRules {ExplicitPath : path },
29
- & clientcmd.ConfigOverrides {}).ClientConfig ()
30
- if err != nil {
31
- return nil , errors .WithStack (err )
32
- }
33
- return cfg , nil
20
+ loadingrules .ExplicitPath = path
21
+
22
+ cfg , err := clientcmd .NewNonInteractiveDeferredLoadingClientConfig (
23
+ loadingrules ,
24
+ & clientcmd.ConfigOverrides {},
25
+ ).ClientConfig ()
26
+ if err != nil {
27
+ return nil , errors .WithStack (err )
34
28
}
29
+
30
+ return cfg , nil
35
31
}
0 commit comments