1
0
Fork 0
mirror of https://github.com/kyverno/kyverno.git synced 2024-12-14 11:57:48 +00:00

chore: improve a couple kuttl tests (#6079)

* chore: improve a couple kuttl tests

Signed-off-by: Charles-Edouard Brétéché <charles.edouard@nirmata.com>

* more

Signed-off-by: Charles-Edouard Brétéché <charles.edouard@nirmata.com>

* more

Signed-off-by: Charles-Edouard Brétéché <charles.edouard@nirmata.com>

* readme

Signed-off-by: Charles-Edouard Brétéché <charles.edouard@nirmata.com>

* Update test/conformance/kuttl/cleanup/validation/cron-format/README.md

Signed-off-by: Charles-Edouard Brétéché <charles.edouard@nirmata.com>

---------

Signed-off-by: Charles-Edouard Brétéché <charles.edouard@nirmata.com>
This commit is contained in:
Charles-Edouard Brétéché 2023-01-30 15:11:06 +01:00 committed by GitHub
parent 6a95f480e3
commit 47b4a177dd
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
37 changed files with 74 additions and 139 deletions

View file

@ -1,5 +0,0 @@
# A clean-up is presently required because kuttl does not do a reliable job of cleaning up both cluster-scoped objects.
apiVersion: kuttl.dev/v1beta1
kind: TestStep
commands:
- command: kubectl delete -f 01-manifests.yaml,02-secret.yaml --force --wait=true --ignore-not-found=true

View file

@ -1,4 +0,0 @@
apiVersion: kuttl.dev/v1beta1
kind: TestStep
commands:
- command: kubectl delete -f 01-manifests.yaml,02-secret.yaml --force --wait=true --ignore-not-found=true

View file

@ -1,20 +0,0 @@
apiVersion: kyverno.io/v2alpha1
kind: ClusterCleanupPolicy
metadata:
name: cleanup-pod
spec:
match:
any:
- resources:
kinds:
- Pod
conditions:
all:
- key: "{{ target.metadata.name }}"
operator: Equals
value: example
- key: "{{ target.metadata.namespace }}"
operator: Equals
value: default
## execute every minute
schedule: "*/1 * * * *"

View file

@ -0,0 +1,4 @@
apiVersion: kuttl.dev/v1beta1
kind: TestStep
apply:
- rbac.yaml

View file

@ -0,0 +1,6 @@
apiVersion: kuttl.dev/v1beta1
kind: TestStep
apply:
- pod.yaml
assert:
- pod-assert.yaml

View file

@ -1,5 +0,0 @@
# A command can only run a single command, not a pipeline and not a script. The program called must exist on the system where the test is run.
apiVersion: kuttl.dev/v1beta1
kind: TestStep
commands:
- command: sleep 65

View file

@ -0,0 +1,6 @@
apiVersion: kuttl.dev/v1beta1
kind: TestStep
apply:
- policy.yaml
assert:
- policy.yaml

View file

@ -0,0 +1,4 @@
apiVersion: kuttl.dev/v1beta1
kind: TestStep
commands:
- command: sleep 65

View file

@ -0,0 +1,4 @@
apiVersion: kuttl.dev/v1beta1
kind: TestStep
error:
- pod-assert.yaml

View file

@ -1,5 +0,0 @@
# A clean-up is presently required because kuttl does not do a reliable job of cleaning up both cluster-scoped objects.
apiVersion: kuttl.dev/v1beta1
kind: TestStep
commands:
- command: kubectl delete -f 00-manifests.yaml,01-policy.yaml --force --wait=true --ignore-not-found=true

View file

@ -6,5 +6,4 @@ This test cleans up pods via a cluster cleanup policy.
The pod `default/example` is cleaned up successfully.
## Reference Issue(s)

View file

@ -2,4 +2,4 @@ apiVersion: v1
kind: Pod
metadata:
name: example
namespace: default
namespace: default

View file

@ -6,4 +6,4 @@ metadata:
spec:
containers:
- image: nginx:latest
name: example
name: example

View file

@ -17,4 +17,4 @@ spec:
operator: Equals
value: default
## execute every minute
schedule: "*/1 * * * *"
schedule: "*/1 * * * *"

View file

@ -1,13 +1,3 @@
apiVersion: v1
kind: Pod
metadata:
name: example
namespace: default
spec:
containers:
- image: nginx:latest
name: example
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:

View file

@ -1,17 +0,0 @@
apiVersion: kyverno.io/v2alpha1
kind: CleanupPolicy
metadata:
name: cleanup-pod
namespace: default
spec:
match:
any:
- resources:
kinds:
- Pod
conditions:
any:
- key: "{{ target.metadata.name }}"
operator: Equals
value: example
schedule: "*/1 * * * *"

View file

@ -0,0 +1,4 @@
apiVersion: kuttl.dev/v1beta1
kind: TestStep
apply:
- rbac.yaml

View file

@ -0,0 +1,6 @@
apiVersion: kuttl.dev/v1beta1
kind: TestStep
apply:
- pod.yaml
assert:
- pod-assert.yaml

View file

@ -1,5 +0,0 @@
# A command can only run a single command, not a pipeline and not a script. The program called must exist on the system where the test is run.
apiVersion: kuttl.dev/v1beta1
kind: TestStep
commands:
- command: sleep 65

View file

@ -0,0 +1,6 @@
apiVersion: kuttl.dev/v1beta1
kind: TestStep
apply:
- policy.yaml
assert:
- policy.yaml

View file

@ -0,0 +1,4 @@
apiVersion: kuttl.dev/v1beta1
kind: TestStep
commands:
- command: sleep 65

View file

@ -0,0 +1,4 @@
apiVersion: kuttl.dev/v1beta1
kind: TestStep
error:
- pod-assert.yaml

View file

@ -1,5 +0,0 @@
# A clean-up is presently required because kuttl does not do a reliable job of cleaning up both cluster-scoped objects.
apiVersion: kuttl.dev/v1beta1
kind: TestStep
commands:
- command: kubectl delete -f 00-manifests.yaml,01-policy.yaml --force --wait=true --ignore-not-found=true

View file

@ -2,4 +2,4 @@ apiVersion: v1
kind: Pod
metadata:
name: example
namespace: default
namespace: default

View file

@ -6,4 +6,4 @@ metadata:
spec:
containers:
- image: nginx:latest
name: example
name: example

View file

@ -1,13 +1,3 @@
apiVersion: v1
kind: Pod
metadata:
name: example
namespace: default
spec:
containers:
- image: nginx:latest
name: example
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:

View file

@ -1,17 +0,0 @@
apiVersion: kyverno.io/v2alpha1
kind: CleanupPolicy
metadata:
name: cleanuppolicy
namespace: default
spec:
match:
any:
- resources:
kinds:
- Pod
conditions:
any:
- key: "{{ target.metadata.name }}"
operator: Equals
value: example
schedule: "*/2 * * * *"

View file

@ -1,16 +0,0 @@
apiVersion: kyverno.io/v2alpha1
kind: ClusterCleanupPolicy
metadata:
name: cleanuppolicy
spec:
match:
any:
- resources:
kinds:
- Pod
conditions:
any:
- key: "{{ target.metadata.name }}"
operator: Equals
value: example
schedule: "*/2 * * * *"

View file

@ -0,0 +1,6 @@
apiVersion: kuttl.dev/v1beta1
kind: TestStep
apply:
- policy.yaml
assert:
- policy.yaml

View file

@ -0,0 +1,6 @@
apiVersion: kuttl.dev/v1beta1
kind: TestStep
apply:
- clusterpolicy.yaml
assert:
- clusterpolicy.yaml

View file

@ -1,14 +0,0 @@
## Checks that the manifests.yaml file CANNOT be successfully created. If it can, fail the test as this is incorrect.
apiVersion: kuttl.dev/v1beta1
kind: TestStep
commands:
- script: |
if kubectl apply -f badcleanuppolicy.yaml
then
echo "Tested failed. Task was created when it shouldn't have been."
exit 1
else
echo "Test succeeded. Task was not created as intended."
exit 0
fi

View file

@ -0,0 +1,5 @@
apiVersion: kuttl.dev/v1beta1
kind: TestStep
apply:
- file: invalidpolicy.yaml
shouldFail: true

View file

@ -0,0 +1,4 @@
## Description
This test creates tries to create two cleanup policies, one with a valid schedule and one with an invalid schedule.
The creation of the one with the valid schedule is expected to succeed while the one with the invalid schedule is expected to fail.