Skip to content

Commit a871894

Browse files
authored
Merge pull request #2043 from FabianKramm/main
feat: importer, translate patches & generic sync
2 parents b808bf9 + 4d726aa commit a871894

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

73 files changed

+1115
-259
lines changed

chart/templates/_rbac.tpl

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@
3434
(eq (toString .Values.sync.fromHost.csiDrivers.enabled) "true")
3535
(eq (toString .Values.sync.fromHost.csiStorageCapacities.enabled) "true")
3636
.Values.sync.fromHost.nodes.enabled
37+
.Values.sync.toHost.customResourceDefinitions
38+
.Values.sync.fromHost.customResourceDefinitions
3739
.Values.integrations.kubeVirt.enabled
3840
(and .Values.integrations.metricsServer.enabled .Values.integrations.metricsServer.nodes)
3941
.Values.experimental.multiNamespaceMode.enabled -}}
@@ -122,6 +124,36 @@
122124
{{- end }}
123125
{{- end -}}
124126

127+
{{/*
128+
Role rules defined in generic syncer
129+
*/}}
130+
{{- define "vcluster.customResourceDefinitions.roleExtraRules" -}}
131+
{{- if .Values.sync.toHost.customResourceDefinitions }}
132+
{{- range $crdName, $rule := .Values.sync.toHost.customResourceDefinitions }}
133+
{{- if $rule.enabled }}
134+
- resources: [ "{{ (splitn "." 2 $crdName)._0 }}" ]
135+
apiGroups: [ "{{ (splitn "." 2 $crdName)._1 }}" ]
136+
verbs: ["create", "delete", "patch", "update", "get", "list", "watch"]
137+
{{- end }}
138+
{{- end }}
139+
{{- end }}
140+
{{- end -}}
141+
142+
{{/*
143+
Cluster role rules defined in generic syncer
144+
*/}}
145+
{{- define "vcluster.customResourceDefinitions.clusterRoleExtraRules" -}}
146+
{{- if .Values.sync.fromHost.customResourceDefinitions }}
147+
{{- range $crdName, $rule := .Values.sync.fromHost.customResourceDefinitions }}
148+
{{- if $rule.enabled }}
149+
- resources: [ "{{ (splitn "." 2 $crdName)._0 }}" ]
150+
apiGroups: [ "{{ (splitn "." 2 $crdName)._1 }}" ]
151+
verbs: ["get", "list", "watch"]
152+
{{- end }}
153+
{{- end }}
154+
{{- end }}
155+
{{- end -}}
156+
125157
{{/*
126158
Cluster role rules defined in generic syncer
127159
*/}}

chart/templates/clusterrole.yaml

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -112,16 +112,17 @@ rules:
112112
resources: ["nodes"]
113113
verbs: ["get", "list"]
114114
{{- end }}
115-
{{- if .Values.integrations.kubeVirt.enabled }}
116-
- apiGroups: ["apiextensions.k8s.io"]
117-
resources: ["customresourcedefinitions"]
118-
verbs: ["get", "list", "watch"]
119-
{{- end }}
120115
{{- if and .Values.integrations.kubeVirt.enabled .Values.integrations.kubeVirt.webhook.enabled }}
121116
- apiGroups: ["admissionregistration.k8s.io"]
122117
resources: ["validatingwebhookconfigurations", "mutatingwebhookconfigurations"]
123118
verbs: ["get", "list", "watch"]
124119
{{- end }}
120+
{{- if or .Values.integrations.kubeVirt.enabled .Values.sync.toHost.customResourceDefinitions .Values.sync.fromHost.customResourceDefinitions }}
121+
- apiGroups: ["apiextensions.k8s.io"]
122+
resources: ["customresourcedefinitions"]
123+
verbs: ["get", "list", "watch"]
124+
{{- end }}
125+
{{- include "vcluster.customResourceDefinitions.clusterRoleExtraRules" . | indent 2 }}
125126
{{- include "vcluster.plugin.clusterRoleExtraRules" . | indent 2 }}
126127
{{- include "vcluster.generic.clusterRoleExtraRules" . | indent 2 }}
127128
{{- include "vcluster.rbac.clusterRoleExtraRules" . | indent 2 }}

