Skip to content

Version 17.0 + Generate 1.33 #1626

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

Merged
merged 13 commits into from
Apr 27, 2025
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
2 changes: 1 addition & 1 deletion .github/workflows/buildtest.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ jobs:
- name: Setup dotnet SDK
uses: actions/setup-dotnet@v4
with:
dotnet-version: '8.0.x'
dotnet-version: '9.0.x'
- name: Restore nugets (msbuild)
run: msbuild .\src\KubernetesClient\ -t:restore -p:RestorePackagesConfig=true
- name: Build (msbuild)
Expand Down
104 changes: 52 additions & 52 deletions Directory.Packages.props
Original file line number Diff line number Diff line change
@@ -1,53 +1,53 @@
<Project>
<PropertyGroup>
<ManagePackageVersionsCentrally>true</ManagePackageVersionsCentrally>
</PropertyGroup>
<ItemGroup>
<PackageVersion Include="AutoMapper" Version="13.0.1" />
<PackageVersion Include="BouncyCastle.Cryptography" Version="2.5.0" />
<PackageVersion Include="FluentAssertions" Version="7.0.0" />
<PackageVersion Include="Fractions" Version="7.3.0" />
<PackageVersion Include="JsonPatch.Net" Version="2.1.0" />
<PackageVersion Include="MartinCostello.Logging.XUnit" Version="0.5.1" />
<PackageVersion Include="Microsoft.Bcl.AsyncInterfaces" Version="9.0.0" />
<PackageVersion Include="Microsoft.Extensions.Hosting" Version="9.0.0" />
<PackageVersion Include="Microsoft.Extensions.Logging" Version="9.0.0" />
<PackageVersion Include="Microsoft.NET.Test.Sdk" Version="17.12.0" />
<PackageVersion Include="Microsoft.TestPlatform.ObjectModel" Version="17.12.0" />
<PackageVersion Include="Moq" Version="4.20.72" />
<PackageVersion Include="Nito.AsyncEx" Version="5.1.2" />
<PackageVersion Include="Nito.AsyncEx.Coordination" Version="5.1.2" />
<PackageVersion Include="OpenTelemetry.Exporter.Console" Version="1.7.0" />
<PackageVersion Include="OpenTelemetry.Instrumentation.Http" Version="1.8.1" />
<PackageVersion Include="Portable.BouncyCastle" Version="1.9.0" />
<PackageVersion Include="SharpZipLib" Version="1.4.2" />
<PackageVersion Include="Swashbuckle.AspNetCore" Version="6.5.0" />
<PackageVersion Include="System.Diagnostics.DiagnosticSource" Version="9.0.0" />
<PackageVersion Include="System.IO.Abstractions.TestingHelpers" Version="21.2.1" />
<PackageVersion Include="System.Reactive" Version="6.0.1" />
<PackageVersion Include="System.Text.Json" Version="9.0.0" />
<PackageVersion Include="Vecc.YamlDotNet.Analyzers.StaticGenerator" Version="16.3.0" />
<PackageVersion Include="Wiremock.Net" Version="1.7.4" />
<PackageVersion Include="xunit" Version="2.9.2" />
<PackageVersion Include="xunit.runner.visualstudio" Version="3.0.0" />
<PackageVersion Include="Xunit.StaFact" Version="1.1.11" />
<PackageVersion Include="YamlDotNet" Version="16.3.0" />
</ItemGroup>
<ItemGroup>
<PackageVersion Include="Autofac" Version="8.2.0" />
<PackageVersion Include="CaseExtensions" Version="1.1.0" />
<PackageVersion Include="Microsoft.CodeAnalysis.CSharp.Workspaces" Version="4.4.0" />
<PackageVersion Include="Namotion.Reflection" Version="3.0.1" />
<PackageVersion Include="Newtonsoft.Json" Version="13.0.3" />
<PackageVersion Include="NJsonSchema" Version="10.9.0" />
<PackageVersion Include="NSwag.Core" Version="13.20.0" />
<PackageVersion Include="Scriban" Version="5.9.1" />
</ItemGroup>
<ItemGroup>
<GlobalPackageReference Include="Microsoft.CodeAnalysis.NetAnalyzers" Version="9.0.0" />
<GlobalPackageReference Include="Microsoft.SourceLink.GitHub" Version="8.0.0" />
<GlobalPackageReference Include="Microsoft.VisualStudio.SlnGen" Version="12.0.3" />
<GlobalPackageReference Include="Nerdbank.GitVersioning" Version="3.7.112" />
<GlobalPackageReference Include="StyleCop.Analyzers" Version="1.1.118" />
</ItemGroup>
<Project>
<PropertyGroup>
<ManagePackageVersionsCentrally>true</ManagePackageVersionsCentrally>
</PropertyGroup>
<ItemGroup>
<PackageVersion Include="BouncyCastle.Cryptography" Version="2.5.1" />
<PackageVersion Include="FluentAssertions" Version="8.2.0" />
<PackageVersion Include="Fractions" Version="7.3.0" />
<PackageVersion Include="JsonPatch.Net" Version="3.3.0" />
<PackageVersion Include="MartinCostello.Logging.XUnit" Version="0.5.1" />
<PackageVersion Include="Microsoft.Bcl.AsyncInterfaces" Version="9.0.4" />
<PackageVersion Include="Microsoft.Extensions.Hosting" Version="9.0.4" />
<PackageVersion Include="Microsoft.Extensions.Logging" Version="9.0.4" />
<PackageVersion Include="Microsoft.NET.Test.Sdk" Version="17.13.0" />
<PackageVersion Include="Microsoft.TestPlatform.ObjectModel" Version="17.13.0" />
<PackageVersion Include="Moq" Version="4.20.72" />
<PackageVersion Include="Nito.AsyncEx" Version="5.1.2" />
<PackageVersion Include="Nito.AsyncEx.Coordination" Version="5.1.2" />
<PackageVersion Include="OpenTelemetry.Exporter.Console" Version="1.11.2" />
<PackageVersion Include="OpenTelemetry.Instrumentation.Http" Version="1.11.1" />
<PackageVersion Include="Portable.BouncyCastle" Version="1.9.0" />
<PackageVersion Include="SharpZipLib" Version="1.4.2" />
<PackageVersion Include="Swashbuckle.AspNetCore" Version="8.1.1" />
<PackageVersion Include="System.Diagnostics.DiagnosticSource" Version="9.0.4" />
<PackageVersion Include="System.IO.Abstractions.TestingHelpers" Version="22.0.14" />
<PackageVersion Include="System.Reactive" Version="6.0.1" />
<PackageVersion Include="System.Text.Json" Version="9.0.4" />
<PackageVersion Include="Vecc.YamlDotNet.Analyzers.StaticGenerator" Version="16.3.0" />
<PackageVersion Include="Wiremock.Net" Version="1.7.4" />
<PackageVersion Include="xunit" Version="2.9.3" />
<PackageVersion Include="xunit.runner.visualstudio" Version="3.0.2" />
<PackageVersion Include="Xunit.StaFact" Version="1.2.69" />
<PackageVersion Include="YamlDotNet" Version="16.3.0" />
</ItemGroup>
<ItemGroup>
<PackageVersion Include="Autofac" Version="8.2.1" />
<PackageVersion Include="CaseExtensions" Version="1.1.0" />
<PackageVersion Include="Microsoft.CodeAnalysis.Common" Version="4.13.0" />
<PackageVersion Include="Namotion.Reflection" Version="3.3.0" />
<PackageVersion Include="Newtonsoft.Json" Version="13.0.3" />
<PackageVersion Include="NJsonSchema" Version="11.2.0" />
<PackageVersion Include="NJsonSchema.Annotations" Version="11.2.0" />
<PackageVersion Include="NSwag.Core" Version="14.3.0" />
<PackageVersion Include="Scriban" Version="6.2.1" />
</ItemGroup>
<ItemGroup>
<GlobalPackageReference Include="Microsoft.CodeAnalysis.NetAnalyzers" Version="9.0.0" />
<GlobalPackageReference Include="Microsoft.SourceLink.GitHub" Version="8.0.0" />
<GlobalPackageReference Include="Microsoft.VisualStudio.SlnGen" Version="12.0.3" />
<GlobalPackageReference Include="Nerdbank.GitVersioning" Version="3.7.112" />
<GlobalPackageReference Include="StyleCop.Analyzers" Version="1.1.118" />
</ItemGroup>
</Project>
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,7 @@ ${GEN_DIR}/openapi/csharp.sh ${REPO_DIR}/src/KubernetesClient ${REPO_DIR}/csharp

