diff --git a/other/copy-namespace-labels/.chainsaw-test/chainsaw-test.yaml b/other/copy-namespace-labels/.chainsaw-test/chainsaw-test.yaml new file mode 100644 index 000000000..125cccbe9 --- /dev/null +++ b/other/copy-namespace-labels/.chainsaw-test/chainsaw-test.yaml @@ -0,0 +1,28 @@ +apiVersion: chainsaw.kyverno.io/v1alpha1 +kind: Test +metadata: + name: copy-namespace-labels +spec: + steps: + - name: step-01 + try: + - apply: + file: ns.yaml + - apply: + file: ../copy-namespace-labels.yaml + - assert: + file: policy-ready.yaml + - name: step-02 + try: + - apply: + file: resource.yaml + - assert: + file: patchresource.yaml + - error: + resource: + apiVersion: apps/v1 + kind: Deployment + metadata: + namespace: within-ns + labels: + kubernetes.io/metadata.name: "within-ns" \ No newline at end of file diff --git a/other/copy-namespace-labels/.chainsaw-test/ns.yaml b/other/copy-namespace-labels/.chainsaw-test/ns.yaml new file mode 100644 index 000000000..5940d9141 --- /dev/null +++ b/other/copy-namespace-labels/.chainsaw-test/ns.yaml @@ -0,0 +1,7 @@ +apiVersion: v1 +kind: Namespace +metadata: + name: within-ns + labels: + owner: "any-corp" + env: dev diff --git a/other/copy-namespace-labels/.chainsaw-test/patchresource.yaml b/other/copy-namespace-labels/.chainsaw-test/patchresource.yaml new file mode 100644 index 000000000..a2f8ea14b --- /dev/null +++ b/other/copy-namespace-labels/.chainsaw-test/patchresource.yaml @@ -0,0 +1,66 @@ +apiVersion: apps/v1 +kind: Deployment +metadata: + name: my-deployment-1 + namespace: within-ns + labels: + app: good-app + owner: "any-corp" + env: dev +spec: + replicas: 1 + selector: + matchLabels: + app: good-app + template: + metadata: + labels: + app: good-app + spec: + containers: + - name: good-app-deploy + image: busybox:1.35 +--- +apiVersion: apps/v1 +kind: Deployment +metadata: + name: my-deployment-3 + namespace: within-ns + labels: + owner: "any-corp" + env: dev +spec: + replicas: 1 + selector: + matchLabels: + app: my-app03 + template: + metadata: + labels: + app: my-app03 + spec: + containers: + - name: my-app03-deploy + image: busybox:1.35 +--- +apiVersion: apps/v1 +kind: Deployment +metadata: + name: my-deployment-4 + namespace: within-ns + labels: + owner: "any-corp" + env: dev +spec: + replicas: 1 + selector: + matchLabels: + app: my-app04 + template: + metadata: + labels: + app: my-app04 + spec: + containers: + - name: my-app04-deploy + image: busybox:1.35 \ No newline at end of file diff --git a/other/copy-namespace-labels/.chainsaw-test/policy-ready.yaml b/other/copy-namespace-labels/.chainsaw-test/policy-ready.yaml new file mode 100644 index 000000000..1fed6971c --- /dev/null +++ b/other/copy-namespace-labels/.chainsaw-test/policy-ready.yaml @@ -0,0 +1,6 @@ +apiVersion: kyverno.io/v1 +kind: ClusterPolicy +metadata: + name: copy-namespace-labels +status: + ready: true diff --git a/other/copy-namespace-labels/.chainsaw-test/resource.yaml b/other/copy-namespace-labels/.chainsaw-test/resource.yaml new file mode 100644 index 000000000..b1b58993e --- /dev/null +++ b/other/copy-namespace-labels/.chainsaw-test/resource.yaml @@ -0,0 +1,60 @@ +apiVersion: apps/v1 +kind: Deployment +metadata: + name: my-deployment-1 + namespace: within-ns + labels: + app: good-app +spec: + replicas: 1 + selector: + matchLabels: + app: good-app + template: + metadata: + labels: + app: good-app + spec: + containers: + - name: good-app-deploy + image: busybox:1.35 +--- +apiVersion: apps/v1 +kind: Deployment +metadata: + name: my-deployment-3 + namespace: within-ns + labels: + owner: "dev-team" +spec: + replicas: 1 + selector: + matchLabels: + app: my-app03 + template: + metadata: + labels: + app: my-app03 + spec: + containers: + - name: my-app03-deploy + image: busybox:1.35 +--- +apiVersion: apps/v1 +kind: Deployment +metadata: + name: my-deployment-4 + namespace: within-ns +spec: + replicas: 1 + selector: + matchLabels: + app: my-app04 + template: + metadata: + labels: + app: my-app04 + spec: + containers: + - name: my-app04-deploy + image: busybox:1.35