Skip to content

Commit

Permalink
Do not generate violations when there are no incidents
Browse files Browse the repository at this point in the history
Signed-off-by: Parthiba-Hazra <[email protected]>
  • Loading branch information
Parthiba-Hazra committed Aug 2, 2023
1 parent ff6c243 commit 7e49d7f
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions provider/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -401,14 +401,12 @@ func (p *ProviderCondition) Evaluate(ctx context.Context, log logr.Logger, condC
}

incidents := []engine.IncidentContext{}
filteredOutCount := 0 // Counter to track incidents filtered out
for _, inc := range resp.Incidents {
// filter out incidents that don't match the dep label selector
if matched, err := matchDepLabelSelector(p.DepLabelSelector, inc, deps); err != nil {
log.V(5).Error(err, "failed to match dep label selector")
return engine.ConditionResponse{}, err
} else if !matched {
filteredOutCount++
continue
}
i := engine.IncidentContext{
Expand All @@ -435,8 +433,8 @@ func (p *ProviderCondition) Evaluate(ctx context.Context, log logr.Logger, condC
}

// If there are no incidents, don't generate any violations
if len(incidents) == 0 {
log.V(3).Info("filtered out all incidents based on dep label selector", "filteredOutCount: ", filteredOutCount)
if len(incidents) == 0 && len(resp.Incidents)-len(incidents) > 0 {
log.V(5).Info("filtered out all incidents based on dep label selector", "filteredOutCount", len(resp.Incidents)-len(incidents))
return engine.ConditionResponse{}, nil
}

Expand All @@ -447,7 +445,9 @@ func (p *ProviderCondition) Evaluate(ctx context.Context, log logr.Logger, condC
}

log.V(8).Info("condition response", "ruleID", p.Rule.RuleID, "response", cr, "cap", p.Capability, "conditionInfo", p.ConditionInfo, "client", p.Client)
log.V(3).Info("filtered out incidents based on dep label selector", "filteredOutCount: ", filteredOutCount)
if len(resp.Incidents)-len(incidents) > 0 {
log.V(5).Info("filtered out incidents based on dep label selector", "filteredOutCount", len(resp.Incidents)-len(incidents))
}
return cr, nil

}
Expand Down

0 comments on commit 7e49d7f

Please sign in to comment.