1
0
Fork 0
mirror of https://github.com/kyverno/kyverno.git synced 2025-03-31 03:45:17 +00:00

527 skippings stats for sync pv

This commit is contained in:
shravan 2020-02-26 00:26:09 +05:30
parent d0217a3faf
commit 157694b4fd
4 changed files with 22 additions and 4 deletions

View file

@ -18,6 +18,10 @@ func (pc *PolicyController) cleanupAndReport(engineResponses []response.EngineRe
pc.eventGen.Add(eventInfos...)
// create policy violation
pvInfos := policyviolation.GeneratePVsFromEngineResponse(engineResponses)
for i := range pvInfos {
pvInfos[i].FromSync = true
}
pc.pvGenerator.Add(pvInfos...)
// cleanup existing violations if any
// if there is any error in clean up, we dont re-queue the resource

View file

@ -99,7 +99,10 @@ func (cpv *clusterPV) createPV(newPv *kyverno.ClusterPolicyViolation) error {
return err
}
go cpv.policyStatus.UpdatePolicyStatusWithViolationCount(newPv.Spec.Policy, newPv.Spec.ViolatedRules)
if newPv.Annotations["fromSync"] != "true" {
go cpv.policyStatus.UpdatePolicyStatusWithViolationCount(newPv.Spec.Policy, newPv.Spec.ViolatedRules)
}
glog.Infof("policy violation created for resource %v", newPv.Spec.ResourceSpec)
return nil
}
@ -122,6 +125,8 @@ func (cpv *clusterPV) updatePV(newPv, oldPv *kyverno.ClusterPolicyViolation) err
}
glog.Infof("cluster policy violation updated for resource %v", newPv.Spec.ResourceSpec)
go cpv.policyStatus.UpdatePolicyStatusWithViolationCount(newPv.Spec.Policy, newPv.Spec.ViolatedRules)
if newPv.Annotations["fromSync"] != "true" {
go cpv.policyStatus.UpdatePolicyStatusWithViolationCount(newPv.Spec.Policy, newPv.Spec.ViolatedRules)
}
return nil
}

View file

@ -81,6 +81,7 @@ type Info struct {
PolicyName string
Resource unstructured.Unstructured
Rules []kyverno.ViolatedRule
FromSync bool
}
func (i Info) toKey() string {
@ -232,6 +233,10 @@ func (gen *Generator) syncHandler(info Info) error {
failure := false
pv := builder.generate(info)
if info.FromSync {
pv.Annotations["fromSync"] = "true"
}
// Create Policy Violations
glog.V(3).Infof("Creating policy violation: %s", info.toKey())
if err := handler.create(pv); err != nil {

View file

@ -98,7 +98,9 @@ func (nspv *namespacedPV) createPV(newPv *kyverno.PolicyViolation) error {
return err
}
go nspv.policyStatus.UpdatePolicyStatusWithViolationCount(newPv.Spec.Policy, newPv.Spec.ViolatedRules)
if newPv.Annotations["fromSync"] != "true" {
go nspv.policyStatus.UpdatePolicyStatusWithViolationCount(newPv.Spec.Policy, newPv.Spec.ViolatedRules)
}
glog.Infof("policy violation created for resource %v", newPv.Spec.ResourceSpec)
return nil
}
@ -119,7 +121,9 @@ func (nspv *namespacedPV) updatePV(newPv, oldPv *kyverno.PolicyViolation) error
return fmt.Errorf("failed to update namespaced policy violation: %v", err)
}
go nspv.policyStatus.UpdatePolicyStatusWithViolationCount(newPv.Spec.Policy, newPv.Spec.ViolatedRules)
if newPv.Annotations["fromSync"] != "true" {
go nspv.policyStatus.UpdatePolicyStatusWithViolationCount(newPv.Spec.Policy, newPv.Spec.ViolatedRules)
}
glog.Infof("namespaced policy violation updated for resource %v", newPv.Spec.ResourceSpec)
return nil
}