diff --git a/examples/simple/PodList.cs b/examples/simple/PodList.cs index 32c8fb2aa..e2a567071 100755 --- a/examples/simple/PodList.cs +++ b/examples/simple/PodList.cs @@ -8,7 +8,11 @@ class PodList { static void Main(string[] args) { - var k8sClientConfig = new KubernetesClientConfiguration(); + var k8sClientConfig = KubernetesClientConfiguration.defaultConfiguration(); + if (k8sClientConfig.CurrentContext == null) { + Console.WriteLine("No current context"); + return; + } IKubernetes client = new Kubernetes(k8sClientConfig); Console.WriteLine("Starting Request!"); var listTask = client.ListNamespacedPodWithHttpMessagesAsync("default").Result; diff --git a/src/KubernetesClient.csproj b/src/KubernetesClient.csproj index 2d90d215b..d5fcd6311 100644 --- a/src/KubernetesClient.csproj +++ b/src/KubernetesClient.csproj @@ -1,6 +1,9 @@ + Library netstandard2.0 + 0.1.0 + beta @@ -12,4 +15,4 @@ - \ No newline at end of file + diff --git a/src/KubernetesClientConfiguration.cs b/src/KubernetesClientConfiguration.cs index 90ed05eac..f70625f64 100644 --- a/src/KubernetesClientConfiguration.cs +++ b/src/KubernetesClientConfiguration.cs @@ -25,6 +25,15 @@ public KubernetesClientConfiguration(FileInfo kubeconfig = null, string currentC this.Initialize(k8SConfig, currentContext); } + public static KubernetesClientConfiguration defaultConfiguration() { + var kubeConfig = Environment.GetEnvironmentVariable("KUBECONFIG"); + if (kubeConfig != null) { + return new KubernetesClientConfiguration(new FileInfo(kubeConfig)); + } + return new KubernetesClientConfiguration(); + } + + /// /// kubeconfig Default Location /// @@ -120,6 +129,10 @@ private void Initialize(K8SConfiguration k8SConfig, string currentContext = null // current context currentContext = currentContext ?? k8SConfig.CurrentContext; + if (string.IsNullOrEmpty(currentContext)) { + // Nothing more to do... + return; + } Context activeContext = k8SConfig.Contexts.FirstOrDefault(c => c.Name.Equals(currentContext, StringComparison.OrdinalIgnoreCase)); if (activeContext == null) {