Skip to content

Commit 6979dd5

Browse files
committed
refactor: simplify watch event handling in Kubernetes client example
1 parent 80b46b7 commit 6979dd5

File tree

2 files changed

+3
-15
lines changed

2 files changed

+3
-15
lines changed

examples/clientset/Program.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
// See https://aka.ms/new-console-template for more information
2-
using k8s;
1+
using k8s;
32
using k8s.ClientSets;
43
using System.Threading.Tasks;
54

examples/watch/Program.cs

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -22,24 +22,13 @@
2222
void WatchUsingCallback(IKubernetes client)
2323
#pragma warning restore CS8321 // Remove unused private members
2424
{
25-
using var podlistResp = client.CoreV1.WatchListNamespacedPod("default");
26-
podlistResp.OnEvent += (type, item) =>
25+
using var podlistResp = client.CoreV1.WatchListNamespacedPod("default", onEvent: (type, item) =>
2726
{
2827
Console.WriteLine("==on watch event==");
2928
Console.WriteLine(type);
3029
Console.WriteLine(item.Metadata.Name);
3130
Console.WriteLine("==on watch event==");
32-
};
33-
podlistResp.OnError += (error) =>
34-
{
35-
Console.WriteLine("==on watch error==");
36-
Console.WriteLine(error.Message);
37-
Console.WriteLine("==on watch error==");
38-
};
39-
podlistResp.OnClosed += () =>
40-
{
41-
Console.WriteLine("==on watch closed==");
42-
};
31+
});
4332
{
4433
Console.WriteLine("press ctrl + c to stop watching");
4534

0 commit comments

Comments
 (0)