diff --git a/test/cli/test/wildcard_match_label_selector/kyverno-test.yaml b/test/cli/test/wildcard_match_label_selector/kyverno-test.yaml new file mode 100644 index 0000000000..967a870fb8 --- /dev/null +++ b/test/cli/test/wildcard_match_label_selector/kyverno-test.yaml @@ -0,0 +1,31 @@ +name: wildcard-support-in-matchlabels +policies: + - policy.yaml +resources: + - resources.yaml +results: + - policy: wildcard-support-in-matchlabels + rule: wildcard-label + resource: my-service-1 + kind: Pod + result: pass + - policy: wildcard-support-in-matchlabels + rule: label-end-with-test + resource: my-service-2 + kind: Pod + result: pass + - policy: wildcard-support-in-matchlabels + rule: label-end-with-test + resource: my-service-3 + kind: Pod + result: skip + - policy: wildcard-support-in-matchlabels + rule: label-start-with-test + resource: my-service-4 + kind: Pod + result: pass + - policy: wildcard-support-in-matchlabels + rule: label-start-with-test + resource: my-service-5 + kind: Pod + result: skip \ No newline at end of file diff --git a/test/cli/test/wildcard_match_label_selector/policy.yaml b/test/cli/test/wildcard_match_label_selector/policy.yaml new file mode 100644 index 0000000000..972dc0ce93 --- /dev/null +++ b/test/cli/test/wildcard_match_label_selector/policy.yaml @@ -0,0 +1,50 @@ +apiVersion: kyverno.io/v1 +kind: ClusterPolicy +metadata: + name: wildcard-support-in-matchlabels +spec: + validationFailureAction: enforce + background: false + rules: + - name: wildcard-label + match: + resources: + kinds: + - Pod + selector: + matchLabels: + protected: "*" + validate: + message: "Using a mutable image tag e.g. 'latest' is not allowed." + pattern: + spec: + containers: + - image: "!*:latest" + - name: label-end-with-test + match: + resources: + kinds: + - pod + selector: + matchLabels: + protected: "*-test" + validate: + message: "Using a mutable image tag e.g. 'latest' is not allowed." + pattern: + spec: + containers: + - image: "!*:latest" + - name: label-start-with-test + match: + resources: + kinds: + - pod + selector: + matchLabels: + protected: "test-*" + validate: + message: "Using a mutable image tag e.g. 'latest' is not allowed." + pattern: + spec: + containers: + - image: "!*:latest" \ No newline at end of file diff --git a/test/cli/test/wildcard_match_label_selector/resources.yaml b/test/cli/test/wildcard_match_label_selector/resources.yaml new file mode 100644 index 0000000000..6b40c347e7 --- /dev/null +++ b/test/cli/test/wildcard_match_label_selector/resources.yaml @@ -0,0 +1,57 @@ +apiVersion: v1 +kind: Pod +metadata: + name: my-service-1 + labels: + protected: "true" +spec: + containers: + - name: nginx + image: nginx + +--- +apiVersion: v1 +kind: Pod +metadata: + name: my-service-2 + labels: + protected: "label-test" +spec: + containers: + - name: nginx + image: nginx + +--- +apiVersion: v1 +kind: Pod +metadata: + name: my-service-3 + labels: + protected: "label-fail" +spec: + containers: + - name: nginx + image: nginx +--- +apiVersion: v1 +kind: Pod +metadata: + name: my-service-4 + labels: + protected: "test-label" +spec: + containers: + - name: nginx + image: nginx + +--- +apiVersion: v1 +kind: Pod +metadata: + name: my-service-5 + labels: + protected: "fail-label" +spec: + containers: + - name: nginx + image: nginx \ No newline at end of file