diff --git a/test/cli/test/globalcontext/kyverno-test.yaml b/test/cli/test/globalcontext/kyverno-test.yaml new file mode 100644 index 0000000000..b9ebfbb476 --- /dev/null +++ b/test/cli/test/globalcontext/kyverno-test.yaml @@ -0,0 +1,16 @@ +apiVersion: cli.kyverno.io/v1alpha1 +kind: Test +metadata: + name: gctx +policies: +- policy.yaml +resources: +- resources.yaml +results: +- kind: Deployment + policy: gctx + resources: + - test-gctx/new-deployment + result: pass + rule: main-deployment-exists +variables: values.yaml diff --git a/test/cli/test/globalcontext/policy.yaml b/test/cli/test/globalcontext/policy.yaml new file mode 100644 index 0000000000..5869993205 --- /dev/null +++ b/test/cli/test/globalcontext/policy.yaml @@ -0,0 +1,33 @@ +apiVersion: kyverno.io/v1 +kind: ClusterPolicy +metadata: + name: gctx +spec: + failurePolicy: Fail + rules: + - name: main-deployment-exists + context: + - name: deploymentCount + globalReference: + name: gctxentry-apicall-correct + jmesPath: "items | length(@)" + match: + all: + - resources: + kinds: + - Pod + preconditions: + all: + - key: "{{ request.operation }}" + operator: AnyIn + value: + - CREATE + - UPDATE + validate: + validationFailureAction: Enforce + deny: + conditions: + any: + - key: "{{ deploymentCount }}" + operator: Equal + value: 0 diff --git a/test/cli/test/globalcontext/resources.yaml b/test/cli/test/globalcontext/resources.yaml new file mode 100644 index 0000000000..2c1f25d742 --- /dev/null +++ b/test/cli/test/globalcontext/resources.yaml @@ -0,0 +1,22 @@ +apiVersion: apps/v1 +kind: Deployment +metadata: + name: new-deployment + namespace: test-gctx + labels: + app: new-deployment +spec: + replicas: 1 + selector: + matchLabels: + app: new-deployment + template: + metadata: + labels: + app: new-deployment + spec: + containers: + - name: nginx + image: nginx:1.14.2 + ports: + - containerPort: 80 diff --git a/test/cli/test/globalcontext/values.yaml b/test/cli/test/globalcontext/values.yaml new file mode 100644 index 0000000000..2a906e39aa --- /dev/null +++ b/test/cli/test/globalcontext/values.yaml @@ -0,0 +1,12 @@ +apiVersion: cli.kyverno.io/v1alpha1 +kind: Value +metadata: + name: values +globalValues: + request.operation: CREATE +policies: + - name: gctx + rules: + - name: main-deployment-exists + values: + deploymentCount: 1