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.
fix: account for error rules in mutation webhook (kyverno#5264)
* fix: account for error rules in mutation webhook Signed-off-by: Charles-Edouard Brétéché <[email protected]> * add test Signed-off-by: Charles-Edouard Brétéché <[email protected]> Signed-off-by: Charles-Edouard Brétéché <[email protected]>
- Loading branch information
1 parent
060f7bb
commit b71c000
Showing
11 changed files
with
121 additions
and
5 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
apiVersion: kyverno.io/v1 | ||
kind: ClusterPolicy | ||
metadata: | ||
name: propagate-cost-labels-from-namespace | ||
status: | ||
conditions: | ||
- reason: Succeeded | ||
status: "True" | ||
type: Ready |
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,29 @@ | ||
apiVersion: kyverno.io/v1 | ||
kind: ClusterPolicy | ||
metadata: | ||
name: propagate-cost-labels-from-namespace | ||
spec: | ||
failurePolicy: Ignore | ||
rules: | ||
- name: add-cost-labels | ||
context: | ||
- name: namespaceLabels | ||
apiCall: | ||
urlPath: "/api/v1/namespaces/{{request.namespace}}" | ||
jmesPath: metadata.labels | ||
match: | ||
any: | ||
- resources: | ||
kinds: | ||
- Pod | ||
- Deployment | ||
- StatefulSet | ||
- DaemonSet | ||
- Job | ||
- CronJob | ||
mutate: | ||
patchStrategicMerge: | ||
metadata: | ||
labels: | ||
cost.starfleet.evtech/project: "{{namespaceLabels.\"cost.starfleet.evtech/project\"}}" | ||
cost.starfleet.evtech/application: "{{request.object.metadata.labels.\"cost.starfleet.evtech/application\" || namespaceLabels.\"cost.starfleet.evtech/application\"}}" |
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 @@ | ||
## 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 resource.yaml | ||
then | ||
echo "Tested failed. Resource was allowed." | ||
exit 1 | ||
else | ||
echo "Test succeeded. Resource was blocked." | ||
exit 0 | ||
fi |
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: v1 | ||
kind: Pod | ||
metadata: | ||
name: webserver |
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,29 @@ | ||
apiVersion: kyverno.io/v1 | ||
kind: ClusterPolicy | ||
metadata: | ||
name: propagate-cost-labels-from-namespace | ||
spec: | ||
failurePolicy: Ignore | ||
rules: | ||
- name: add-cost-labels | ||
context: | ||
- name: namespaceLabels | ||
apiCall: | ||
urlPath: "/api/v1/namespaces/{{request.namespace}}" | ||
jmesPath: metadata.labels | ||
match: | ||
any: | ||
- resources: | ||
kinds: | ||
- Pod | ||
- Deployment | ||
- StatefulSet | ||
- DaemonSet | ||
- Job | ||
- CronJob | ||
mutate: | ||
patchStrategicMerge: | ||
metadata: | ||
labels: | ||
cost.starfleet.evtech/project: "{{namespaceLabels.\"cost.starfleet.evtech/project\" || 'empty'}}" | ||
cost.starfleet.evtech/application: "{{request.object.metadata.labels.\"cost.starfleet.evtech/application\" || namespaceLabels.\"cost.starfleet.evtech/application\" || 'empty'}}" |
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,7 @@ | ||
apiVersion: v1 | ||
kind: Pod | ||
metadata: | ||
name: webserver | ||
labels: | ||
cost.starfleet.evtech/project: empty | ||
cost.starfleet.evtech/application: empty |
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,10 @@ | ||
apiVersion: v1 | ||
kind: Pod | ||
metadata: | ||
name: webserver | ||
spec: | ||
containers: | ||
- name: webserver | ||
image: nginx:latest | ||
ports: | ||
- containerPort: 80 |
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: kuttl.dev/v1beta1 | ||
kind: TestStep | ||
commands: | ||
- command: kubectl delete -f 01-manifests.yaml,resource.yaml,05-pod.yaml --force --wait=true --ignore-not-found=true |
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,10 @@ | ||
apiVersion: v1 | ||
kind: Pod | ||
metadata: | ||
name: webserver | ||
spec: | ||
containers: | ||
- name: webserver | ||
image: nginx:latest | ||
ports: | ||
- containerPort: 80 |