From 4a208f3b1ca394d0208b956c347628208ba9ccaa Mon Sep 17 00:00:00 2001 From: Boshi Lian Date: Thu, 16 Nov 2017 01:51:33 +0800 Subject: [PATCH] add watch example --- examples/watch/Program.cs | 33 +++++++++++++++++++++++++++++++++ examples/watch/watch.csproj | 12 ++++++++++++ 2 files changed, 45 insertions(+) create mode 100644 examples/watch/Program.cs create mode 100644 examples/watch/watch.csproj diff --git a/examples/watch/Program.cs b/examples/watch/Program.cs new file mode 100644 index 0000000..1868472 --- /dev/null +++ b/examples/watch/Program.cs @@ -0,0 +1,33 @@ +using System; +using System.Threading; +using k8s; +using k8s.Models; + +namespace watch +{ + internal class Program + { + private static void Main(string[] args) + { + var config = KubernetesClientConfiguration.BuildConfigFromConfigFile(); + + IKubernetes client = new Kubernetes(config); + + var podlistResp = client.ListNamespacedPodWithHttpMessagesAsync("default", watch: true).Result; + using (podlistResp.Watch((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(); + } + } + } +} diff --git a/examples/watch/watch.csproj b/examples/watch/watch.csproj new file mode 100644 index 0000000..698630e --- /dev/null +++ b/examples/watch/watch.csproj @@ -0,0 +1,12 @@ + + + + Exe + netcoreapp2.0 + + + + + + +