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

bugfix - delete synchronized resources (#997)

* Delete individual resource when policy deleted

Co-authored-by: evalsocket <yuvraj.yad001@gmail.com>
This commit is contained in:
shuting 2020-07-15 10:39:02 -07:00 committed by GitHub
parent bfaeefafd3
commit 55d5812404
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -47,11 +47,17 @@ func (c *Controller) applyGenerate(resource unstructured.Unstructured, gr kyvern
policy, err := c.pLister.Get(gr.Spec.Policy)
if err != nil {
if apierrors.IsNotFound(err) {
labels := resource.GetLabels()
if labels["app.kubernetes.io/synchronize"] == "enable" {
if err := c.client.DeleteResource(gr.Spec.Resource.Kind, gr.Spec.Resource.Namespace, gr.Spec.Resource.Name, false); err != nil {
logger.V(4).Info("Generated resource is deleted")
return nil, err
for _,e := range gr.Status.GeneratedResources {
resp, err := c.client.GetResource(e.Kind,e.Namespace,e.Name);
if err != nil {
logger.Error(err,"Generated resource failed to get","Resource",resp.GetName())
}
labels := resp.GetLabels()
if labels["app.kubernetes.io/synchronize"] == "enable" {
if err := c.client.DeleteResource(resp.GetKind(), resp.GetNamespace(), resp.GetName(), false); err != nil {
logger.Error(err,"Generated resource is not deleted","Resource",resp.GetName())
}
}
}
return nil, nil