Skip to content

Commit de7d298

Browse files
committed
kubearchive's policy: add support for new tenant label
This commit adds support for the new tenant label in the policy that generates the KubeArchiveConfig in each tenant namespace. Signed-off-by: Francesco Ilario <[email protected]>
1 parent de932c0 commit de7d298

File tree

3 files changed

+92
-0
lines changed

3 files changed

+92
-0
lines changed

components/kubearchive/policies/.chainsaw-test/chainsaw-test.yaml

+80
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,46 @@
11
# yaml-language-server: $schema=https://raw.githubusercontent.com/kyverno/chainsaw/main/.schemas/json/test-chainsaw-v1alpha1.json
22
apiVersion: chainsaw.kyverno.io/v1alpha1
33
kind: Test
4+
metadata:
5+
name: mutate-new-namespace-konfluxcidev
6+
spec:
7+
description: |
8+
tests that the KubeArchiveConfig is created in a namespace
9+
labelled with `konflux-ci.dev/type=tenant`
10+
concurrent: false
11+
namespace: 'generate-new-namespace'
12+
bindings:
13+
- name: suffix
14+
value: konfluxcidev
15+
steps:
16+
- name: given-kubearchiveconfig-crd-exists
17+
try:
18+
- apply:
19+
file: resources/kubearchive-crd.yaml
20+
- name: given-kyverno-has-permission-on-resources
21+
try:
22+
- apply:
23+
file: ../kyverno_rbac.yaml
24+
- name: given-cluster-policy-is-ready
25+
try:
26+
- apply:
27+
file: ../bootstrap-namespace.yaml
28+
- assert:
29+
file: chainsaw-assert-clusterpolicy.yaml
30+
- name: when-konfluxcidev-labeled-namespace-is-created
31+
try:
32+
- apply:
33+
file: resources/actual-namespace-konfluxcidev.yaml
34+
template: true
35+
- name: then-kubearchiveconfig-is-created
36+
try:
37+
- assert:
38+
file: resources/expected-kubearchiveconfig.yaml
39+
template: true
40+
---
41+
# yaml-language-server: $schema=https://raw.githubusercontent.com/kyverno/chainsaw/main/.schemas/json/test-chainsaw-v1alpha1.json
42+
apiVersion: chainsaw.kyverno.io/v1alpha1
43+
kind: Test
444
metadata:
545
name: mutate-new-namespace-konflux
646
spec:
@@ -200,6 +240,46 @@ spec:
200240
# yaml-language-server: $schema=https://raw.githubusercontent.com/kyverno/chainsaw/main/.schemas/json/test-chainsaw-v1alpha1.json
201241
apiVersion: chainsaw.kyverno.io/v1alpha1
202242
kind: Test
243+
metadata:
244+
name: mutate-existing-namespace-konfluxcidev
245+
spec:
246+
description: |
247+
tests that the KubeArchiveConfig is created in an already existing
248+
namespace labelled with `konflux-ci.dev/type=tenant`
249+
concurrent: false
250+
namespace: 'generate-existing-namespace'
251+
bindings:
252+
- name: suffix
253+
value: konflux
254+
steps:
255+
- name: given-kubearchiveconfig-crd-exists
256+
try:
257+
- apply:
258+
file: resources/kubearchive-crd.yaml
259+
- name: given-kyverno-has-permission-on-resources
260+
try:
261+
- apply:
262+
file: ../kyverno_rbac.yaml
263+
- name: given-konfluxci-labeled-namespace-is-created
264+
try:
265+
- apply:
266+
file: resources/actual-namespace-konfluxcidev.yaml
267+
template: true
268+
- name: when-cluster-policy-is-ready
269+
try:
270+
- apply:
271+
file: ../bootstrap-namespace.yaml
272+
- assert:
273+
file: chainsaw-assert-clusterpolicy.yaml
274+
- name: then-kubearchiveconfig-is-created
275+
try:
276+
- assert:
277+
file: resources/expected-kubearchiveconfig.yaml
278+
template: true
279+
---
280+
# yaml-language-server: $schema=https://raw.githubusercontent.com/kyverno/chainsaw/main/.schemas/json/test-chainsaw-v1alpha1.json
281+
apiVersion: chainsaw.kyverno.io/v1alpha1
282+
kind: Test
203283
metadata:
204284
name: mutate-existing-namespace-toolchain
205285
spec:
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
apiVersion: v1
2+
kind: Namespace
3+
metadata:
4+
name: (join('-', [$namespace, $suffix]))
5+
labels:
6+
konflux-ci.dev/type: tenant

components/kubearchive/policies/bootstrap-namespace.yaml

+6
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,12 @@ spec:
1919
selector:
2020
matchLabels:
2121
konflux.ci/type: user
22+
- resources:
23+
kinds:
24+
- Namespace
25+
selector:
26+
matchLabels:
27+
konflux-ci.dev/type: tenant
2228
generate:
2329
generateExisting: true
2430
apiVersion: kubearchive.kubearchive.org/v1alpha1

0 commit comments

Comments
 (0)