fix: consider policy's namespace as well while report rule results to policyreports
@@ -45,11 +45,15 @@ func (pc *PolicyController) processExistingResources(policy *kyverno.ClusterPoli
namespaces := pc.getNamespacesForRule(&rule, logger.WithValues("kind", k))
for _, ns := range namespaces {
+ // for kind: Policy, consider only the namespace which the policy belongs to.
+ // for kind: ClusterPolicy, consider all the namespaces.
+ if policy.Namespace == ns || policy.Namespace == "" {
pc.applyAndReportPerNamespace(policy, k, ns, rule, logger.WithValues("kind", k).WithValues("ns", ns))
}
}
}
}
+}
func (pc *PolicyController) registerResource(gvk string) (err error) {
genericCache, ok := pc.resCache.GetGVRCache(gvk)
