forked from kyverno/kyverno
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: added chainsaw tests for backport
Signed-off-by: Ved Ratan <[email protected]>
- Loading branch information
Showing
49 changed files
with
706 additions
and
116 deletions.
There are no files selected for viewing
11 changes: 0 additions & 11 deletions
11
test/conformance/chainsaw/assert/allow-existing-violations/README.md
This file was deleted.
Oops, something went wrong.
34 changes: 0 additions & 34 deletions
34
test/conformance/chainsaw/assert/allow-existing-violations/chainsaw-test.yaml
This file was deleted.
Oops, something went wrong.
7 changes: 0 additions & 7 deletions
7
test/conformance/chainsaw/assert/allow-existing-violations/ns-ready.yaml
This file was deleted.
Oops, something went wrong.
7 changes: 0 additions & 7 deletions
7
test/conformance/chainsaw/assert/allow-existing-violations/ns-update-bad.yaml
This file was deleted.
Oops, something went wrong.
7 changes: 0 additions & 7 deletions
7
test/conformance/chainsaw/assert/allow-existing-violations/ns-update-good.yaml
This file was deleted.
Oops, something went wrong.
7 changes: 0 additions & 7 deletions
7
test/conformance/chainsaw/assert/allow-existing-violations/ns-update.yaml
This file was deleted.
Oops, something went wrong.
7 changes: 0 additions & 7 deletions
7
test/conformance/chainsaw/assert/allow-existing-violations/ns.yaml
This file was deleted.
Oops, something went wrong.
35 changes: 0 additions & 35 deletions
35
test/conformance/chainsaw/assert/allow-existing-violations/policy.yaml
This file was deleted.
Oops, something went wrong.
13 changes: 13 additions & 0 deletions
13
...terpolicy/enforce/enforce-validate-existing-allow-existing-violations/README.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
## Description | ||
|
||
This test mainly verifies that an enforce validate policy blocks changes in old objects that were present before policy was created when `allowExistingViolations` is set to `false` | ||
|
||
## Expected Behavior | ||
|
||
1. A bad pod is created that violates the policy. | ||
2. The policy is applied. | ||
3. Violating changes in bad pod causes error becuase `allowExistingViolations` is set to `false` | ||
|
||
## Reference Issue(s) | ||
|
||
10084 |
5 changes: 5 additions & 0 deletions
5
...sterpolicy/enforce/enforce-validate-existing-allow-existing-violations/bad-pod-ready.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
apiVersion: v1 | ||
kind: Pod | ||
metadata: | ||
name: badpod-allow-existing | ||
namespace: default |
8 changes: 8 additions & 0 deletions
8
...policy/enforce/enforce-validate-existing-allow-existing-violations/bad-pod-update-test.sh
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
if kubectl label po badpod-allow-existing foo=bad1 --overwrite 2>&1 | grep -q "validation error: rule check-labels" | ||
then | ||
echo "Test succeed, updating violating preexisting resource does throw error" | ||
exit 0 | ||
else | ||
echo "Test failed, updating violating preexisting resource should throw error" | ||
exit 1 | ||
fi |
14 changes: 14 additions & 0 deletions
14
...te/clusterpolicy/enforce/enforce-validate-existing-allow-existing-violations/bad-pod.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
apiVersion: v1 | ||
kind: Pod | ||
metadata: | ||
name: badpod-allow-existing | ||
namespace: default | ||
labels: | ||
foo: bad | ||
spec: | ||
containers: | ||
- name: container01 | ||
image: busybox:1.35 | ||
args: | ||
- sleep | ||
- 1d |
25 changes: 25 additions & 0 deletions
25
...sterpolicy/enforce/enforce-validate-existing-allow-existing-violations/chainsaw-test.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
apiVersion: chainsaw.kyverno.io/v1alpha1 | ||
kind: Test | ||
metadata: | ||
creationTimestamp: null | ||
name: enforce-validate-existing | ||
spec: | ||
steps: | ||
- name: step-01 | ||
try: | ||
- apply: | ||
file: bad-pod.yaml | ||
- assert: | ||
file: bad-pod-ready.yaml | ||
- name: step-02 | ||
try: | ||
- apply: | ||
file: policy.yaml | ||
- assert: | ||
file: policy-ready.yaml | ||
- name: step-03 | ||
try: | ||
- script: | ||
content: ./bad-pod-update-test.sh | ||
timeout: 30s | ||
|
4 changes: 4 additions & 0 deletions
4
...usterpolicy/enforce/enforce-validate-existing-allow-existing-violations/policy-ready.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
apiVersion: kyverno.io/v1 | ||
kind: ClusterPolicy | ||
metadata: | ||
name: check-labels-allow-existing |
22 changes: 22 additions & 0 deletions
22
...ate/clusterpolicy/enforce/enforce-validate-existing-allow-existing-violations/policy.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
apiVersion: kyverno.io/v1 | ||
kind: ClusterPolicy | ||
metadata: | ||
name: check-labels-allow-existing | ||
spec: | ||
background: true | ||
rules: | ||
- name: check-labels | ||
match: | ||
any: | ||
- resources: | ||
kinds: | ||
- Pod | ||
validate: | ||
failureAction: Enforce | ||
allowExistingViolations: false | ||
deny: | ||
conditions: | ||
any: | ||
- key: "{{ request.object.metadata.labels.foo || '' }}" | ||
operator: NotEquals | ||
value: 'bar' |
15 changes: 15 additions & 0 deletions
15
...hainsaw/validate/clusterpolicy/enforce/enforce-validate-existing-deny/README.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
## Description | ||
|
||
This test mainly verifies that an enforce validate policy does not block changes in old objects that were present before policy was created | ||
|
||
## Expected Behavior | ||
|
||
1. A pod is created that violates the policy. | ||
2. The policy is applied. | ||
3. A pod is created that follows the policy. | ||
4. Violating changes on bad pad does not cause error. | ||
5. Violating changes in good pod causes error. | ||
6. The bad pod once passed the policy, will be tracked by the policy and return error on bad changes. | ||
## Reference Issue(s) | ||
|
||
8837 |
5 changes: 5 additions & 0 deletions
5
...chainsaw/validate/clusterpolicy/enforce/enforce-validate-existing-deny/bad-pod-ready.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
apiVersion: v1 | ||
kind: Pod | ||
metadata: | ||
name: badpod-deny | ||
namespace: default |
8 changes: 8 additions & 0 deletions
8
...nsaw/validate/clusterpolicy/enforce/enforce-validate-existing-deny/bad-pod-update-test.sh
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
if kubectl label po badpod-deny foo=bad1 --overwrite 2>&1 | grep -q "validation error: rule check-labels" | ||
then | ||
echo "Test failed, updating violating preexisting resource should not throw error" | ||
exit 1 | ||
else | ||
echo "Test succeed, updating violating preexisting resource does not throw error" | ||
exit 0 | ||
fi |
14 changes: 14 additions & 0 deletions
14
...mance/chainsaw/validate/clusterpolicy/enforce/enforce-validate-existing-deny/bad-pod.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
apiVersion: v1 | ||
kind: Pod | ||
metadata: | ||
name: badpod-deny | ||
namespace: default | ||
labels: | ||
foo: bad | ||
spec: | ||
containers: | ||
- name: container01 | ||
image: busybox:1.35 | ||
args: | ||
- sleep | ||
- 1d |
40 changes: 40 additions & 0 deletions
40
...chainsaw/validate/clusterpolicy/enforce/enforce-validate-existing-deny/chainsaw-test.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
apiVersion: chainsaw.kyverno.io/v1alpha1 | ||
kind: Test | ||
metadata: | ||
creationTimestamp: null | ||
name: enforce-validate-existing | ||
spec: | ||
steps: | ||
- name: step-01 | ||
try: | ||
- apply: | ||
file: bad-pod.yaml | ||
- assert: | ||
file: bad-pod-ready.yaml | ||
- name: step-02 | ||
try: | ||
- apply: | ||
file: policy.yaml | ||
- assert: | ||
file: policy-ready.yaml | ||
- name: step-03 | ||
try: | ||
- apply: | ||
file: good-pod.yaml | ||
- assert: | ||
file: good-pod-ready.yaml | ||
- name: step-04 | ||
try: | ||
- script: | ||
content: ./bad-pod-update-test.sh | ||
timeout: 30s | ||
- name: step-05 | ||
try: | ||
- script: | ||
content: ./good-pod-update-test.sh | ||
timeout: 30s | ||
- name: step-06 | ||
try: | ||
- script: | ||
content: ./update-bad-pod-to-comply.sh | ||
timeout: 30s |
5 changes: 5 additions & 0 deletions
5
...hainsaw/validate/clusterpolicy/enforce/enforce-validate-existing-deny/good-pod-ready.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
apiVersion: v1 | ||
kind: Pod | ||
metadata: | ||
name: goodpod-deny | ||
namespace: default |
8 changes: 8 additions & 0 deletions
8
...saw/validate/clusterpolicy/enforce/enforce-validate-existing-deny/good-pod-update-test.sh
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
if kubectl label po goodpod-deny foo=bad1 --overwrite 2>&1 | grep -q "validation error: rule check-labels" | ||
then | ||
echo "Test succeed, updating violating resource throws error" | ||
exit 0 | ||
else | ||
echo "Test failed, updating violating resource did not throw error" | ||
exit 1 | ||
fi |
14 changes: 14 additions & 0 deletions
14
...ance/chainsaw/validate/clusterpolicy/enforce/enforce-validate-existing-deny/good-pod.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
apiVersion: v1 | ||
kind: Pod | ||
metadata: | ||
name: goodpod-deny | ||
namespace: default | ||
labels: | ||
foo: bar | ||
spec: | ||
containers: | ||
- name: container01 | ||
image: busybox:1.35 | ||
args: | ||
- sleep | ||
- 1d |
2 changes: 1 addition & 1 deletion
2
...low-existing-violations/policy-ready.yaml → ...-validate-existing-deny/policy-ready.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
apiVersion: kyverno.io/v1 | ||
kind: ClusterPolicy | ||
metadata: | ||
name: check-old-object | ||
name: check-labels-deny |
21 changes: 21 additions & 0 deletions
21
...rmance/chainsaw/validate/clusterpolicy/enforce/enforce-validate-existing-deny/policy.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
apiVersion: kyverno.io/v1 | ||
kind: ClusterPolicy | ||
metadata: | ||
name: check-labels-deny | ||
spec: | ||
background: true | ||
rules: | ||
- name: check-labels | ||
match: | ||
any: | ||
- resources: | ||
kinds: | ||
- Pod | ||
validate: | ||
failureAction: Enforce | ||
deny: | ||
conditions: | ||
any: | ||
- key: "{{ request.object.metadata.labels.foo || '' }}" | ||
operator: NotEquals | ||
value: 'bar' |
9 changes: 9 additions & 0 deletions
9
...validate/clusterpolicy/enforce/enforce-validate-existing-deny/update-bad-pod-to-comply.sh
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
kubectl label po badpod-deny foo=bar --overwrite | ||
if kubectl label po badpod-deny foo=bad1 --overwrite 2>&1 | grep -q "validation error: rule check-labels" | ||
then | ||
echo "Test succeed, updating violating resource throws error" | ||
exit 0 | ||
else | ||
echo "Test failed, updating violating resource did not throw error" | ||
exit 1 | ||
fi |
Oops, something went wrong.