diff --git a/pkg/email/violations/generator.go b/pkg/email/violations/generator.go index 5122193f..0aae6afc 100644 --- a/pkg/email/violations/generator.go +++ b/pkg/email/violations/generator.go @@ -68,7 +68,7 @@ func (o *Generator) GenerateData(ctx context.Context) ([]Source, error) { continue } - s.AddClusterResults(mapResult(result)) + s.AddClusterResults(mapResult(&report, result)) } }(rep) } @@ -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) } diff --git a/pkg/email/violations/model.go b/pkg/email/violations/model.go index a4522c64..93e31eb8 100644 --- a/pkg/email/violations/model.go +++ b/pkg/email/violations/model.go @@ -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)