| SDK Version | Kubernetes Version | .NET Targeting |
|-------------|--------------------|-----------------------------------------------------|
| 17.0 | 1.33 | net8.0;net9.0;net48*;netstandard2.0* |
| 16.0 | 1.32 | net8.0;net9.0;net48*;netstandard2.0* |
| 15.0 | 1.31 | net6.0;net8.0;net48*;netstandard2.0* |
| 14.0 | 1.30 | net6.0;net8.0;net48*;netstandard2.0* |
Expand Down
2 changes: 1 addition & 1 deletion csharp.settings
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
export KUBERNETES_BRANCH=v1.32.0
export KUBERNETES_BRANCH=v1.33.0
export CLIENT_VERSION=0.0.1
export PACKAGE_NAME=k8s
3 changes: 2 additions & 1 deletion examples/Directory.Build.props
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="..\Directory.Build.props" />
<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<TargetFramework>net9.0</TargetFramework>
</PropertyGroup>
</Project>
1 change: 1 addition & 0 deletions examples/Directory.Build.targets
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="..\Directory.Build.targets" />
<ItemGroup>
<ProjectReference Include="$(MSBuildThisFileDirectory)\..\src\KubernetesClient\KubernetesClient.csproj" Condition="'$(PublishAot)' != 'true'" />
</ItemGroup>
Expand Down
150 changes: 72 additions & 78 deletions examples/cp/Cp.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using ICSharpCode.SharpZipLib.Tar;
using ICSharpCode.SharpZipLib.Tar;
using k8s;
using System;
using System.IO;
Expand All @@ -7,110 +7,104 @@
using System.Threading;
using System.Threading.Tasks;

