@@ -10,26 +10,22 @@ import (
1010// empty, the kube config will be loaded from KUBECONFIG, and if KUBECONFIG
1111// isn't set, the in-cluster config will be used.
1212func 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.
1417 // If the kubeconfig path is not provided, use the default loading rules
1518 // so we read the regular KUBECONFIG variable or create a non-interactive
1619 // 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 )
3428 }
29+
30+ return cfg , nil
3531}
0 commit comments