Files
csharp/examples/clientset/Program.cs
Qing Long 6d27bd900b feat: enhance Kubernetes client with watch functionality (#1667)
* feat: enhance Kubernetes client with watch functionality

* refactor: simplify watch event handling in Kubernetes client example

* refactor: update Kubernetes watch functionality to use new event handling methods and add async enumerable support

* fix

* fix

* fix: correct usage of Pod list items in client example and update Obsolete attribute formatting

* fix: update client example to use correct Pod list method and improve Obsolete attribute formatting

* refactor: enhance type resolution for list items in TypeHelper by adding TryGetItemTypeFromSchema method

* feat: mark Watch methods as obsolete to prepare for future deprecation

* fix

* refactor: update WatcherExt class to internal and remove obsolete attributes; improve example method signature in Program.cs

* refactor: change WatcherExt class from internal to public and mark methods as obsolete for future deprecation
2025-10-11 15:10:53 -07:00

32 lines
1.0 KiB
C#
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

using k8s;
using k8s.Models;
using k8s.ClientSets;
using System.Threading.Tasks;
namespace clientset
{
internal class Program
{
private static async Task Main(string[] args)
{
var config = KubernetesClientConfiguration.BuildConfigFromConfigFile();
var client = new Kubernetes(config);
var clientSet = new ClientSet(client);
var list = await clientSet.CoreV1.Pod.ListAsync("default").ConfigureAwait(false);
foreach (var item in list)
{
System.Console.WriteLine(item.Metadata.Name);
}
var pod = await clientSet.CoreV1.Pod.GetAsync("test", "default").ConfigureAwait(false);
System.Console.WriteLine(pod?.Metadata?.Name);
var watch = clientSet.CoreV1.Pod.WatchListAsync("default");
await foreach (var (_, item) in watch.ConfigureAwait(false))
{
System.Console.WriteLine(item.Metadata.Name);
}
}
}
}