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:
parent
bfaeefafd3
commit
55d5812404
1 changed files with 11 additions and 5 deletions
|
@ -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
|
||||
|
|
Loading…
Add table
Reference in a new issue