forked from kubernetes-client/csharp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathProgram.cs
42 lines (35 loc) · 1.27 KB
/
Program.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
using System;
using System.Collections.Generic;
using System.Linq;
using k8s;
using k8s.Models;
using Microsoft.AspNetCore.JsonPatch;
namespace patch
{
internal class Program
{
private static void Main(string[] args)
{
var config = KubernetesClientConfiguration.BuildConfigFromConfigFile();
IKubernetes client = new Kubernetes(config);
Console.WriteLine("Starting Request!");
var pod = client.ListNamespacedPod("default").Items.First();
var name = pod.Metadata.Name;
PrintLabels(pod);
var newlabels = new Dictionary<string, string>(pod.Metadata.Labels) { ["test"] = "test" };
var patch = new JsonPatchDocument<V1Pod>();
patch.Replace(e => e.Metadata.Labels, newlabels);
client.PatchNamespacedPod(new V1Patch(patch), name, "default");
PrintLabels(client.ReadNamespacedPod(name, "default"));
}
private static void PrintLabels(V1Pod pod)
{
Console.WriteLine($"Lables: for {pod.Metadata.Name}");
foreach (var (k, v) in pod.Metadata.Labels)
{
Console.WriteLine($"{k} : {v}");
}
Console.WriteLine("=-=-=-=-=-=-=-=-=-=-=");
}
}
}