-
Notifications
You must be signed in to change notification settings - Fork 106
/
Copy pathServiceAccountMirror.cs
56 lines (47 loc) · 1.89 KB
/
ServiceAccountMirror.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
using ES.Kubernetes.Reflector.Core.Mirroring;
using ES.Kubernetes.Reflector.Core.Resources;
using k8s;
using k8s.Models;
using Microsoft.AspNetCore.JsonPatch;
namespace ES.Kubernetes.Reflector.Core;
public class ServiceAccountMirror : ResourceMirror<V1ServiceAccount>
{
public ServiceAccountMirror(ILogger<ServiceAccountMirror> logger, IKubernetes client) : base(logger, client)
{
}
protected override async Task<V1ServiceAccount[]> OnResourceWithNameList(string itemRefName)
{
return (await Client.CoreV1.ListServiceAccountForAllNamespacesAsync(fieldSelector: $"metadata.name={itemRefName}")).Items
.ToArray();
}
protected override Task OnResourceApplyPatch(V1Patch patch, KubeRef refId)
{
return Client.CoreV1.PatchNamespacedServiceAccountWithHttpMessagesAsync(patch, refId.Name, refId.Namespace);
}
protected override Task OnResourceConfigurePatch(V1ServiceAccount source, JsonPatchDocument<V1ServiceAccount> patchDoc)
{
// Just update annotations.
return Task.CompletedTask;
}
protected override Task OnResourceCreate(V1ServiceAccount item, string ns)
{
item.Metadata.ResourceVersion = null;
return Client.CoreV1.CreateNamespacedServiceAccountAsync(item, ns);
}
protected override Task<V1ServiceAccount> OnResourceClone(V1ServiceAccount sourceResource)
{
return Task.FromResult(new V1ServiceAccount
{
ApiVersion = sourceResource.ApiVersion,
Kind = sourceResource.Kind
});
}
protected override Task OnResourceDelete(KubeRef resourceId)
{
return Client.CoreV1.DeleteNamespacedServiceAccountAsync(resourceId.Name, resourceId.Namespace);
}
protected override Task<V1ServiceAccount> OnResourceGet(KubeRef refId)
{
return Client.CoreV1.ReadNamespacedServiceAccountAsync(refId.Name, refId.Namespace);
}
}