From 04ecfd3998a8fa0ced87a157bfbca0ade46391ff Mon Sep 17 00:00:00 2001 From: evalsocket Date: Fri, 10 Jul 2020 17:06:16 -0700 Subject: [PATCH] delete if sync is true --- pkg/generate/generate.go | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/pkg/generate/generate.go b/pkg/generate/generate.go index f8816bd1ed..267a62d34d 100644 --- a/pkg/generate/generate.go +++ b/pkg/generate/generate.go @@ -47,10 +47,15 @@ func (c *Controller) applyGenerate(resource unstructured.Unstructured, gr kyvern policy, err := c.pLister.Get(gr.Spec.Policy) if err != nil { if apierrors.IsNotFound(err) { - 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 policy.Spec.Rules { + if e.Generation.Synchronize { + if err := c.client.DeleteResource(e.Generation.Kind, e.Generation.Namespace, e.Generation.Name, false); err != nil { + logger.V(4).Info("Generated resource is deleted") + return nil, err + } + } } + return nil, nil } logger.Error(err, "error in getting policy")