* generated based on 1.33 * Update version to 17.0 in version.json * Remove extra API endpoint from swagger.json * Remove ModelConverter and related AutoMapper components * Update package versions * Refactor code to use ConfigureAwait(false) for asynchronous calls and update target framework to net9.0 * Remove ConfigureAwait(false) from OidcAuthTests for consistency in async calls * Update SDK version in README to reflect support for net8.0 and net9.0 * Update dotnet SDK version to 9.0.x in build workflow * Revert Fractions package version to 7.3.0 in Directory.Packages.props * Update target framework to netstandard2.1 for improved compatibility * Update package references for Microsoft.CodeAnalysis in Directory.Packages.props and LibKubernetesGenerator.target * Refactor Worker class constructor documentation and standardize Dictionary type declaration in Program.cs
53 lines
1.9 KiB
C#
53 lines
1.9 KiB
C#
using k8s;
|
|
using k8s.Models;
|
|
using System;
|
|
using System.Threading;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace watch
|
|
{
|
|
internal class Program
|
|
{
|
|
private static async Task Main(string[] args)
|
|
{
|
|
var config = KubernetesClientConfiguration.BuildConfigFromConfigFile();
|
|
|
|
IKubernetes client = new Kubernetes(config);
|
|
|
|
var podlistResp = client.CoreV1.ListNamespacedPodWithHttpMessagesAsync("default", watch: true);
|
|
// C# 8 required https://docs.microsoft.com/en-us/archive/msdn-magazine/2019/november/csharp-iterating-with-async-enumerables-in-csharp-8
|
|
await foreach (var (type, item) in podlistResp.WatchAsync<V1Pod, V1PodList>().ConfigureAwait(false))
|
|
{
|
|
Console.WriteLine("==on watch event==");
|
|
Console.WriteLine(type);
|
|
Console.WriteLine(item.Metadata.Name);
|
|
Console.WriteLine("==on watch event==");
|
|
}
|
|
|
|
// uncomment if you prefer callback api
|
|
// WatchUsingCallback(client);
|
|
}
|
|
|
|
#pragma warning disable IDE0051 // Remove unused private members
|
|
private static void WatchUsingCallback(IKubernetes client)
|
|
#pragma warning restore IDE0051 // Remove unused private members
|
|
{
|
|
var podlistResp = client.CoreV1.ListNamespacedPodWithHttpMessagesAsync("default", watch: true);
|
|
using (podlistResp.Watch<V1Pod, V1PodList>((type, item) =>
|
|
{
|
|
Console.WriteLine("==on watch event==");
|
|
Console.WriteLine(type);
|
|
Console.WriteLine(item.Metadata.Name);
|
|
Console.WriteLine("==on watch event==");
|
|
}))
|
|
{
|
|
Console.WriteLine("press ctrl + c to stop watching");
|
|
|
|
var ctrlc = new ManualResetEventSlim(false);
|
|
Console.CancelKeyPress += (sender, eventArgs) => ctrlc.Set();
|
|
ctrlc.Wait();
|
|
}
|
|
}
|
|
}
|
|
}
|