From 03c41e77462b1ec2e881ae0e39cd13befb62e3bc Mon Sep 17 00:00:00 2001 From: XDRAGON2002 <81813720+XDRAGON2002@users.noreply.github.com> Date: Thu, 13 Oct 2022 14:02:20 +0530 Subject: [PATCH] [Cleanup] Disable PolicySkipped events (#4913) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * remove skip events Signed-off-by: Anant Vijay * update conditions Signed-off-by: Anant Vijay * improve conditions Signed-off-by: Anant Vijay * remove redundant function Signed-off-by: Anant Vijay Signed-off-by: Anant Vijay Co-authored-by: Charles-Edouard Brétéché --- pkg/event/events.go | 20 -------------------- pkg/policy/report.go | 7 +------ pkg/webhooks/utils/event.go | 13 +++---------- 3 files changed, 4 insertions(+), 36 deletions(-) diff --git a/pkg/event/events.go b/pkg/event/events.go index 4742176c71..dd37fa73a0 100644 --- a/pkg/event/events.go +++ b/pkg/event/events.go @@ -89,26 +89,6 @@ func NewResourceViolationEvent(source Source, reason Reason, engineResponse *res } } -func NewPolicySkippedEvent(source Source, reason Reason, engineResponse *response.EngineResponse, ruleResp *response.RuleResponse) Info { - var bldr strings.Builder - defer bldr.Reset() - resource := engineResponse.GetResourceSpec() - - if resource.Namespace != "" { - fmt.Fprintf(&bldr, "%s %s/%s: %s", resource.Kind, resource.Namespace, resource.Name, ruleResp.Status.String()) - } else { - fmt.Fprintf(&bldr, "%s %s: %s", resource.Kind, resource.Name, ruleResp.Status.String()) - } - return Info{ - Kind: getPolicyKind(engineResponse.Policy), - Name: engineResponse.PolicyResponse.Policy.Name, - Namespace: engineResponse.PolicyResponse.Policy.Namespace, - Reason: PolicySkipped.String(), - Source: source, - Message: bldr.String(), - } -} - func NewBackgroundFailedEvent(err error, policy, rule string, source Source, r *unstructured.Unstructured) []Info { if r == nil { return nil diff --git a/pkg/policy/report.go b/pkg/policy/report.go index 4731752b69..1ae0a6ec38 100644 --- a/pkg/policy/report.go +++ b/pkg/policy/report.go @@ -89,12 +89,7 @@ func generateFailEventsPerEr(log logr.Logger, er *response.EngineResponse) []eve "name", er.PolicyResponse.Resource.Name) for i, rule := range er.PolicyResponse.Rules { - if rule.Status == response.RuleStatusPass { - continue - } else if rule.Status == response.RuleStatusSkip { - eventResource := event.NewPolicySkippedEvent(event.PolicyController, event.PolicySkipped, er, &er.PolicyResponse.Rules[i]) - eventInfos = append(eventInfos, eventResource) - } else { + if rule.Status != response.RuleStatusPass && rule.Status != response.RuleStatusSkip { eventResource := event.NewResourceViolationEvent(event.PolicyController, event.PolicyViolation, er, &er.PolicyResponse.Rules[i]) eventInfos = append(eventInfos, eventResource) diff --git a/pkg/webhooks/utils/event.go b/pkg/webhooks/utils/event.go index c673f24053..3395bbc4b8 100644 --- a/pkg/webhooks/utils/event.go +++ b/pkg/webhooks/utils/event.go @@ -30,16 +30,9 @@ func GenerateEvents(engineResponses []*response.EngineResponse, blocked bool) [] events = append(events, e) } } - } else { - if er.IsSkipped() { - for i := range er.PolicyResponse.Rules { - e := event.NewPolicySkippedEvent(event.AdmissionController, event.PolicySkipped, er, &er.PolicyResponse.Rules[i]) - events = append(events, e) - } - } else { - e := event.NewPolicyAppliedEvent(event.AdmissionController, er) - events = append(events, e) - } + } else if !er.IsSkipped() { + e := event.NewPolicyAppliedEvent(event.AdmissionController, er) + events = append(events, e) } }