forked from kyverno/kyverno
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Bug] [CLI] Restore warn-exit-code functionality for apply command (k…
…yverno#9828) (kyverno#9833) * Restore warn-exite-code functionality for apply command * Nove error handling * Uncomment println statement * Fixing linting * Adding conformance tets for cli apply command with warn-exit-code * Update path to kubectl-kyverno binary * Add prepare-cli as needed dependency * feat: install kubectl-kyverno in standard conformance tests * fix: update chainsaw config * fix: move CLI chainsaw tests to a separate action * fix: CLI path * fix: name * fix: add chainsaw flag '--no-cluster' * fix: CLI name --------- Signed-off-by: Matt Veitas <[email protected]> Signed-off-by: ShutingZhao <[email protected]> Signed-off-by: shuting <[email protected]> Co-authored-by: Matt Veitas <[email protected]>
- Loading branch information
1 parent
652f354
commit d91c2cf
Showing
9 changed files
with
179 additions
and
7 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
28 changes: 28 additions & 0 deletions
28
cmd/cli/kubectl-kyverno/_testdata/apply/test-2/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,28 @@ | ||
apiVersion: kyverno.io/v1 | ||
kind: ClusterPolicy | ||
metadata: | ||
name: test-policy | ||
annotations: | ||
policies.kyverno.io/title: "Lol Security Standards" | ||
policies.kyverno.io/category: "Lol Security Standards" | ||
policies.kyverno.io/severity: "high" | ||
policies.kyverno.io/subject: "Pod" | ||
spec: | ||
background: true | ||
failurePolicy: Fail | ||
rules: | ||
- name: restrict-lol-annotation | ||
match: | ||
any: | ||
- resources: | ||
kinds: | ||
- Pod | ||
validate: | ||
message: >- | ||
If "lol" annotation is present then | ||
its value can be only one of "such lol", "much annotation". | ||
pattern: | ||
# syntax refdoc: https://kyverno.io/docs/writing-policies/validate/#anchors | ||
=(metadata): | ||
=(annotations): | ||
=(lol): such lol | much annotation |
20 changes: 20 additions & 0 deletions
20
cmd/cli/kubectl-kyverno/_testdata/apply/test-2/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,20 @@ | ||
apiVersion: apps/v1 | ||
kind: Deployment | ||
metadata: | ||
labels: | ||
app: lol | ||
name: i-will-fail-the-policy-check | ||
spec: | ||
selector: | ||
matchLabels: | ||
app: lol | ||
template: | ||
metadata: | ||
labels: | ||
app: lol | ||
annotations: | ||
lol: not much | ||
spec: | ||
containers: | ||
- image: woot | ||
name: woot |
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
12 changes: 12 additions & 0 deletions
12
test/conformance/chainsaw/cli/apply/warn-exit-code/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,12 @@ | ||
apiVersion: chainsaw.kyverno.io/v1alpha1 | ||
kind: Test | ||
metadata: | ||
name: test-name | ||
spec: | ||
steps: | ||
- try: | ||
- script: | ||
content: | | ||
kyverno apply policy.yaml --resource resource.yaml --audit-warn --warn-exit-code 3 | ||
check: | ||
($error): "exit status 3" |
28 changes: 28 additions & 0 deletions
28
test/conformance/chainsaw/cli/apply/warn-exit-code/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,28 @@ | ||
apiVersion: kyverno.io/v1 | ||
kind: ClusterPolicy | ||
metadata: | ||
name: test-policy | ||
annotations: | ||
policies.kyverno.io/title: "Lol Security Standards" | ||
policies.kyverno.io/category: "Lol Security Standards" | ||
policies.kyverno.io/severity: "high" | ||
policies.kyverno.io/subject: "Pod" | ||
spec: | ||
background: true | ||
failurePolicy: Fail | ||
rules: | ||
- name: restrict-lol-annotation | ||
match: | ||
any: | ||
- resources: | ||
kinds: | ||
- Pod | ||
validate: | ||
message: >- | ||
If "lol" annotation is present then | ||
its value can be only one of "such lol", "much annotation". | ||
pattern: | ||
# syntax refdoc: https://kyverno.io/docs/writing-policies/validate/#anchors | ||
=(metadata): | ||
=(annotations): | ||
=(lol): such lol | much annotation |
20 changes: 20 additions & 0 deletions
20
test/conformance/chainsaw/cli/apply/warn-exit-code/resource.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,20 @@ | ||
apiVersion: apps/v1 | ||
kind: Deployment | ||
metadata: | ||
labels: | ||
app: lol | ||
name: i-will-fail-the-policy-check | ||
spec: | ||
selector: | ||
matchLabels: | ||
app: lol | ||
template: | ||
metadata: | ||
labels: | ||
app: lol | ||
annotations: | ||
lol: not much | ||
spec: | ||
containers: | ||
- image: woot | ||
name: woot |