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
This commit is contained in:
@@ -1,7 +1,6 @@
|
||||
// See https://aka.ms/new-console-template for more information
|
||||
using k8s;
|
||||
using k8s.ClientSets;
|
||||
using k8s;
|
||||
using k8s.Models;
|
||||
using k8s.ClientSets;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace clientset
|
||||
@@ -13,7 +12,7 @@ namespace clientset
|
||||
var config = KubernetesClientConfiguration.BuildConfigFromConfigFile();
|
||||
var client = new Kubernetes(config);
|
||||
|
||||
ClientSet clientSet = new ClientSet(client);
|
||||
var clientSet = new ClientSet(client);
|
||||
var list = await clientSet.CoreV1.Pod.ListAsync("default").ConfigureAwait(false);
|
||||
foreach (var item in list)
|
||||
{
|
||||
@@ -22,6 +21,12 @@ namespace clientset
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user