mirror of
https://github.com/kyverno/kyverno.git
synced 2025-03-28 18:38:40 +00:00
Fix: not showing error during policy validation error (#9533)
* Update result.go Signed-off-by: mohamedasifs123 <142201466+mohamedasifs123@users.noreply.github.com> * Update command.go to call function policyvalerror Signed-off-by: mohamedasifs123 <142201466+mohamedasifs123@users.noreply.github.com> * Update cmd/cli/kubectl-kyverno/processor/result.go Signed-off-by: Charles-Edouard Brétéché <charles.edouard@nirmata.com> * Update cmd/cli/kubectl-kyverno/commands/apply/command.go Signed-off-by: Charles-Edouard Brétéché <charles.edouard@nirmata.com> * nit Signed-off-by: Charles-Edouard Brétéché <charles.edouard@nirmata.com> --------- Signed-off-by: mohamedasifs123 <142201466+mohamedasifs123@users.noreply.github.com> Signed-off-by: Charles-Edouard Brétéché <charles.edouard@nirmata.com> Co-authored-by: Charles-Edouard Brétéché <charles.edouard@nirmata.com>
This commit is contained in:
parent
e3274386e7
commit
1e6f827f42
2 changed files with 6 additions and 1 deletions
|
@ -237,6 +237,7 @@ func (c *ApplyCommandConfig) applyPolicytoResource(
|
|||
if vars != nil {
|
||||
vars.SetInStore(store)
|
||||
}
|
||||
var rc processor.ResultCounts
|
||||
// validate policies
|
||||
var validPolicies []kyvernov1.PolicyInterface
|
||||
for _, pol := range policies {
|
||||
|
@ -244,6 +245,7 @@ func (c *ApplyCommandConfig) applyPolicytoResource(
|
|||
_, err := policyvalidation.Validate(pol, nil, nil, true, config.KyvernoUserName(config.KyvernoServiceAccountName()))
|
||||
if err != nil {
|
||||
log.Log.Error(err, "policy validation error")
|
||||
rc.IncrementError(1)
|
||||
if strings.HasPrefix(err.Error(), "variable 'element.name'") {
|
||||
skipInvalidPolicies.invalid = append(skipInvalidPolicies.invalid, pol.GetName())
|
||||
} else {
|
||||
|
@ -254,7 +256,6 @@ func (c *ApplyCommandConfig) applyPolicytoResource(
|
|||
validPolicies = append(validPolicies, pol)
|
||||
}
|
||||
|
||||
var rc processor.ResultCounts
|
||||
var responses []engineapi.EngineResponse
|
||||
for _, resource := range resources {
|
||||
processor := processor.PolicyProcessor{
|
||||
|
|
|
@ -21,6 +21,10 @@ func (rc ResultCounts) Warn() int { return rc.warn }
|
|||
func (rc ResultCounts) Error() int { return rc.err }
|
||||
func (rc ResultCounts) Skip() int { return rc.skip }
|
||||
|
||||
func (rc *ResultCounts) IncrementError(inc int) {
|
||||
rc.err += inc
|
||||
}
|
||||
|
||||
func (rc *ResultCounts) addEngineResponses(auditWarn bool, responses ...engineapi.EngineResponse) {
|
||||
for _, response := range responses {
|
||||
rc.addEngineResponse(auditWarn, response)
|
||||
|
|
Loading…
Add table
Reference in a new issue