Skip to content

Commit

Permalink
Fix issue where CLI test command ignores failures (kyverno#5189)
Browse files Browse the repository at this point in the history
Closes kyverno#5187

The test command was resetting the return value to "pass", even if it
was already marked failed, in some cases. This solves by moving the
"pass" into an else-if clause.

Signed-off-by: Eric Miller <eric.miller@instructure.com>

Signed-off-by: Eric Miller <eric.miller@instructure.com>
Co-authored-by: Vyankatesh Kudtarkar <vyankateshkd@gmail.com>
Co-authored-by: shuting <shuting@nirmata.com>
  • Loading branch information
3 people authored Nov 11, 2022
1 parent 6091af6 commit 001db94
Showing 1 changed file with 3 additions and 5 deletions.
8 changes: 3 additions & 5 deletions cmd/cli/kubectl-kyverno/test/test_command.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ applying 1 policy to 2 resources...
kyverno test .
Executing limit-containers-per-pod...
applying 1 policy to 4 resources...
applying 1 policy to 4 resources...
│───│──────────────────────────│──────────────────────────────────────│─────────────────────────────│────────│
│ # │ POLICY │ RULE │ RESOURCE │ RESULT │
Expand All @@ -84,7 +84,7 @@ Test Summary: 4 tests passed and 0 tests failed
kyverno test . --test-case-selector "policy=disallow-latest-tag, rule=require-image-tag, resource=test-require-image-tag-pass"
Executing test-simple...
applying 1 policy to 1 resource...
applying 1 policy to 1 resource...
│───│─────────────────────│───────────────────│─────────────────────────────────────────│────────│
│ # │ POLICY │ RULE │ RESOURCE │ RESULT │
Expand Down Expand Up @@ -787,9 +787,7 @@ func getAndCompareResource(path string, engineResource unstructured.Unstructured
if err != nil {
log.Log.V(3).Info(resourceType+" mismatch", "error", err.Error())
status = "fail"
}

if matched == "" {
} else if matched == "" {
status = "pass"
}
return status
Expand Down

0 comments on commit 001db94

Please sign in to comment.