Skip to content

Commit

Permalink
Fix Resource information in Violation E-Mail Reports (#411)
Browse files Browse the repository at this point in the history
Signed-off-by: Frank Jogeleit <[email protected]>
  • Loading branch information
fjogeleit authored Feb 21, 2024
1 parent 661cbb2 commit c295800
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
4 changes: 2 additions & 2 deletions pkg/email/violations/generator.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ func (o *Generator) GenerateData(ctx context.Context) ([]Source, error) {
continue
}

s.AddClusterResults(mapResult(result))
s.AddClusterResults(mapResult(&report, result))
}
}(rep)
}
Expand Down Expand Up @@ -117,7 +117,7 @@ func (o *Generator) GenerateData(ctx context.Context) ([]Source, error) {
if result.Result == v1alpha2.StatusPass || result.Result == v1alpha2.StatusSkip {
continue
}
s.AddNamespacedResults(report.Namespace, mapResult(result))
s.AddNamespacedResults(report.Namespace, mapResult(&report, result))
}
}(rep)
}
Expand Down
12 changes: 10 additions & 2 deletions pkg/email/violations/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,27 @@ type Result struct {
Status string
}

func mapResult(res v1alpha2.PolicyReportResult) []Result {
func mapResult(polr v1alpha2.ReportInterface, res v1alpha2.PolicyReportResult) []Result {
count := len(res.Resources)
rule := res.Rule
if rule == "" {
rule = res.Message
}

if count == 0 {
if count == 0 && polr.GetScope() == nil {
return []Result{{
Policy: res.Policy,
Rule: rule,
Status: string(res.Result),
}}
} else if count == 0 && polr.GetScope() != nil {
return []Result{{
Policy: res.Policy,
Rule: rule,
Name: polr.GetScope().Name,
Kind: polr.GetScope().Kind,
Status: string(res.Result),
}}
}

list := make([]Result, 0, count)
Expand Down

0 comments on commit c295800

Please sign in to comment.