1
0
Fork 0
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:
Khaled Emara 2024-08-13 16:15:53 +03:00 committed by GitHub
parent 25b7142ee0
commit e0ff371ccc
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 83 additions and 0 deletions

View 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

View 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

View 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

View 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