Skip to content

Commit 00c4c6f

Browse files
authored
add KubernetesClient.Aot to support Aot (#1498)
* init aot * fix ca2007 * xUnit1031 * fix ca2007 * fix ca2007 * remove deprecated ctor * fix xUnit1031 * fix missing doc * fix missing dispose * wait for warnings fix * fix space * move aot code to dedicated proj * Remove commented out code * eliminate know warnings * add e2e test for aot * rever on field convert annotation * add e2e aot gh * Add KubernetesClient.Aot project reference * move CA1812 rule violation to file
1 parent c7060d4 commit 00c4c6f

27 files changed

+2030
-3
lines changed

.github/workflows/buildtest.yaml

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,16 @@ jobs:
8080
cat skip.log
8181
echo "CASES MUST NOT BE SKIPPED"
8282
exit 1
83-
fi
83+
fi
84+
- name: AOT Test
85+
run: |
86+
true > skip.log
87+
env K8S_E2E_MINIKUBE=1 dotnet test tests/E2E.Aot.Tests --logger "SkipTestLogger;file=$PWD/skip.log"
88+
if [ -s skip.log ]; then
89+
cat skip.log
90+
echo "CASES MUST NOT BE SKIPPED"
91+
exit 1
92+
fi
8493
8594
on:
8695
pull_request:

examples/Directory.Build.targets

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
22
<ItemGroup>
3-
<ProjectReference Include="$(MSBuildThisFileDirectory)\..\src\KubernetesClient\KubernetesClient.csproj" />
3+
<ProjectReference Include="$(MSBuildThisFileDirectory)\..\src\KubernetesClient\KubernetesClient.csproj" Condition="'$(PublishAot)' != 'true'" />
44
</ItemGroup>
55
</Project>

examples/aot/Program.cs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
using k8s;
2+
3+
var config = KubernetesClientConfiguration.BuildDefaultConfig();
4+
IKubernetes client = new Kubernetes(config);
5+
Console.WriteLine("Starting Request!");
6+
7+
var list = client.CoreV1.ListNamespacedPod("default");
8+
foreach (var item in list.Items)
9+
{
10+
Console.WriteLine(item.Metadata.Name);
11+
}
12+
13+
if (list.Items.Count == 0)
14+
{
15+
Console.WriteLine("Empty!");
16+
}

examples/aot/aot.csproj

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
<PropertyGroup>
3+
<OutputType>Exe</OutputType>
4+
<ImplicitUsings>enable</ImplicitUsings>
5+
<Nullable>enable</Nullable>
6+
<PublishAot>true</PublishAot>
7+
</PropertyGroup>
8+
<ItemGroup>
9+
<ProjectReference Include="..\..\src\KubernetesClient.Aot\KubernetesClient.Aot.csproj"/>
10+
</ItemGroup>
11+
</Project>

src/KubernetesClient.Aot/Global.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
global using k8s.Autorest;
2+
global using k8s.Models;
3+
global using System;
4+
global using System.Collections.Generic;
5+
global using System.IO;
6+
global using System.Linq;
7+
global using System.Text.Json;
8+
global using System.Text.Json.Serialization;
9+
global using System.Threading;
10+
global using System.Threading.Tasks;
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
using YamlDotNet.Serialization;
2+
3+
namespace k8s.KubeConfigModels
4+
{
5+
/// <summary>
6+
/// Contains information that describes identity information. This is use to tell the kubernetes cluster who you are.
7+
/// </summary>
8+
[YamlSerializable]
9+
public class AuthProvider
10+
{
11+
/// <summary>
12+
/// Gets or sets the nickname for this auth provider.
13+
/// </summary>
14+
[YamlMember(Alias = "name")]
15+
public string Name { get; set; }
16+
17+
/// <summary>
18+
/// Gets or sets the configuration for this auth provider
19+
/// </summary>
20+
[YamlMember(Alias = "config")]
21+
public Dictionary<string, string> Config { get; set; }
22+
}
23+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
using YamlDotNet.Serialization;
2+
3+
namespace k8s.KubeConfigModels
4+
{
5+
/// <summary>
6+
/// Relates nicknames to cluster information.
7+
/// </summary>
8+
[YamlSerializable]
9+
public class Cluster
10+
{
11+
/// <summary>
12+
/// Gets or sets the cluster information.
13+
/// </summary>
14+
[YamlMember(Alias = "cluster")]
15+
public ClusterEndpoint ClusterEndpoint { get; set; }
16+
17+
/// <summary>
18+
/// Gets or sets the nickname for this Cluster.
19+
/// </summary>
20+
[YamlMember(Alias = "name")]
21+
public string Name { get; set; }
22+
}
23+
}
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
using YamlDotNet.Serialization;
2+
3+
namespace k8s.KubeConfigModels
4+
{
5+
/// <summary>
6+
/// Contains information about how to communicate with a kubernetes cluster
7+
/// </summary>
8+
[YamlSerializable]
9+
public class ClusterEndpoint
10+
{
11+
/// <summary>
12+
/// Gets or sets the path to a cert file for the certificate authority.
13+
/// </summary>
14+
[YamlMember(Alias = "certificate-authority", ApplyNamingConventions = false)]
15+
public string CertificateAuthority { get; set; }
16+
17+
/// <summary>
18+
/// Gets or sets =PEM-encoded certificate authority certificates. Overrides <see cref="CertificateAuthority"/>.
19+
/// </summary>
20+
[YamlMember(Alias = "certificate-authority-data", ApplyNamingConventions = false)]
21+
public string CertificateAuthorityData { get; set; }
22+
23+
/// <summary>
24+
/// Gets or sets the address of the kubernetes cluster (https://hostname:port).
25+
/// </summary>
26+
[YamlMember(Alias = "server")]
27+
public string Server { get; set; }
28+
29+
/// <summary>
30+
/// Gets or sets a value to override the TLS server name.
31+
/// </summary>
32+
[YamlMember(Alias = "tls-server-name", ApplyNamingConventions = false)]
33+
public string TlsServerName { get; set; }
34+
35+
/// <summary>
36+
/// Gets or sets a value indicating whether to skip the validity check for the server's certificate.
37+
/// This will make your HTTPS connections insecure.
38+
/// </summary>
39+
[YamlMember(Alias = "insecure-skip-tls-verify", ApplyNamingConventions = false)]
40+
public bool SkipTlsVerify { get; set; }
41+
}
42+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
using YamlDotNet.Serialization;
2+
3+
namespace k8s.KubeConfigModels
4+
{
5+
/// <summary>
6+
/// Relates nicknames to context information.
7+
/// </summary>
8+
[YamlSerializable]
9+
public class Context
10+
{
11+
/// <summary>
12+
/// Gets or sets the context information.
13+
/// </summary>
14+
[YamlMember(Alias = "context")]
15+
public ContextDetails ContextDetails { get; set; }
16+
17+
/// <summary>
18+
/// Gets or sets the nickname for this context.
19+
/// </summary>
20+
[YamlMember(Alias = "name")]
21+
public string Name { get; set; }
22+
}
23+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
using YamlDotNet.Serialization;
2+
3+
namespace k8s.KubeConfigModels
4+
{
5+
/// <summary>
6+
/// Represents a tuple of references to a cluster (how do I communicate with a kubernetes cluster),
7+
/// a user (how do I identify myself), and a namespace (what subset of resources do I want to work with)
8+
/// </summary>
9+
[YamlSerializable]
10+
public class ContextDetails
11+
{
12+
/// <summary>
13+
/// Gets or sets the name of the cluster for this context.
14+
/// </summary>
15+
[YamlMember(Alias = "cluster")]
16+
public string Cluster { get; set; }
17+
18+
/// <summary>
19+
/// Gets or sets the name of the user for this context.
20+
/// </summary>
21+
[YamlMember(Alias = "user")]
22+
public string User { get; set; }
23+
24+
/// <summary>
25+
/// /Gets or sets the default namespace to use on unspecified requests.
26+
/// </summary>
27+
[YamlMember(Alias = "namespace")]
28+
public string Namespace { get; set; }
29+
}
30+
}

0 commit comments

Comments
 (0)