chart/templates/role.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ rules:
9494
resources: ["virtualmachines", "virtualmachines/status", "virtualmachineinstances", "virtualmachineinstances/status", "virtualmachineinstancemigrations", "virtualmachineinstancemigrations/status"]
9595
verbs: ["create", "delete", "patch", "update", "get", "list", "watch"]
9696
{{- end }}
97+
{{- include "vcluster.customResourceDefinitions.roleExtraRules" . | indent 2 }}
9798
{{- include "vcluster.plugin.roleExtraRules" . | indent 2 }}
9899
{{- include "vcluster.generic.roleExtraRules" . | indent 2 }}
99100
{{- include "vcluster.rbac.roleExtraRules" . | indent 2 }}

chart/tests/clusterrole_test.yaml

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -323,3 +323,55 @@ tests:
323323
apiGroups: ["admissionregistration.k8s.io"]
324324
resources: ["validatingwebhookconfigurations", "mutatingwebhookconfigurations"]
325325
verbs: ["get", "list", "watch"]
326+
327+
- it: crd sync to host
328+
set:
329+
sync:
330+
toHost:
331+
customResourceDefinitions:
332+
test.test-group:
333+
enabled: true
334+
release:
335+
name: my-release
336+
namespace: my-namespace
337+
asserts:
338+
- hasDocuments:
339+
count: 1
340+
- lengthEqual:
341+
path: rules
342+
count: 1
343+
- contains:
344+
path: rules
345+
content:
346+
apiGroups: [ "apiextensions.k8s.io" ]
347+
resources: [ "customresourcedefinitions" ]
348+
verbs: [ "get", "list", "watch" ]
349+
350+
- it: crd sync from host
351+
set:
352+
sync:
353+
fromHost:
354+
customResourceDefinitions:
355+
test.test-group:
356+
enabled: true
357+
release:
358+
name: my-release
359+
namespace: my-namespace
360+
asserts:
361+
- hasDocuments:
362+
count: 1
363+
- lengthEqual:
364+
path: rules
365+
count: 2
366+
- contains:
367+
path: rules
368+
content:
369+
apiGroups: [ "test-group" ]
370+
resources: [ "test" ]
371+
verbs: [ "get", "list", "watch" ]
372+
- contains:
373+
path: rules
374+
content:
375+
apiGroups: [ "apiextensions.k8s.io" ]
376+
resources: [ "customresourcedefinitions" ]
377+
verbs: [ "get", "list", "watch" ]

chart/tests/role_test.yaml

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,3 +213,74 @@ tests:
213213
apiGroups: [ "pool.kubevirt.io" ]
214214
resources: [ "virtualmachinepools", "virtualmachinepools/status" ]
215215
verbs: [ "create", "delete", "patch", "update", "get", "list", "watch" ]
216+
217+
- it: crd sync
218+
set:
219+
sync:
220+
toHost:
221+
customResourceDefinitions:
222+
test.my-group:
223+
enabled: false
224+
test.my-group-2:
225+
enabled: true
226+
tests.my-group-3.com:
227+
enabled: true
228+
release:
229+
name: my-release
230+
namespace: my-namespace
231+
asserts:
232+
- hasDocuments:
233+
count: 1
234+
- equal:
235+
path: kind
236+
value: Role
237+
- lengthEqual:
238+
path: rules
239+
count: 7
240+
- contains:
241+
path: rules
242+
content:
243+
apiGroups: [ "my-group-2" ]
244+
resources: [ "test" ]
245+
verbs: ["create", "delete", "patch", "update", "get", "list", "watch"]
246+
- contains:
247+
path: rules
248+
content:
249+
apiGroups: [ "my-group-3.com" ]
250+
resources: [ "tests" ]
251+
verbs: ["create", "delete", "patch", "update", "get", "list", "watch"]
252+
253+
- it: translate
254+
set:
255+
sync:
256+
toHost:
257+
customResourceDefinitions:
258+
test.my-group-2:
259+
enabled: true
260+
translate:
261+
- path: "test"
262+
expression:
263+
toHost: "test"
264+
release:
265+
name: my-release
266+
namespace: my-namespace
267+
asserts:
268+
- notFailedTemplate: {}
269+
270+
- it: translate 2
271+
set:
272+
sync:
273+
toHost:
274+
customResourceDefinitions:
275+
test.my-group-2:
276+
enabled: true
277+
translate:
278+
- path: "test"
279+
reference:
280+
apiVersion: "v1"
281+
kind: "Secret"
282+
release:
283+
name: my-release
284+
namespace: my-namespace
285+
asserts:
286+
- notFailedTemplate: {}

0 commit comments

Comments
 (0)