1
0
Fork 0
mirror of https://github.com/kyverno/kyverno.git synced 2025-04-18 02:06:52 +00:00

replace deletion timestamp check ()

This commit is contained in:
Jim Bugwadia 2020-06-30 23:30:31 -07:00 committed by GitHub
parent 65193feccb
commit 05250c2870
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 9 additions and 3 deletions

View file

@ -15,12 +15,11 @@ func (pc *PolicyController) addClusterPolicyViolation(obj interface{}) {
pc.deleteClusterPolicyViolation(pv)
return
}
// dont manage controller references as the ownerReference is assigned by violation generator
ps := pc.getPolicyForClusterPolicyViolation(pv)
if len(ps) == 0 {
// there is no cluster policy for this violation, so we can delete this cluster policy violation
logger.V(4).Info("Cluster Policy Violation does not belong to an active policy, will be cleanedup")
logger.V(4).Info("Cluster Policy Violation does not belong to an active policy, will be cleaned up")
if err := pc.pvControl.DeleteClusterPolicyViolation(pv.Name); err != nil {
logger.Error(err, "failed to delete resource")
return

View file

@ -10,10 +10,17 @@ func (pc *PolicyController) addNamespacedPolicyViolation(obj interface{}) {
pv := obj.(*kyverno.PolicyViolation)
logger := pc.log.WithValues("kind", pv.GetObjectKind(), "namespace", pv.Namespace, "name", pv.Name)
if pv.DeletionTimestamp != nil {
// On a restart of the controller manager, it's possible for an object to
// show up in a state that is already pending deletion.
pc.deleteNamespacedPolicyViolation(pv)
return
}
ps := pc.getPolicyForNamespacedPolicyViolation(pv)
if len(ps) == 0 {
// there is no cluster policy for this violation, so we can delete this cluster policy violation
logger.V(4).Info("namepaced policy violation does not belong to an active policy, will be cleanedup")
logger.V(4).Info("namespaced policy violation does not belong to an active policy, will be cleaned up")
if err := pc.pvControl.DeleteNamespacedPolicyViolation(pv.Namespace, pv.Name); err != nil {
logger.Error(err, "failed to delete resource")
return