1
0
Fork 0
mirror of https://github.com/kyverno/kyverno.git synced 2025-03-06 16:06:56 +00:00

tests: add chainsaw test for image data loading (#12077)

Signed-off-by: Charles-Edouard Brétéché <charles.edouard@nirmata.com>
This commit is contained in:
Charles-Edouard Brétéché 2025-02-04 10:22:43 +01:00 committed by GitHub
parent ac45755fc5
commit c78ab6654c
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 59 additions and 0 deletions

View file

@ -0,0 +1,17 @@
# yaml-language-server: $schema=https://raw.githubusercontent.com/kyverno/chainsaw/main/.schemas/json/test-chainsaw-v1alpha1.json
apiVersion: chainsaw.kyverno.io/v1alpha1
kind: Test
metadata:
name: image-data
spec:
steps:
- name: create policy
try:
- create:
file: policy.yaml
- sleep:
duration: 10s
- name: create deployment
try:
- create:
file: deployment.yaml

View file

@ -0,0 +1,19 @@
apiVersion: apps/v1
kind: Deployment
metadata:
name: deployment
labels:
app: nginx
spec:
replicas: 1
selector:
matchLabels:
app: nginx
template:
metadata:
labels:
app: nginx
spec:
containers:
- name: nginx
image: nginx:latest

View file

@ -0,0 +1,23 @@
apiVersion: kyverno.io/v2alpha1
kind: ValidatingPolicy
metadata:
name: check-deployment-labels
spec:
matchConstraints:
resourceRules:
- apiGroups: [apps]
apiVersions: [v1]
operations: [CREATE, UPDATE]
resources: [deployments]
variables:
- name: image
expression: >-
context.GetImageData("ghcr.io/kyverno/kyverno:latest")
- name: accept
expression: >-
variables.image != null
validations:
- expression: >-
variables.accept
message: >-
Deployment must be accepted