|
1 | 1 | using k8s;
|
2 |
| -using k8s.Models; |
3 | 2 | using System;
|
4 | 3 | using System.Threading;
|
5 | 4 | using System.Threading.Tasks;
|
|
8 | 7 |
|
9 | 8 | IKubernetes client = new Kubernetes(config);
|
10 | 9 |
|
11 |
| -var podlistResp = client.CoreV1.ListNamespacedPodWithHttpMessagesAsync("default", watch: true); |
| 10 | +var podlistResp = client.CoreV1.WatchListNamespacedPodAsync("default"); |
| 11 | + |
12 | 12 | // C# 8 required https://docs.microsoft.com/en-us/archive/msdn-magazine/2019/november/csharp-iterating-with-async-enumerables-in-csharp-8
|
13 |
| -await foreach (var (type, item) in podlistResp.WatchAsync<V1Pod, V1PodList>().ConfigureAwait(false)) |
| 13 | +await foreach (var (type, item) in podlistResp.ConfigureAwait(false)) |
14 | 14 | {
|
15 | 15 | Console.WriteLine("==on watch event==");
|
16 | 16 | Console.WriteLine(type);
|
|
22 | 22 | void WatchUsingCallback(IKubernetes client)
|
23 | 23 | #pragma warning restore CS8321 // Remove unused private members
|
24 | 24 | {
|
25 |
| - var podlistResp = client.CoreV1.ListNamespacedPodWithHttpMessagesAsync("default", watch: true); |
26 |
| - using (podlistResp.Watch<V1Pod, V1PodList>((type, item) => |
| 25 | + using var podlistResp = client.CoreV1.WatchListNamespacedPod("default"); |
| 26 | + podlistResp.OnEvent += (type, item) => |
27 | 27 | {
|
28 | 28 | Console.WriteLine("==on watch event==");
|
29 | 29 | Console.WriteLine(type);
|
30 | 30 | Console.WriteLine(item.Metadata.Name);
|
31 | 31 | Console.WriteLine("==on watch event==");
|
32 |
| - })) |
| 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 | + }; |
33 | 43 | {
|
34 | 44 | Console.WriteLine("press ctrl + c to stop watching");
|
35 | 45 |
|
|
0 commit comments