Skip to content

Commit

Permalink
fix resource details in compliance report
Browse files Browse the repository at this point in the history
Signed-off-by: Frank Jogeleit <[email protected]>
  • Loading branch information
Frank Jogeleit committed Jan 19, 2024
1 parent e31a162 commit 6cfa71c
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion pkg/reporting/policy_report.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"strings"

"golang.org/x/exp/slices"
corev1 "k8s.io/api/core/v1"

v1 "github.com/kyverno/policy-reporter-kyverno-plugin/pkg/crd/api/kyverno/v1"
"github.com/kyverno/policy-reporter-kyverno-plugin/pkg/crd/api/policyreport/v1alpha2"
Expand Down Expand Up @@ -115,6 +116,8 @@ func (g *policyReportGenerator) PerPolicyData(ctx context.Context, filter Filter

if len(result.Resources) > 0 {
val.Groups[polr.GetNamespace()].Rules[rule].Resources = append(val.Groups[polr.GetNamespace()].Rules[rule].Resources, mapResource(result))
} else if polr.GetScope() != nil {
val.Groups[polr.GetNamespace()].Rules[rule].Resources = append(val.Groups[polr.GetNamespace()].Rules[rule].Resources, mapScope(result.Result, polr.GetScope()))
}

increaseSummary(result.Result, val.Groups[polr.GetNamespace()].Rules[rule].Summary)
Expand Down Expand Up @@ -238,11 +241,12 @@ func (g *policyReportGenerator) PerNamespaceData(ctx context.Context, filter Fil

if len(result.Resources) > 0 {
ruleObj.Resources = append(ruleObj.Resources, mapResource(result))
} else if polr.GetScope() != nil {
ruleObj.Resources = append(ruleObj.Resources, mapScope(result.Result, polr.GetScope()))
}

increaseSummary(result.Result, ruleObj.Summary)
increaseSummary(result.Result, val.Groups[result.Policy].Summary)

}
}

Expand Down Expand Up @@ -319,6 +323,15 @@ func mapResource(result v1alpha2.PolicyReportResult) *Resource {
}
}

func mapScope(result v1alpha2.PolicyResult, resource *corev1.ObjectReference) *Resource {
return &Resource{
Kind: resource.Kind,
APIVersion: resource.APIVersion,
Name: resource.Name,
Status: string(result),
}
}

func mapPolicy(pol v1.Policy) *Policy {
v := &Policy{
Title: pol.Annotations[titleAnnotation],
Expand Down

0 comments on commit 6cfa71c

Please sign in to comment.