Skip to content

Commit 759c101

Browse files
Add support Namespace in the kubeconfig file. (#72)
1 parent 2a54a8c commit 759c101

File tree

3 files changed

+16
-8
lines changed

3 files changed

+16
-8
lines changed

Diff for: src/KubeConfigModels/Context.cs

+3
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,8 @@ public class Context
99

1010
[YamlMember(Alias = "name")]
1111
public string Name { get; set; }
12+
13+
[YamlMember(Alias = "namespace")]
14+
public string Namespace { get; set; }
1215
}
1316
}

Diff for: src/KubernetesClientConfiguration.ConfigFile.cs

+8-8
Original file line numberDiff line numberDiff line change
@@ -53,13 +53,11 @@ public static KubernetesClientConfiguration BuildConfigFromConfigFile(FileInfo k
5353
var k8SConfiguration = new KubernetesClientConfiguration();
5454

5555
currentContext = currentContext ?? k8SConfig.CurrentContext;
56-
5756
// only init context if context if set
5857
if (currentContext != null)
5958
{
60-
k8SConfiguration.InitializeContext(k8SConfig, currentContext);
61-
}
62-
59+
k8SConfiguration.InitializeContext(k8SConfig, currentContext);
60+
}
6361
if (!string.IsNullOrWhiteSpace(masterUrl))
6462
{
6563
k8SConfiguration.Host = masterUrl;
@@ -68,8 +66,8 @@ public static KubernetesClientConfiguration BuildConfigFromConfigFile(FileInfo k
6866
if (string.IsNullOrWhiteSpace(k8SConfiguration.Host))
6967
{
7068
throw new KubeConfigException("Cannot infer server host url either from context or masterUrl");
71-
}
72-
69+
}
70+
7371
return k8SConfiguration;
7472
}
7573

@@ -96,6 +94,9 @@ private void InitializeContext(K8SConfiguration k8SConfig, string currentContext
9694

9795
// user
9896
SetUserDetails(k8SConfig, activeContext);
97+
98+
// namespace
99+
Namespace = activeContext.Namespace;
99100
}
100101

101102
private void SetClusterDetails(K8SConfiguration k8SConfig, Context activeContext)
@@ -122,8 +123,7 @@ private void SetClusterDetails(K8SConfiguration k8SConfig, Context activeContext
122123
var uri = new Uri(Host);
123124
if (uri.Scheme == "https")
124125
{
125-
126-
// check certificate for https
126+
// check certificate for https
127127
if (!clusterDetails.ClusterEndpoint.SkipTlsVerify &&
128128
string.IsNullOrWhiteSpace(clusterDetails.ClusterEndpoint.CertificateAuthorityData) &&
129129
string.IsNullOrWhiteSpace(clusterDetails.ClusterEndpoint.CertificateAuthority))

Diff for: src/KubernetesClientConfiguration.cs

+5
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,11 @@ namespace k8s
77
/// </summary>
88
public partial class KubernetesClientConfiguration
99
{
10+
/// <summary>
11+
/// Gets current namespace
12+
/// </summary>
13+
public string Namespace { get; set; }
14+
1015
/// <summary>
1116
/// Gets Host
1217
/// </summary>

0 commit comments

Comments
 (0)