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

+10-1
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

+1-1
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

+16
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

+11
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

+10
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;
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+
}
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+
}
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+
}
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+
}
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+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
using YamlDotNet.Serialization;
2+
3+
namespace k8s.KubeConfigModels
4+
{
5+
[YamlSerializable]
6+
public class ExecCredentialResponse
7+
{
8+
public class ExecStatus
9+
{
10+
#nullable enable
11+
public DateTime? ExpirationTimestamp { get; set; }
12+
public string? Token { get; set; }
13+
public string? ClientCertificateData { get; set; }
14+
public string? ClientKeyData { get; set; }
15+
#nullable disable
16+
17+
public bool IsValid()
18+
{
19+
return !string.IsNullOrEmpty(Token) ||
20+
(!string.IsNullOrEmpty(ClientCertificateData) && !string.IsNullOrEmpty(ClientKeyData));
21+
}
22+
}
23+
24+
[JsonPropertyName("apiVersion")]
25+
public string ApiVersion { get; set; }
26+
[JsonPropertyName("kind")]
27+
public string Kind { get; set; }
28+
[JsonPropertyName("status")]
29+
public ExecStatus Status { get; set; }
30+
}
31+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
using YamlDotNet.Serialization;
2+
3+
namespace k8s.KubeConfigModels
4+
{
5+
[YamlSerializable]
6+
public class ExternalExecution
7+
{
8+
[YamlMember(Alias = "apiVersion")]
9+
public string ApiVersion { get; set; }
10+
11+
/// <summary>
12+
/// The command to execute. Required.
13+
/// </summary>
14+
[YamlMember(Alias = "command")]
15+
public string Command { get; set; }
16+
17+
/// <summary>
18+
/// Environment variables to set when executing the plugin. Optional.
19+
/// </summary>
20+
[YamlMember(Alias = "env")]
21+
public IList<Dictionary<string, string>> EnvironmentVariables { get; set; }
22+
23+
/// <summary>
24+
/// Arguments to pass when executing the plugin. Optional.
25+
/// </summary>
26+
[YamlMember(Alias = "args")]
27+
public IList<string> Arguments { get; set; }
28+
29+
/// <summary>
30+
/// Text shown to the user when the executable doesn't seem to be present. Optional.
31+
/// </summary>
32+
[YamlMember(Alias = "installHint")]
33+
public string InstallHint { get; set; }
34+
35+
/// <summary>
36+
/// Whether or not to provide cluster information to this exec plugin as a part of
37+
/// the KUBERNETES_EXEC_INFO environment variable. Optional.
38+
/// </summary>
39+
[YamlMember(Alias = "provideClusterInfo")]
40+
public bool ProvideClusterInfo { get; set; }
41+
}
42+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
using YamlDotNet.Serialization;
2+
3+
namespace k8s.KubeConfigModels
4+
{
5+
/// <summary>
6+
/// kubeconfig configuration model. Holds the information needed to build connect to remote
7+
/// Kubernetes clusters as a given user.
8+
/// </summary>
9+
/// <remarks>
10+
/// Should be kept in sync with https://github.com/kubernetes/kubernetes/blob/master/staging/src/k8s.io/client-go/tools/clientcmd/api/v1/types.go
11+
/// Should update MergeKubeConfig in KubernetesClientConfiguration.ConfigFile.cs if updated.
12+
/// </remarks>
13+
[YamlSerializable]
14+
public class K8SConfiguration
15+
{
16+
// /// <summary>
17+
// /// Gets or sets general information to be use for CLI interactions
18+
// /// </summary>
19+
// [YamlMember(Alias = "preferences")]
20+
// public IDictionary<string, object> Preferences { get; set; }
21+
22+
[YamlMember(Alias = "apiVersion")]
23+
public string ApiVersion { get; set; }
24+
25+
[YamlMember(Alias = "kind")]
26+
public string Kind { get; set; }
27+
28+
/// <summary>
29+
/// Gets or sets the name of the context that you would like to use by default.
30+
/// </summary>
31+
[YamlMember(Alias = "current-context", ApplyNamingConventions = false)]
32+
public string CurrentContext { get; set; }
33+
34+
/// <summary>
35+
/// Gets or sets a map of referencable names to context configs.
36+
/// </summary>
37+
[YamlMember(Alias = "contexts")]
38+
public List<Context> Contexts { get; set; } = new List<Context>();
39+
40+
/// <summary>
41+
/// Gets or sets a map of referencable names to cluster configs.
42+
/// </summary>
43+
[YamlMember(Alias = "clusters")]
44+
public List<Cluster> Clusters { get; set; } = new List<Cluster>();
45+
46+
/// <summary>
47+
/// Gets or sets a map of referencable names to user configs
48+
/// </summary>
49+
[YamlMember(Alias = "users")]
50+
public List<User> Users { get; set; } = new List<User>();
51+
52+
// /// <summary>
53+
// /// Gets or sets additional information. This is useful for extenders so that reads and writes don't clobber unknown fields.
54+
// /// </summary>
55+
// [YamlMember(Alias = "extensions")]
56+
// public List<NamedExtension> Extensions { get; set; }
57+
58+
/// <summary>
59+
/// Gets or sets the name of the Kubernetes configuration file. This property is set only when the configuration
60+
/// was loaded from disk, and can be used to resolve relative paths.
61+
/// </summary>
62+
[YamlIgnore]
63+
public string FileName { get; set; }
64+
}
65+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
using YamlDotNet.Serialization;
2+
3+
namespace k8s.KubeConfigModels;
4+
5+
[YamlStaticContext]
6+
public partial class StaticContext : YamlDotNet.Serialization.StaticContext
7+
{
8+
}
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 auth information.
7+
/// </summary>
8+
[YamlSerializable]
9+
public class User
10+
{
11+
/// <summary>
12+
/// Gets or sets the auth information.
13+
/// </summary>
14+
[YamlMember(Alias = "user")]
15+
public UserCredentials UserCredentials { get; set; }
16+
17+
/// <summary>
18+
/// Gets or sets the nickname for this auth information.
19+
/// </summary>
20+
[YamlMember(Alias = "name")]
21+
public string Name { get; set; }
22+
}
23+
}

0 commit comments

Comments
 (0)