MCPcopy
hub / github.com/kubernetes/client-go / BuildConfigFromFlags

Function BuildConfigFromFlags

tools/clientcmd/client_config.go:539–551  ·  view source on GitHub ↗

BuildConfigFromFlags is a helper function that builds configs from a master url or a kubeconfig filepath. These are passed in as command line flags for cluster components. Warnings should reflect this usage. If neither masterUrl or kubeconfigPath are passed in we fallback to inClusterConfig. If inCl

(masterUrl, kubeconfigPath string)

Source from the content-addressed store, hash-verified

537// are passed in we fallback to inClusterConfig. If inClusterConfig fails, we fallback
538// to the default config.
539func BuildConfigFromFlags(masterUrl, kubeconfigPath string) (*restclient.Config, error) {
540 if kubeconfigPath == "" && masterUrl == "" {
541 klog.Warningf("Neither --kubeconfig nor --master was specified. Using the inClusterConfig. This might not work.")
542 kubeconfig, err := restclient.InClusterConfig()
543 if err == nil {
544 return kubeconfig, nil
545 }
546 klog.Warning("error creating inClusterConfig, falling back to default config: ", err)
547 }
548 return NewNonInteractiveDeferredLoadingClientConfig(
549 &ClientConfigLoadingRules{ExplicitPath: kubeconfigPath},
550 &ConfigOverrides{ClusterInfo: clientcmdapi.Cluster{Server: masterUrl}}).ClientConfig()
551}
552
553// BuildConfigFromKubeconfigGetter is a helper function that builds configs from a master
554// url and a kubeconfigGetter.

Callers 5

mainFunction · 0.92
mainFunction · 0.92
buildConfigFunction · 0.92
mainFunction · 0.92
TestAuthConfigMergeFunction · 0.85

Tested by 1

TestAuthConfigMergeFunction · 0.68