Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add KubernetesClient.Aot to support Aot #1498

Merged
merged 21 commits into from
Jan 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion .github/workflows/buildtest.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,16 @@ jobs:
cat skip.log
echo "CASES MUST NOT BE SKIPPED"
exit 1
fi
fi
- name: AOT Test
run: |
true > skip.log
env K8S_E2E_MINIKUBE=1 dotnet test tests/E2E.Aot.Tests --logger "SkipTestLogger;file=$PWD/skip.log"
if [ -s skip.log ]; then
cat skip.log
echo "CASES MUST NOT BE SKIPPED"
exit 1
fi

on:
pull_request:
Expand Down
2 changes: 1 addition & 1 deletion examples/Directory.Build.targets
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>
16 changes: 16 additions & 0 deletions examples/aot/Program.cs
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!");
}
11 changes: 11 additions & 0 deletions examples/aot/aot.csproj
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>
10 changes: 10 additions & 0 deletions src/KubernetesClient.Aot/Global.cs
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;
23 changes: 23 additions & 0 deletions src/KubernetesClient.Aot/KubeConfigModels/AuthProvider.cs
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; }
}
}
23 changes: 23 additions & 0 deletions src/KubernetesClient.Aot/KubeConfigModels/Cluster.cs
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 src/KubernetesClient.Aot/KubeConfigModels/ClusterEndpoint.cs
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; }
}
}
23 changes: 23 additions & 0 deletions src/KubernetesClient.Aot/KubeConfigModels/Context.cs
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 src/KubernetesClient.Aot/KubeConfigModels/ContextDetails.cs
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; }
}
}
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 src/KubernetesClient.Aot/KubeConfigModels/ExternalExecution.cs
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 src/KubernetesClient.Aot/KubeConfigModels/K8SConfiguration.cs
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; }
}
}
8 changes: 8 additions & 0 deletions src/KubernetesClient.Aot/KubeConfigModels/StaticContext.cs
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
{
}
23 changes: 23 additions & 0 deletions src/KubernetesClient.Aot/KubeConfigModels/User.cs
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; }
}
}
Loading
Loading