forked from kyverno/kyverno
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: chainsaw tests for generateExisting
Signed-off-by: ShutingZhao <[email protected]>
- Loading branch information
1 parent
ba04f5f
commit 14b8a86
Showing
7 changed files
with
128 additions
and
0 deletions.
There are no files selected for viewing
26 changes: 26 additions & 0 deletions
26
test/conformance/chainsaw/generate/foreach/existing/cpol-clone-sync-create/1-1-source.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,26 @@ | ||
apiVersion: v1 | ||
kind: Namespace | ||
metadata: | ||
name: foreach-ns-1 | ||
--- | ||
apiVersion: v1 | ||
kind: Namespace | ||
metadata: | ||
name: foreach-ns-2 | ||
--- | ||
apiVersion: v1 | ||
data: | ||
foo: YmFy | ||
kind: Secret | ||
metadata: | ||
name: source-secret | ||
namespace: default | ||
type: Opaque | ||
--- | ||
kind: ConfigMap | ||
apiVersion: v1 | ||
metadata: | ||
name: default-deny | ||
namespace: default | ||
data: | ||
namespaces: foreach-ns-1,foreach-ns-2 |
43 changes: 43 additions & 0 deletions
43
test/conformance/chainsaw/generate/foreach/existing/cpol-clone-sync-create/2-1-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,43 @@ | ||
apiVersion: kyverno.io/v1 | ||
kind: ClusterPolicy | ||
metadata: | ||
name: foreach-cpol-clone-sync-create | ||
spec: | ||
rules: | ||
- match: | ||
any: | ||
- resources: | ||
kinds: | ||
- ConfigMap | ||
name: k-kafka-address | ||
context: | ||
- name: configmapns | ||
variable: | ||
jmesPath: request.object.metadata.namespace | ||
preconditions: | ||
any: | ||
- key: '{{configmapns}}' | ||
operator: Equals | ||
value: 'default' | ||
generate: | ||
generateExisting: true | ||
synchronize: true | ||
foreach: | ||
- list: request.object.data.namespaces | split(@, ',') | ||
context: | ||
- name: ns | ||
variable: | ||
jmesPath: element | ||
preconditions: | ||
any: | ||
- key: '{{ ns }}' | ||
operator: AnyIn | ||
value: | ||
- foreach-ns-1 | ||
apiVersion: v1 | ||
kind: Secret | ||
name: cloned-secret-{{ elementIndex }}-{{ ns }} | ||
namespace: '{{ ns }}' | ||
clone: | ||
namespace: default | ||
name: source-secret |
9 changes: 9 additions & 0 deletions
9
...formance/chainsaw/generate/foreach/existing/cpol-clone-sync-create/2-2-policy-assert.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,9 @@ | ||
apiVersion: kyverno.io/v1 | ||
kind: ClusterPolicy | ||
metadata: | ||
name: foreach-cpol-clone-sync-create | ||
status: | ||
conditions: | ||
- reason: Succeeded | ||
status: "True" | ||
type: Ready |
8 changes: 8 additions & 0 deletions
8
...formance/chainsaw/generate/foreach/existing/cpol-clone-sync-create/3-1-cloned-target.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,8 @@ | ||
apiVersion: v1 | ||
data: | ||
foo: YmFy | ||
kind: Secret | ||
metadata: | ||
name: cloned-secret-0-foreach-ns-1 | ||
namespace: foreach-ns-1 | ||
type: Opaque |
8 changes: 8 additions & 0 deletions
8
...mance/chainsaw/generate/foreach/existing/cpol-clone-sync-create/3-2-no-cloned-target.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,8 @@ | ||
apiVersion: v1 | ||
data: | ||
foo: YmFy | ||
kind: Secret | ||
metadata: | ||
name: cloned-secret-0-foreach-ns-2 | ||
namespace: foreach-ns-2 | ||
type: Opaque |
11 changes: 11 additions & 0 deletions
11
...conformance/chainsaw/generate/foreach/existing/cpol-clone-sync-create/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,11 @@ | ||
## Description | ||
|
||
This is a basic test for generate existing foreach clone policy, with preconditions and context variables. It checks that the basic functionality works whereby installation of the policy causes correct evaluation of the match and preconditions blocks. | ||
|
||
## Expected Behavior | ||
|
||
If only the `foreach-ns-1` Namespace receives a cloned Secret upon policy creation, the test passes. If either it does not or `foreach-ns-2` receives a cloned Secret, the test fails. | ||
|
||
## Reference Issue(s) | ||
|
||
https://github.com/kyverno/kyverno/issues/3542 |
23 changes: 23 additions & 0 deletions
23
.../conformance/chainsaw/generate/foreach/existing/cpol-clone-sync-create/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,23 @@ | ||
apiVersion: chainsaw.kyverno.io/v1alpha1 | ||
kind: Test | ||
metadata: | ||
creationTimestamp: null | ||
name: cpol-data-sync-create | ||
spec: | ||
steps: | ||
- name: step-01 | ||
try: | ||
- apply: | ||
file: 1-1-source.yaml | ||
- name: step-02 | ||
try: | ||
- apply: | ||
file: 2-1-policy.yaml | ||
- assert: | ||
file: 2-2-policy-assert.yaml | ||
- name: step-03 | ||
try: | ||
- apply: | ||
file: 3-1-cloned-target.yaml | ||
- error: | ||
file: 3-2-no-cloned-target.yaml |