Improve the default client loading code. (#251)

* Improve the default client loading code.

* Address comments.
This commit is contained in:
Brendan Burns
2019-03-06 01:26:04 -08:00
committed by Kubernetes Prow Robot
parent e0db2ae8bd
commit de99b2b6b4
3 changed files with 41 additions and 6 deletions

View File

@@ -24,6 +24,26 @@ namespace k8s
/// </summary>
public string CurrentContext { get; private set; }
/// <summary>
/// Initializes a new instance of the <see cref="KubernetesClientConfiguration" /> from config file
/// </summary>
public static KubernetesClientConfiguration BuildDefaultConfig() {
var kubeconfig = Environment.GetEnvironmentVariable("KUBECONFIG");
if (kubeconfig != null) {
return BuildConfigFromConfigFile(kubeconfigPath: kubeconfig);
}
if (File.Exists(KubeConfigDefaultLocation)) {
return BuildConfigFromConfigFile(kubeconfigPath: KubeConfigDefaultLocation);
}
if (IsInCluster()) {
return InClusterConfig();
}
var config = new KubernetesClientConfiguration();
config.Host = "http://localhost:8080";
return config;
}
/// <summary>
/// Initializes a new instance of the <see cref="KubernetesClientConfiguration" /> from config file
/// </summary>