-
Notifications
You must be signed in to change notification settings - Fork 106
/
Copy pathRoleMirror.cs
60 lines (50 loc) · 1.91 KB
/
RoleMirror.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
using ES.Kubernetes.Reflector.Core.Mirroring;
using ES.Kubernetes.Reflector.Core.Resources;
using k8s;
using k8s.Models;
using Microsoft.AspNetCore.JsonPatch;
using System.Text.Json;
namespace ES.Kubernetes.Reflector.Core;
public class RoleMirror : ResourceMirror<V1Role>
{
public RoleMirror(ILogger<RoleMirror> logger, IKubernetes client) : base(logger, client)
{
}
protected override async Task<V1Role[]> OnResourceWithNameList(string itemRefName)
{
return (await Client.RbacAuthorizationV1.ListRoleForAllNamespacesAsync(fieldSelector: $"metadata.name={itemRefName}")).Items
.ToArray();
}
protected override Task OnResourceApplyPatch(V1Patch patch, KubeRef refId)
{
return Client.RbacAuthorizationV1.PatchNamespacedRoleWithHttpMessagesAsync(patch, refId.Name, refId.Namespace);
}
protected override Task OnResourceConfigurePatch(V1Role source, JsonPatchDocument<V1Role> patchDoc)
{
// Replace with new List of Rules
patchDoc.Replace(e => e.Rules, source.Rules);
return Task.CompletedTask;
}
protected override Task OnResourceCreate(V1Role item, string ns)
{
item.Metadata.ResourceVersion = null;
return Client.RbacAuthorizationV1.CreateNamespacedRoleAsync(item, ns);
}
protected override Task<V1Role> OnResourceClone(V1Role sourceResource)
{
return Task.FromResult(new V1Role
{
ApiVersion = sourceResource.ApiVersion,
Kind = sourceResource.Kind,
Rules = sourceResource.Rules
});
}
protected override Task OnResourceDelete(KubeRef resourceId)
{
return Client.RbacAuthorizationV1.DeleteNamespacedRoleAsync(resourceId.Name, resourceId.Namespace);
}
protected override Task<V1Role> OnResourceGet(KubeRef refId)
{
return Client.RbacAuthorizationV1.ReadNamespacedRoleAsync(refId.Name, refId.Namespace);
}
}