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.
Signed-off-by: ShutingZhao <[email protected]>
- Loading branch information
1 parent
e67a111
commit c868596
Showing
11 changed files
with
224 additions
and
17 deletions.
There are no files selected for viewing
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
17 changes: 17 additions & 0 deletions
17
...erpolicy/standard/existing/different-generate-existing-values-reorder/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,17 @@ | ||
## Description | ||
|
||
This test ensures that a generate policy works as expected in case the rules have a different value for the `generateExisting` field. | ||
|
||
## Expected Behavior | ||
|
||
1. Create two Namespaces named `red-ns` and `green-ns`. | ||
|
||
2. Create a policy with two generate rules: | ||
- The first rule named `generate-network-policy` matches Namespaces sets the `generateExisting` to `true`. | ||
- The second rule named `generate-config-map` matches Namespaces sets the `generateExisting` to `false`. | ||
|
||
3. It is expected that a NetworkPolicy will be generated for each Namespace whereas ConfigMaps will not be generated. | ||
|
||
## Reference Issue(s) | ||
|
||
N/A |
27 changes: 27 additions & 0 deletions
27
...terpolicy/standard/existing/different-generate-existing-values-reorder/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,27 @@ | ||
apiVersion: chainsaw.kyverno.io/v1alpha1 | ||
kind: Test | ||
metadata: | ||
creationTimestamp: null | ||
name: different-generate-existing-values | ||
spec: | ||
steps: | ||
- name: step-01 | ||
try: | ||
- apply: | ||
file: existing-resources.yaml | ||
- name: step-02 | ||
try: | ||
- apply: | ||
file: policy.yaml | ||
- assert: | ||
file: policy-ready.yaml | ||
- name: step-03 | ||
try: | ||
- sleep: | ||
duration: 3s | ||
- name: step-04 | ||
try: | ||
- assert: | ||
file: generated-resources.yaml | ||
- error: | ||
file: fail-generated-resources.yaml |
13 changes: 13 additions & 0 deletions
13
...licy/standard/existing/different-generate-existing-values-reorder/existing-resources.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,13 @@ | ||
apiVersion: v1 | ||
kind: Namespace | ||
metadata: | ||
name: red-ns | ||
labels: | ||
color: red | ||
--- | ||
apiVersion: v1 | ||
kind: Namespace | ||
metadata: | ||
name: green-ns | ||
labels: | ||
color: green |
34 changes: 34 additions & 0 deletions
34
...tandard/existing/different-generate-existing-values-reorder/fail-generated-resources.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,34 @@ | ||
apiVersion: v1 | ||
data: | ||
KAFKA_ADDRESS: 192.168.10.13:9092,192.168.10.14:9092,192.168.10.15:9092 | ||
ZK_ADDRESS: 192.168.10.10:2181,192.168.10.11:2181,192.168.10.12:2181 | ||
kind: ConfigMap | ||
metadata: | ||
labels: | ||
somekey: somevalue | ||
name: zk-kafka-address | ||
namespace: red-ns | ||
--- | ||
apiVersion: v1 | ||
data: | ||
KAFKA_ADDRESS: 192.168.10.13:9092,192.168.10.14:9092,192.168.10.15:9092 | ||
ZK_ADDRESS: 192.168.10.10:2181,192.168.10.11:2181,192.168.10.12:2181 | ||
kind: ConfigMap | ||
metadata: | ||
labels: | ||
somekey: somevalue | ||
name: zk-kafka-address | ||
namespace: green-ns | ||
--- | ||
apiVersion: networking.k8s.io/v1 | ||
kind: NetworkPolicy | ||
metadata: | ||
labels: | ||
created-by: kyverno | ||
name: default-deny | ||
namespace: red-ns | ||
spec: | ||
podSelector: {} | ||
policyTypes: | ||
- Ingress | ||
- Egress |
25 changes: 25 additions & 0 deletions
25
...icy/standard/existing/different-generate-existing-values-reorder/generated-resources.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: networking.k8s.io/v1 | ||
# kind: NetworkPolicy | ||
# metadata: | ||
# labels: | ||
# created-by: kyverno | ||
# name: default-deny | ||
# namespace: red-ns | ||
# spec: | ||
# podSelector: {} | ||
# policyTypes: | ||
# - Ingress | ||
# - Egress | ||
--- | ||
apiVersion: networking.k8s.io/v1 | ||
kind: NetworkPolicy | ||
metadata: | ||
labels: | ||
created-by: kyverno | ||
name: default-deny | ||
namespace: green-ns | ||
spec: | ||
podSelector: {} | ||
policyTypes: | ||
- Ingress | ||
- Egress |
9 changes: 9 additions & 0 deletions
9
...sterpolicy/standard/existing/different-generate-existing-values-reorder/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,9 @@ | ||
apiVersion: kyverno.io/v1 | ||
kind: ClusterPolicy | ||
metadata: | ||
name: different-generate-existing-values-reorder | ||
status: | ||
conditions: | ||
- reason: Succeeded | ||
status: "True" | ||
type: Ready |
53 changes: 53 additions & 0 deletions
53
...te/clusterpolicy/standard/existing/different-generate-existing-values-reorder/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,53 @@ | ||
apiVersion: kyverno.io/v1 | ||
kind: ClusterPolicy | ||
metadata: | ||
name: different-generate-existing-values-reorder | ||
spec: | ||
rules: | ||
- name: generate-config-map | ||
match: | ||
any: | ||
- resources: | ||
kinds: | ||
- Namespace | ||
names: | ||
- red-ns | ||
generate: | ||
generateExisting: false | ||
synchronize: true | ||
apiVersion: v1 | ||
kind: ConfigMap | ||
name: zk-kafka-address | ||
namespace: "{{request.object.metadata.name}}" | ||
data: | ||
kind: ConfigMap | ||
metadata: | ||
labels: | ||
somekey: somevalue | ||
data: | ||
ZK_ADDRESS: "192.168.10.10:2181,192.168.10.11:2181,192.168.10.12:2181" | ||
KAFKA_ADDRESS: "192.168.10.13:9092,192.168.10.14:9092,192.168.10.15:9092" | ||
- name: generate-network-policy | ||
match: | ||
any: | ||
- resources: | ||
kinds: | ||
- Namespace | ||
names: | ||
- green-ns | ||
generate: | ||
generateExisting: true | ||
kind: NetworkPolicy | ||
apiVersion: networking.k8s.io/v1 | ||
name: default-deny | ||
namespace: "{{request.object.metadata.name}}" | ||
synchronize: true | ||
data: | ||
metadata: | ||
labels: | ||
created-by: kyverno | ||
spec: | ||
podSelector: {} | ||
policyTypes: | ||
- Ingress | ||
- Egress |
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
24 changes: 12 additions & 12 deletions
24
...usterpolicy/standard/existing/different-generate-existing-values/generated-resources.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
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