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)
| 537 | // are passed in we fallback to inClusterConfig. If inClusterConfig fails, we fallback |
| 538 | // to the default config. |
| 539 | func 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. |