Skip to content

Commit 805cc31

Browse files
Merge pull request #4 from krabhishek8260/auth
Add support for connecting/authenticating through kubeconfig
2 parents 810560e + ad74a08 commit 805cc31

18 files changed

+709
-24
lines changed

.gitignore

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,9 @@
22
.vs
33
obj/
44
bin/
5+
6+
# User-specific VS files
7+
*.suo
8+
*.user
9+
*.userosscache
10+
*.sln.docstates

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# csharp
22
Work In Progress
3+
Currently only supported on Linux
34

45
# Generating the client code
56

examples/simple/PodList.cs

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,17 @@
1-
using System;
2-
3-
using k8s;
4-
5-
namespace simple
1+
namespace simple
62
{
3+
using System;
4+
using System.IO;
5+
using k8s;
6+
77
class PodList
88
{
99
static void Main(string[] args)
1010
{
11-
IKubernetes client = new Kubernetes();
12-
client.BaseUri = new Uri("http://localhost:8001");
13-
var listTask = client.ListNamespacedPodWithHttpMessagesAsync("default");
14-
listTask.Wait();
15-
var list = listTask.Result.Body;
11+
var k8sClientConfig = new KubernetesClientConfiguration();
12+
IKubernetes client = new Kubernetes(k8sClientConfig);
13+
var listTask = client.ListNamespacedPodWithHttpMessagesAsync("default").Result;
14+
var list = listTask.Body;
1615
foreach (var item in list.Items) {
1716
Console.WriteLine(item.Metadata.Name);
1817
}

examples/simple/simple.csproj

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
1-
<Project Sdk="Microsoft.NET.Sdk">
2-
3-
<ItemGroup>
4-
<PackageReference Include="Microsoft.Rest.ClientRuntime" Version="3.0.3" />
5-
<PackageReference Include="Newtonsoft.Json" Version="10.0.2" />
6-
<ProjectReference Include="..\..\src\csharp.csproj" />
7-
</ItemGroup>
8-
9-
<PropertyGroup>
10-
<OutputType>Exe</OutputType>
11-
<TargetFramework>netcoreapp1.1</TargetFramework>
12-
</PropertyGroup>
13-
14-
</Project>
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<ItemGroup>
4+
<PackageReference Include="Microsoft.Rest.ClientRuntime" Version="3.0.3" />
5+
<PackageReference Include="Newtonsoft.Json" Version="10.0.2" />
6+
<ProjectReference Include="..\..\src\KubernetesClient.csproj" />
7+
</ItemGroup>
8+
9+
<PropertyGroup>
10+
<OutputType>Exe</OutputType>
11+
<TargetFramework>netcoreapp1.1</TargetFramework>
12+
</PropertyGroup>
13+
14+
</Project>

src/Exceptions/KubeConfigException.cs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
namespace k8s.Exceptions
2+
{
3+
using System;
4+
5+
/// <summary>
6+
/// The exception that is thrown when the kube config is invalid
7+
/// </summary>
8+
public class KubeConfigException : Exception
9+
{
10+
public KubeConfigException()
11+
{
12+
}
13+
14+
public KubeConfigException(string message)
15+
: base(message)
16+
{
17+
}
18+
19+
public KubeConfigException(string message, Exception inner)
20+
: base(message, inner)
21+
{
22+
}
23+
}
24+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
namespace k8s.Exceptions
2+
{
3+
using System;
4+
5+
/// <summary>
6+
/// The exception that is thrown when there is a client exception
7+
/// </summary>
8+
public class KubernetesClientException : Exception
9+
{
10+
public KubernetesClientException()
11+
{
12+
}
13+
14+
public KubernetesClientException(string message)
15+
: base(message)
16+
{
17+
}
18+
19+
public KubernetesClientException(string message, Exception inner)
20+
: base(message, inner)
21+
{
22+
}
23+
}
24+
}

src/KubeConfigModels/Cluster.cs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
namespace k8s.KubeConfigModels
2+
{
3+
using YamlDotNet.Serialization;
4+
5+
public class Cluster
6+
{
7+
[YamlMember(Alias = "cluster")]
8+
public ClusterEndpoint ClusterEndpoint { get; set; }
9+
10+
[YamlMember(Alias = "name")]
11+
public string Name { get; set; }
12+
}
13+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
namespace k8s.KubeConfigModels
2+
{
3+
using YamlDotNet.Serialization;
4+
5+
public class ClusterEndpoint
6+
{
7+
[YamlMember(Alias = "certificate-authority-data")]
8+
public string CertificateAuthorityData { get; set; }
9+
10+
[YamlMember(Alias = "server")]
11+
public string Server { get; set; }
12+
13+
[YamlMember(Alias = "insecure-skip-tls-verify")]
14+
public bool SkipTlsVerify { get; set; }
15+
}
16+
}

src/KubeConfigModels/Context.cs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
namespace k8s.KubeConfigModels
2+
{
3+
using YamlDotNet.Serialization;
4+
5+
public class Context
6+
{
7+
[YamlMember(Alias = "context")]
8+
public ContextDetails ContextDetails { get; set; }
9+
10+
[YamlMember(Alias = "name")]
11+
public string Name { get; set; }
12+
}
13+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
namespace k8s.KubeConfigModels
2+
{
3+
using YamlDotNet.RepresentationModel;
4+
using YamlDotNet.Serialization;
5+
6+
public class ContextDetails
7+
{
8+
[YamlMember(Alias = "cluster")]
9+
public string Cluster { get; set; }
10+
11+
[YamlMember(Alias = "user")]
12+
public string User { get; set; }
13+
14+
[YamlMember(Alias = "namespace")]
15+
public string Namespace { get; set; }
16+
}
17+
}

0 commit comments

Comments
 (0)