Skip to content

Commit

Permalink
test: add kuttl tests for jmespath special chars (kyverno#5310)
Browse files Browse the repository at this point in the history
* Adds tests for fixes in kyverno#4767

Signed-off-by: Tobias Dahlberg <tobias.dahlberg@sinch.com>

Signed-off-by: Tobias Dahlberg <tobias.dahlberg@sinch.com>
Co-authored-by: shuting <shuting@nirmata.com>
  • Loading branch information
somebadcode and realshuting authored Nov 11, 2022
1 parent 001db94 commit 97a2b9a
Show file tree
Hide file tree
Showing 7 changed files with 80 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
apiVersion: kuttl.dev/v1beta1
kind: TestStep
apply:
- policy.yaml
assert:
- policy-assert.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
apiVersion: kuttl.dev/v1beta1
kind: TestStep
apply:
- resources.yaml
assert:
- resources-assert.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
## Description

This test checks that document references with special characters in their names are supported.

## Expected Behavior

JMESPath references generated when documents are traversed are escaped properly according to the JMESPath standard.

## Reference Issue(s)

3578
3616
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
apiVersion: kyverno.io/v1
kind: ClusterPolicy
metadata:
name: jmespath-with-special-chars-demo
status:
conditions:
- reason: Succeeded
status: "True"
type: Ready
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
apiVersion: kyverno.io/v1
kind: ClusterPolicy
metadata:
name: jmespath-with-special-chars-demo
spec:
rules:
- name: format-deploy-zone
match:
any:
- resources:
kinds:
- Pod
mutate:
patchStrategicMerge:
metadata:
labels:
deploy-zone: "{{ to_upper('{{@}}') }}"
- name: retention-adjust
match:
any:
- resources:
kinds:
- Pod
mutate:
patchStrategicMerge:
metadata:
labels:
corp.com/retention: "{{ regex_replace_all('([0-9])([0-9])', '{{ @ }}', '${1}0') }}"
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
apiVersion: v1
kind: Pod
metadata:
name: busybox
labels:
deploy-zone: FRANKFURT
corp.com/retention: days_30
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
apiVersion: v1
kind: Pod
metadata:
name: busybox
labels:
deploy-zone: frankfurt
corp.com/retention: days_37
spec:
containers:
- name: busybox
image: busybox:stable
command: ["sleep", "600"]

0 comments on commit 97a2b9a

Please sign in to comment.