Improve the default client loading code. (#251)
* Improve the default client loading code. * Address comments.
This commit is contained in:
committed by
Kubernetes Prow Robot
parent
e0db2ae8bd
commit
de99b2b6b4
@@ -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>
|
||||
|
||||
Reference in New Issue
Block a user