add watch example

This commit is contained in:
Boshi Lian
2017-11-16 01:51:33 +08:00
parent abc89a1839
commit 4a208f3b1c
2 changed files with 45 additions and 0 deletions

33
examples/watch/Program.cs Normal file
View File

@@ -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<Corev1Pod>((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();
}
}
}
}

View File

@@ -0,0 +1,12 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp2.0</TargetFramework>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\..\src\KubernetesClient.csproj" />
</ItemGroup>
</Project>