-
Notifications
You must be signed in to change notification settings - Fork 123
Expand file tree
/
Copy pathConfigMapMirror.cs
More file actions
71 lines (62 loc) · 2.71 KB
/
Copy pathConfigMapMirror.cs
File metadata and controls
71 lines (62 loc) · 2.71 KB
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
69
70
71
using ES.FX.Additions.KubernetesClient.Models;
using ES.Kubernetes.Reflector.Mirroring.Core;
using k8s;
using k8s.Models;
using Microsoft.AspNetCore.JsonPatch;
namespace ES.Kubernetes.Reflector.Mirroring;
public class ConfigMapMirror(ILogger<ConfigMapMirror> logger, IKubernetes kubernetes)
: ResourceMirror<V1ConfigMap>(logger, kubernetes)
{
protected override async Task DiscoverAutoMirrorSourcesFromClusterAsync(
CancellationToken cancellationToken)
{
string? continueParameter = null;
do
{
var list = await Kubernetes.CoreV1.ListConfigMapForAllNamespacesAsync(
continueParameter: continueParameter,
cancellationToken: cancellationToken);
foreach (var cm in list.Items)
RefreshRememberedAutoMirrorFromResource(cm);
continueParameter = list.Metadata?.ContinueProperty;
} while (!string.IsNullOrEmpty(continueParameter));
}
protected override async Task<V1ConfigMap[]> OnResourceWithNameList(string itemRefName,
CancellationToken cancellationToken) =>
[
.. (await Kubernetes.CoreV1.ListConfigMapForAllNamespacesAsync(
fieldSelector: $"metadata.name={itemRefName}",
cancellationToken: cancellationToken))
.Items
];
protected override async Task OnResourceApplyPatch(V1Patch patch, NamespacedName refId)
{
await Kubernetes.CoreV1.PatchNamespacedConfigMapAsync(patch, refId.Name, refId.Namespace);
}
protected override Task OnResourceConfigurePatch(V1ConfigMap source, JsonPatchDocument<V1ConfigMap> patchDoc)
{
patchDoc.Replace(e => e.Data, source.Data);
patchDoc.Replace(e => e.BinaryData, source.BinaryData);
return Task.CompletedTask;
}
protected override async Task OnResourceCreate(V1ConfigMap item, string ns)
{
await Kubernetes.CoreV1.CreateNamespacedConfigMapAsync(item, ns);
}
protected override Task<V1ConfigMap> OnResourceClone(V1ConfigMap sourceResource) =>
Task.FromResult(new V1ConfigMap
{
ApiVersion = sourceResource.ApiVersion,
Kind = sourceResource.Kind,
Data = sourceResource.Data,
BinaryData = sourceResource.BinaryData
});
protected override async Task OnResourceDelete(NamespacedName resourceId)
{
await Kubernetes.CoreV1.DeleteNamespacedConfigMapAsync(resourceId.Name, resourceId.Namespace);
}
protected override async Task<V1ConfigMap> OnResourceGet(NamespacedName refId,
CancellationToken cancellationToken) =>
await Kubernetes.CoreV1.ReadNamespacedConfigMapAsync(refId.Name, refId.Namespace,
cancellationToken: cancellationToken);
}