-
Notifications
You must be signed in to change notification settings - Fork 297
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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
- Loading branch information
Showing
27 changed files
with
2,030 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> | ||
<ItemGroup> | ||
<ProjectReference Include="$(MSBuildThisFileDirectory)\..\src\KubernetesClient\KubernetesClient.csproj" /> | ||
<ProjectReference Include="$(MSBuildThisFileDirectory)\..\src\KubernetesClient\KubernetesClient.csproj" Condition="'$(PublishAot)' != 'true'" /> | ||
</ItemGroup> | ||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
using k8s; | ||
|
||
var config = KubernetesClientConfiguration.BuildDefaultConfig(); | ||
IKubernetes client = new Kubernetes(config); | ||
Console.WriteLine("Starting Request!"); | ||
|
||
var list = client.CoreV1.ListNamespacedPod("default"); | ||
foreach (var item in list.Items) | ||
{ | ||
Console.WriteLine(item.Metadata.Name); | ||
} | ||
|
||
if (list.Items.Count == 0) | ||
{ | ||
Console.WriteLine("Empty!"); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
<PropertyGroup> | ||
<OutputType>Exe</OutputType> | ||
<ImplicitUsings>enable</ImplicitUsings> | ||
<Nullable>enable</Nullable> | ||
<PublishAot>true</PublishAot> | ||
</PropertyGroup> | ||
<ItemGroup> | ||
<ProjectReference Include="..\..\src\KubernetesClient.Aot\KubernetesClient.Aot.csproj"/> | ||
</ItemGroup> | ||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
global using k8s.Autorest; | ||
global using k8s.Models; | ||
global using System; | ||
global using System.Collections.Generic; | ||
global using System.IO; | ||
global using System.Linq; | ||
global using System.Text.Json; | ||
global using System.Text.Json.Serialization; | ||
global using System.Threading; | ||
global using System.Threading.Tasks; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
using YamlDotNet.Serialization; | ||
|
||
namespace k8s.KubeConfigModels | ||
{ | ||
/// <summary> | ||
/// Contains information that describes identity information. This is use to tell the kubernetes cluster who you are. | ||
/// </summary> | ||
[YamlSerializable] | ||
public class AuthProvider | ||
{ | ||
/// <summary> | ||
/// Gets or sets the nickname for this auth provider. | ||
/// </summary> | ||
[YamlMember(Alias = "name")] | ||
public string Name { get; set; } | ||
|
||
/// <summary> | ||
/// Gets or sets the configuration for this auth provider | ||
/// </summary> | ||
[YamlMember(Alias = "config")] | ||
public Dictionary<string, string> Config { get; set; } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
using YamlDotNet.Serialization; | ||
|
||
namespace k8s.KubeConfigModels | ||
{ | ||
/// <summary> | ||
/// Relates nicknames to cluster information. | ||
/// </summary> | ||
[YamlSerializable] | ||
public class Cluster | ||
{ | ||
/// <summary> | ||
/// Gets or sets the cluster information. | ||
/// </summary> | ||
[YamlMember(Alias = "cluster")] | ||
public ClusterEndpoint ClusterEndpoint { get; set; } | ||
|
||
/// <summary> | ||
/// Gets or sets the nickname for this Cluster. | ||
/// </summary> | ||
[YamlMember(Alias = "name")] | ||
public string Name { get; set; } | ||
} | ||
} |
42 changes: 42 additions & 0 deletions
42
src/KubernetesClient.Aot/KubeConfigModels/ClusterEndpoint.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
using YamlDotNet.Serialization; | ||
|
||
namespace k8s.KubeConfigModels | ||
{ | ||
/// <summary> | ||
/// Contains information about how to communicate with a kubernetes cluster | ||
/// </summary> | ||
[YamlSerializable] | ||
public class ClusterEndpoint | ||
{ | ||
/// <summary> | ||
/// Gets or sets the path to a cert file for the certificate authority. | ||
/// </summary> | ||
[YamlMember(Alias = "certificate-authority", ApplyNamingConventions = false)] | ||
public string CertificateAuthority { get; set; } | ||
|
||
/// <summary> | ||
/// Gets or sets =PEM-encoded certificate authority certificates. Overrides <see cref="CertificateAuthority"/>. | ||
/// </summary> | ||
[YamlMember(Alias = "certificate-authority-data", ApplyNamingConventions = false)] | ||
public string CertificateAuthorityData { get; set; } | ||
|
||
/// <summary> | ||
/// Gets or sets the address of the kubernetes cluster (https://hostname:port). | ||
/// </summary> | ||
[YamlMember(Alias = "server")] | ||
public string Server { get; set; } | ||
|
||
/// <summary> | ||
/// Gets or sets a value to override the TLS server name. | ||
/// </summary> | ||
[YamlMember(Alias = "tls-server-name", ApplyNamingConventions = false)] | ||
public string TlsServerName { get; set; } | ||
|
||
/// <summary> | ||
/// Gets or sets a value indicating whether to skip the validity check for the server's certificate. | ||
/// This will make your HTTPS connections insecure. | ||
/// </summary> | ||
[YamlMember(Alias = "insecure-skip-tls-verify", ApplyNamingConventions = false)] | ||
public bool SkipTlsVerify { get; set; } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
using YamlDotNet.Serialization; | ||
|
||
namespace k8s.KubeConfigModels | ||
{ | ||
/// <summary> | ||
/// Relates nicknames to context information. | ||
/// </summary> | ||
[YamlSerializable] | ||
public class Context | ||
{ | ||
/// <summary> | ||
/// Gets or sets the context information. | ||
/// </summary> | ||
[YamlMember(Alias = "context")] | ||
public ContextDetails ContextDetails { get; set; } | ||
|
||
/// <summary> | ||
/// Gets or sets the nickname for this context. | ||
/// </summary> | ||
[YamlMember(Alias = "name")] | ||
public string Name { get; set; } | ||
} | ||
} |
30 changes: 30 additions & 0 deletions
30
src/KubernetesClient.Aot/KubeConfigModels/ContextDetails.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
using YamlDotNet.Serialization; | ||
|
||
namespace k8s.KubeConfigModels | ||
{ | ||
/// <summary> | ||
/// Represents a tuple of references to a cluster (how do I communicate with a kubernetes cluster), | ||
/// a user (how do I identify myself), and a namespace (what subset of resources do I want to work with) | ||
/// </summary> | ||
[YamlSerializable] | ||
public class ContextDetails | ||
{ | ||
/// <summary> | ||
/// Gets or sets the name of the cluster for this context. | ||
/// </summary> | ||
[YamlMember(Alias = "cluster")] | ||
public string Cluster { get; set; } | ||
|
||
/// <summary> | ||
/// Gets or sets the name of the user for this context. | ||
/// </summary> | ||
[YamlMember(Alias = "user")] | ||
public string User { get; set; } | ||
|
||
/// <summary> | ||
/// /Gets or sets the default namespace to use on unspecified requests. | ||
/// </summary> | ||
[YamlMember(Alias = "namespace")] | ||
public string Namespace { get; set; } | ||
} | ||
} |
31 changes: 31 additions & 0 deletions
31
src/KubernetesClient.Aot/KubeConfigModels/ExecCredentialResponse.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
using YamlDotNet.Serialization; | ||
|
||
namespace k8s.KubeConfigModels | ||
{ | ||
[YamlSerializable] | ||
public class ExecCredentialResponse | ||
{ | ||
public class ExecStatus | ||
{ | ||
#nullable enable | ||
public DateTime? ExpirationTimestamp { get; set; } | ||
public string? Token { get; set; } | ||
public string? ClientCertificateData { get; set; } | ||
public string? ClientKeyData { get; set; } | ||
#nullable disable | ||
|
||
public bool IsValid() | ||
{ | ||
return !string.IsNullOrEmpty(Token) || | ||
(!string.IsNullOrEmpty(ClientCertificateData) && !string.IsNullOrEmpty(ClientKeyData)); | ||
} | ||
} | ||
|
||
[JsonPropertyName("apiVersion")] | ||
public string ApiVersion { get; set; } | ||
[JsonPropertyName("kind")] | ||
public string Kind { get; set; } | ||
[JsonPropertyName("status")] | ||
public ExecStatus Status { get; set; } | ||
} | ||
} |
42 changes: 42 additions & 0 deletions
42
src/KubernetesClient.Aot/KubeConfigModels/ExternalExecution.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
using YamlDotNet.Serialization; | ||
|
||
namespace k8s.KubeConfigModels | ||
{ | ||
[YamlSerializable] | ||
public class ExternalExecution | ||
{ | ||
[YamlMember(Alias = "apiVersion")] | ||
public string ApiVersion { get; set; } | ||
|
||
/// <summary> | ||
/// The command to execute. Required. | ||
/// </summary> | ||
[YamlMember(Alias = "command")] | ||
public string Command { get; set; } | ||
|
||
/// <summary> | ||
/// Environment variables to set when executing the plugin. Optional. | ||
/// </summary> | ||
[YamlMember(Alias = "env")] | ||
public IList<Dictionary<string, string>> EnvironmentVariables { get; set; } | ||
|
||
/// <summary> | ||
/// Arguments to pass when executing the plugin. Optional. | ||
/// </summary> | ||
[YamlMember(Alias = "args")] | ||
public IList<string> Arguments { get; set; } | ||
|
||
/// <summary> | ||
/// Text shown to the user when the executable doesn't seem to be present. Optional. | ||
/// </summary> | ||
[YamlMember(Alias = "installHint")] | ||
public string InstallHint { get; set; } | ||
|
||
/// <summary> | ||
/// Whether or not to provide cluster information to this exec plugin as a part of | ||
/// the KUBERNETES_EXEC_INFO environment variable. Optional. | ||
/// </summary> | ||
[YamlMember(Alias = "provideClusterInfo")] | ||
public bool ProvideClusterInfo { get; set; } | ||
} | ||
} |
65 changes: 65 additions & 0 deletions
65
src/KubernetesClient.Aot/KubeConfigModels/K8SConfiguration.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
using YamlDotNet.Serialization; | ||
|
||
namespace k8s.KubeConfigModels | ||
{ | ||
/// <summary> | ||
/// kubeconfig configuration model. Holds the information needed to build connect to remote | ||
/// Kubernetes clusters as a given user. | ||
/// </summary> | ||
/// <remarks> | ||
/// 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 | ||
/// Should update MergeKubeConfig in KubernetesClientConfiguration.ConfigFile.cs if updated. | ||
/// </remarks> | ||
[YamlSerializable] | ||
public class K8SConfiguration | ||
{ | ||
// /// <summary> | ||
// /// Gets or sets general information to be use for CLI interactions | ||
// /// </summary> | ||
// [YamlMember(Alias = "preferences")] | ||
// public IDictionary<string, object> Preferences { get; set; } | ||
|
||
[YamlMember(Alias = "apiVersion")] | ||
public string ApiVersion { get; set; } | ||
|
||
[YamlMember(Alias = "kind")] | ||
public string Kind { get; set; } | ||
|
||
/// <summary> | ||
/// Gets or sets the name of the context that you would like to use by default. | ||
/// </summary> | ||
[YamlMember(Alias = "current-context", ApplyNamingConventions = false)] | ||
public string CurrentContext { get; set; } | ||
|
||
/// <summary> | ||
/// Gets or sets a map of referencable names to context configs. | ||
/// </summary> | ||
[YamlMember(Alias = "contexts")] | ||
public List<Context> Contexts { get; set; } = new List<Context>(); | ||
|
||
/// <summary> | ||
/// Gets or sets a map of referencable names to cluster configs. | ||
/// </summary> | ||
[YamlMember(Alias = "clusters")] | ||
public List<Cluster> Clusters { get; set; } = new List<Cluster>(); | ||
|
||
/// <summary> | ||
/// Gets or sets a map of referencable names to user configs | ||
/// </summary> | ||
[YamlMember(Alias = "users")] | ||
public List<User> Users { get; set; } = new List<User>(); | ||
|
||
// /// <summary> | ||
// /// Gets or sets additional information. This is useful for extenders so that reads and writes don't clobber unknown fields. | ||
// /// </summary> | ||
// [YamlMember(Alias = "extensions")] | ||
// public List<NamedExtension> Extensions { get; set; } | ||
|
||
/// <summary> | ||
/// Gets or sets the name of the Kubernetes configuration file. This property is set only when the configuration | ||
/// was loaded from disk, and can be used to resolve relative paths. | ||
/// </summary> | ||
[YamlIgnore] | ||
public string FileName { get; set; } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
using YamlDotNet.Serialization; | ||
|
||
namespace k8s.KubeConfigModels; | ||
|
||
[YamlStaticContext] | ||
public partial class StaticContext : YamlDotNet.Serialization.StaticContext | ||
{ | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
using YamlDotNet.Serialization; | ||
|
||
namespace k8s.KubeConfigModels | ||
{ | ||
/// <summary> | ||
/// Relates nicknames to auth information. | ||
/// </summary> | ||
[YamlSerializable] | ||
public class User | ||
{ | ||
/// <summary> | ||
/// Gets or sets the auth information. | ||
/// </summary> | ||
[YamlMember(Alias = "user")] | ||
public UserCredentials UserCredentials { get; set; } | ||
|
||
/// <summary> | ||
/// Gets or sets the nickname for this auth information. | ||
/// </summary> | ||
[YamlMember(Alias = "name")] | ||
public string Name { get; set; } | ||
} | ||
} |
Oops, something went wrong.