From 3501cde249e12a5b96c30e60bbe204cce9c02baa Mon Sep 17 00:00:00 2001 From: "gcp-cherry-pick-bot[bot]" <98988430+gcp-cherry-pick-bot[bot]@users.noreply.github.com> Date: Tue, 26 Dec 2023 22:26:44 +0100 Subject: [PATCH] fix: remove skip increment when resource not found in cli apply (#9282) (#9284) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * fix: remove skip increment when resource not found in cli apply * fix test --------- Signed-off-by: Charles-Edouard Brétéché Co-authored-by: Charles-Edouard Brétéché --- .../processor/policy_processor_test.go | 4 ++-- cmd/cli/kubectl-kyverno/processor/result.go | 15 --------------- 2 files changed, 2 insertions(+), 17 deletions(-) diff --git a/cmd/cli/kubectl-kyverno/processor/policy_processor_test.go b/cmd/cli/kubectl-kyverno/processor/policy_processor_test.go index 60f7ba6fb1..92f98b774b 100644 --- a/cmd/cli/kubectl-kyverno/processor/policy_processor_test.go +++ b/cmd/cli/kubectl-kyverno/processor/policy_processor_test.go @@ -82,7 +82,7 @@ func Test_NamespaceSelector(t *testing.T) { fail: 1, warn: 0, err: 0, - skip: 2, + skip: 0, }, }, { @@ -98,7 +98,7 @@ func Test_NamespaceSelector(t *testing.T) { fail: 1, warn: 0, err: 0, - skip: 4, + skip: 0, }, }, } diff --git a/cmd/cli/kubectl-kyverno/processor/result.go b/cmd/cli/kubectl-kyverno/processor/result.go index c49d6c2667..06f2f5510b 100644 --- a/cmd/cli/kubectl-kyverno/processor/result.go +++ b/cmd/cli/kubectl-kyverno/processor/result.go @@ -38,10 +38,8 @@ func (rc *ResultCounts) addEngineResponse(auditWarn bool, response engineapi.Eng scored := annotations.Scored(policy.GetAnnotations()) for _, rule := range autogen.ComputeRules(policy) { if rule.HasValidate() || rule.HasVerifyImageChecks() || rule.HasVerifyImages() { - ruleFoundInEngineResponse := false for _, valResponseRule := range response.PolicyResponse.Rules { if rule.Name == valResponseRule.Name() { - ruleFoundInEngineResponse = true switch valResponseRule.Status() { case engineapi.RuleStatusPass: rc.pass++ @@ -64,9 +62,6 @@ func (rc *ResultCounts) addEngineResponse(auditWarn bool, response engineapi.Eng continue } } - if !ruleFoundInEngineResponse { - rc.skip++ - } } } } @@ -79,10 +74,8 @@ func (rc *ResultCounts) addGenerateResponse(auditWarn bool, resPath string, resp } policy := genericPolicy.GetPolicy().(kyvernov1.PolicyInterface) for _, policyRule := range autogen.ComputeRules(policy) { - ruleFoundInEngineResponse := false for _, ruleResponse := range response.PolicyResponse.Rules { if policyRule.Name == ruleResponse.Name() { - ruleFoundInEngineResponse = true if ruleResponse.Status() == engineapi.RuleStatusPass { rc.pass++ } else { @@ -95,9 +88,6 @@ func (rc *ResultCounts) addGenerateResponse(auditWarn bool, resPath string, resp continue } } - if !ruleFoundInEngineResponse { - rc.skip++ - } } } @@ -118,10 +108,8 @@ func (rc *ResultCounts) addMutateResponse(resourcePath string, response engineap } printMutatedRes := false for _, policyRule := range autogen.ComputeRules(policy) { - ruleFoundInEngineResponse := false for _, mutateResponseRule := range response.PolicyResponse.Rules { if policyRule.Name == mutateResponseRule.Name() { - ruleFoundInEngineResponse = true if mutateResponseRule.Status() == engineapi.RuleStatusPass { rc.pass++ printMutatedRes = true @@ -135,9 +123,6 @@ func (rc *ResultCounts) addMutateResponse(resourcePath string, response engineap continue } } - if !ruleFoundInEngineResponse { - rc.skip++ - } } return printMutatedRes }