namespace cp
{
internal class Cp
{
private static IKubernetes client;
namespace cp;

private static async Task Main(string[] args)
{
var config = KubernetesClientConfiguration.BuildConfigFromConfigFile();
client = new Kubernetes(config);
internal class Cp
{
private static IKubernetes client;

private static async Task Main(string[] args)
{
var config = KubernetesClientConfiguration.BuildConfigFromConfigFile();
client = new Kubernetes(config);

var pods = client.CoreV1.ListNamespacedPod("default", null, null, null, $"job-name=upload-demo");
var pod = pods.Items.First();

await CopyFileToPodAsync(pod.Metadata.Name, "default", "upload-demo", args[0], $"home/{args[1]}");
var pods = client.CoreV1.ListNamespacedPod("default", null, null, null, $"job-name=upload-demo");
var pod = pods.Items.First();

}
await CopyFileToPodAsync(pod.Metadata.Name, "default", "upload-demo", args[0], $"home/{args[1]}").ConfigureAwait(false);
}




private static void ValidatePathParameters(string sourcePath, string destinationPath)
private static void ValidatePathParameters(string sourcePath, string destinationPath)
{
if (string.IsNullOrWhiteSpace(sourcePath))
{
if (string.IsNullOrWhiteSpace(sourcePath))
{
throw new ArgumentException($"{nameof(sourcePath)} cannot be null or whitespace");
}

if (string.IsNullOrWhiteSpace(destinationPath))
{
throw new ArgumentException($"{nameof(destinationPath)} cannot be null or whitespace");
}

throw new ArgumentException($"{nameof(sourcePath)} cannot be null or whitespace");
}

public static async Task<int> CopyFileToPodAsync(string name, string @namespace, string container, string sourceFilePath, string destinationFilePath, CancellationToken cancellationToken = default(CancellationToken))
if (string.IsNullOrWhiteSpace(destinationPath))
{
// All other parameters are being validated by MuxedStreamNamespacedPodExecAsync called by NamespacedPodExecAsync
ValidatePathParameters(sourceFilePath, destinationFilePath);
throw new ArgumentException($"{nameof(destinationPath)} cannot be null or whitespace");
}
}

public static async Task<int> CopyFileToPodAsync(string name, string @namespace, string container, string sourceFilePath, string destinationFilePath, CancellationToken cancellationToken = default(CancellationToken))
{
// All other parameters are being validated by MuxedStreamNamespacedPodExecAsync called by NamespacedPodExecAsync
ValidatePathParameters(sourceFilePath, destinationFilePath);

// The callback which processes the standard input, standard output and standard error of exec method
var handler = new ExecAsyncCallback(async (stdIn, stdOut, stdError) =>
// The callback which processes the standard input, standard output and standard error of exec method
var handler = new ExecAsyncCallback(async (stdIn, stdOut, stdError) =>
{
var fileInfo = new FileInfo(destinationFilePath);
try
{
var fileInfo = new FileInfo(destinationFilePath);
try
using (var memoryStream = new MemoryStream())
{
using (var memoryStream = new MemoryStream())
using (var inputFileStream = File.OpenRead(sourceFilePath))
using (var tarOutputStream = new TarOutputStream(memoryStream, Encoding.Default))
{
using (var inputFileStream = File.OpenRead(sourceFilePath))
using (var tarOutputStream = new TarOutputStream(memoryStream, Encoding.Default))
{
tarOutputStream.IsStreamOwner = false;

var fileSize = inputFileStream.Length;
var entry = TarEntry.CreateTarEntry(fileInfo.Name);

entry.Size = fileSize;
tarOutputStream.IsStreamOwner = false;

tarOutputStream.PutNextEntry(entry);
await inputFileStream.CopyToAsync(tarOutputStream);
tarOutputStream.CloseEntry();
}
var fileSize = inputFileStream.Length;
var entry = TarEntry.CreateTarEntry(fileInfo.Name);

memoryStream.Position = 0;
entry.Size = fileSize;

await memoryStream.CopyToAsync(stdIn);
await stdIn.FlushAsync();
tarOutputStream.PutNextEntry(entry);
await inputFileStream.CopyToAsync(tarOutputStream).ConfigureAwait(false);
tarOutputStream.CloseEntry();
}

}
catch (Exception ex)
{
throw new IOException($"Copy command failed: {ex.Message}");
}
memoryStream.Position = 0;

using StreamReader streamReader = new StreamReader(stdError);
while (streamReader.EndOfStream == false)
{
string error = await streamReader.ReadToEndAsync();
throw new IOException($"Copy command failed: {error}");
await memoryStream.CopyToAsync(stdIn).ConfigureAwait(false);
await stdIn.FlushAsync().ConfigureAwait(false);
}
});

string destinationFolder = GetFolderName(destinationFilePath);

return await client.NamespacedPodExecAsync(
name,
@namespace,
container,
new string[] { "sh", "-c", $"tar xmf - -C {destinationFolder}" },
false,
handler,
cancellationToken);
}

}
catch (Exception ex)
{
throw new IOException($"Copy command failed: {ex.Message}");
}

private static string GetFolderName(string filePath)
{
var folderName = Path.GetDirectoryName(filePath);
using StreamReader streamReader = new StreamReader(stdError);
while (streamReader.EndOfStream == false)
{
string error = await streamReader.ReadToEndAsync().ConfigureAwait(false);
throw new IOException($"Copy command failed: {error}");
}
});

string destinationFolder = GetFolderName(destinationFilePath);

return await client.NamespacedPodExecAsync(
name,
@namespace,
container,
new string[] { "sh", "-c", $"tar xmf - -C {destinationFolder}" },
false,
handler,
cancellationToken).ConfigureAwait(false);
}

return string.IsNullOrEmpty(folderName) ? "." : folderName;
}

private static string GetFolderName(string filePath)
{
var folderName = Path.GetDirectoryName(filePath);

return string.IsNullOrEmpty(folderName) ? "." : folderName;
}
}
18 changes: 9 additions & 9 deletions examples/csrApproval/Program.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using Json.Patch;
using Json.Patch;
using k8s;
using k8s.Models;
using System.Net;
Expand Down Expand Up @@ -44,34 +44,34 @@ string GenerateCertificate(string name)
Kind = "CertificateSigningRequest",
Metadata = new V1ObjectMeta
{
Name = name
Name = name,
},
Spec = new V1CertificateSigningRequestSpec
{
Request = encodedCsr,
SignerName = "kubernetes.io/kube-apiserver-client",
Usages = new List<string> { "client auth" },
ExpirationSeconds = 600 // minimum should be 10 minutes
}
ExpirationSeconds = 600, // minimum should be 10 minutes
},
};

