Skip to content

Commit

Permalink
🐛 Do not generate violations when there are no incidents (konveyor#281)
Browse files Browse the repository at this point in the history
Closes konveyor#278

---------

Signed-off-by: Parthiba-Hazra <parthibahazra02@gmail.com>
  • Loading branch information
Parthiba-Hazra authored Aug 10, 2023
1 parent c97c18c commit fba062e
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
2 changes: 1 addition & 1 deletion engine/engine.go
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ func (r *ruleEngine) RunRules(ctx context.Context, ruleSets []RuleSet, selectors
if rs, ok := mapRuleSets[response.RuleSetName]; ok {
rs.Errors[response.Rule.RuleID] = response.Err.Error()
}
} else if response.ConditionResponse.Matched {
} else if response.ConditionResponse.Matched && len(response.ConditionResponse.Incidents) > 0 {
violation, err := r.createViolation(response.ConditionResponse, response.Rule)
if err != nil {
r.logger.Error(err, "unable to create violation from response")
Expand Down
12 changes: 12 additions & 0 deletions provider/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -431,13 +431,25 @@ func (p *ProviderCondition) Evaluate(ctx context.Context, log logr.Logger, condC
}
incidents = append(incidents, i)
}

// If there are no incidents, don't generate any violations
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{
Matched: resp.Matched,
}, nil
}

cr := engine.ConditionResponse{
Matched: resp.Matched,
TemplateContext: resp.TemplateContext,
Incidents: incidents,
}

log.V(8).Info("condition response", "ruleID", p.Rule.RuleID, "response", cr, "cap", p.Capability, "conditionInfo", p.ConditionInfo, "client", p.Client)
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 fba062e

Please sign in to comment.