-
Notifications
You must be signed in to change notification settings - Fork 301
/
Copy pathProgram.cs
68 lines (54 loc) · 3 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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
using Json.Patch;
using k8s;
using k8s.Models;
using System.Text.Json;
async Task RestartDaemonSetAsync(string name, string @namespace, IKubernetes client)
{
var daemonSet = await client.AppsV1.ReadNamespacedDaemonSetAsync(name, @namespace).ConfigureAwait(false);
var options = new JsonSerializerOptions { PropertyNamingPolicy = JsonNamingPolicy.CamelCase, WriteIndented = true };
var old = JsonSerializer.SerializeToDocument(daemonSet, options);
var now = DateTimeOffset.Now.ToUnixTimeSeconds();
var restart = new Dictionary<string, string>
{
["date"] = now.ToString(),
};
daemonSet.Spec.Template.Metadata.Annotations = restart;
var expected = JsonSerializer.SerializeToDocument(daemonSet);
var patch = old.CreatePatch(expected);
await client.AppsV1.PatchNamespacedDaemonSetAsync(new V1Patch(patch, V1Patch.PatchType.JsonPatch), name, @namespace).ConfigureAwait(false);
}
async Task RestartDeploymentAsync(string name, string @namespace, IKubernetes client)
{
var deployment = await client.AppsV1.ReadNamespacedDeploymentAsync(name, @namespace).ConfigureAwait(false);
var options = new JsonSerializerOptions { PropertyNamingPolicy = JsonNamingPolicy.CamelCase, WriteIndented = true };
var old = JsonSerializer.SerializeToDocument(deployment, options);
var now = DateTimeOffset.Now.ToUnixTimeSeconds();
var restart = new Dictionary<string, string>
{
["date"] = now.ToString(),
};
deployment.Spec.Template.Metadata.Annotations = restart;
var expected = JsonSerializer.SerializeToDocument(deployment);
var patch = old.CreatePatch(expected);
await client.AppsV1.PatchNamespacedDeploymentAsync(new V1Patch(patch, V1Patch.PatchType.JsonPatch), name, @namespace).ConfigureAwait(false);
}
async Task RestartStatefulSetAsync(string name, string @namespace, IKubernetes client)
{
var deployment = await client.AppsV1.ReadNamespacedStatefulSetAsync(name, @namespace).ConfigureAwait(false);
var options = new JsonSerializerOptions { PropertyNamingPolicy = JsonNamingPolicy.CamelCase, WriteIndented = true };
var old = JsonSerializer.SerializeToDocument(deployment, options);
var now = DateTimeOffset.Now.ToUnixTimeSeconds();
var restart = new Dictionary<string, string>
{
["date"] = now.ToString(),
};
deployment.Spec.Template.Metadata.Annotations = restart;
var expected = JsonSerializer.SerializeToDocument(deployment);
var patch = old.CreatePatch(expected);
await client.AppsV1.PatchNamespacedStatefulSetAsync(new V1Patch(patch, V1Patch.PatchType.JsonPatch), name, @namespace).ConfigureAwait(false);
}
var config = KubernetesClientConfiguration.BuildConfigFromConfigFile();
IKubernetes client = new Kubernetes(config);
await RestartDeploymentAsync("event-exporter", "monitoring", client).ConfigureAwait(false);
await RestartDaemonSetAsync("prometheus-exporter", "monitoring", client).ConfigureAwait(false);
await RestartStatefulSetAsync("argocd-application-controlle", "argocd", client).ConfigureAwait(false);