await client.CertificatesV1.CreateCertificateSigningRequestAsync(request);
await client.CertificatesV1.CreateCertificateSigningRequestAsync(request).ConfigureAwait(false);

var serializeOptions = new JsonSerializerOptions
{
PropertyNamingPolicy = JsonNamingPolicy.CamelCase,
WriteIndented = true
WriteIndented = true,
};
var readCert = await client.CertificatesV1.ReadCertificateSigningRequestAsync(name);
var readCert = await client.CertificatesV1.ReadCertificateSigningRequestAsync(name).ConfigureAwait(false);
var old = JsonSerializer.SerializeToDocument(readCert, serializeOptions);

var replace = new List<V1CertificateSigningRequestCondition>
{
new("True", "Approved", DateTime.UtcNow, DateTime.UtcNow, "This certificate was approved by k8s client", "Approve")
new("True", "Approved", DateTime.UtcNow, DateTime.UtcNow, "This certificate was approved by k8s client", "Approve"),
};
readCert.Status.Conditions = replace;

var expected = JsonSerializer.SerializeToDocument(readCert, serializeOptions);

var patch = old.CreatePatch(expected);
await client.CertificatesV1.PatchCertificateSigningRequestApprovalAsync(new V1Patch(patch, V1Patch.PatchType.JsonPatch), name);
await client.CertificatesV1.PatchCertificateSigningRequestApprovalAsync(new V1Patch(patch, V1Patch.PatchType.JsonPatch), name).ConfigureAwait(false);
1 change: 1 addition & 0 deletions examples/openTelemetryConsole/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
{
Console.WriteLine(item.Metadata.Name);
}

// Or empty if there are no pods
if (list.Items.Count == 0)
{
Expand Down
1 change: 1 addition & 0 deletions examples/patch-aot/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,6 @@ static void PrintLabels(V1Pod pod)
{
Console.WriteLine($"{k} : {v}");
}

Console.WriteLine("=-=-=-=-=-=-=-=-=-=-=");
}
Loading
Loading