mirror of
https://github.com/kyverno/kyverno.git
synced 2024-12-14 11:57:48 +00:00
test(gctx): cli variable injection (#10809)
Signed-off-by: Khaled Emara <khaled.emara@nirmata.com> Co-authored-by: Mariam Fahmy <mariam.fahmy@nirmata.com>
This commit is contained in:
parent
25b7142ee0
commit
e0ff371ccc
4 changed files with 83 additions and 0 deletions
16
test/cli/test/globalcontext/kyverno-test.yaml
Normal file
16
test/cli/test/globalcontext/kyverno-test.yaml
Normal file
|
@ -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
|
33
test/cli/test/globalcontext/policy.yaml
Normal file
33
test/cli/test/globalcontext/policy.yaml
Normal file
|
@ -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
|
22
test/cli/test/globalcontext/resources.yaml
Normal file
22
test/cli/test/globalcontext/resources.yaml
Normal file
|
@ -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
|
12
test/cli/test/globalcontext/values.yaml
Normal file
12
test/cli/test/globalcontext/values.yaml
Normal file
|
@ -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
|
Loading…
Reference in a new issue