mirror of
https://github.com/kyverno/kyverno.git
synced 2025-03-31 03:45:17 +00:00
fix delete logic
This commit is contained in:
parent
04ecfd3998
commit
98fa10ea59
1 changed files with 11 additions and 7 deletions
|
@ -47,18 +47,22 @@ func (c *Controller) applyGenerate(resource unstructured.Unstructured, gr kyvern
|
|||
policy, err := c.pLister.Get(gr.Spec.Policy)
|
||||
if err != nil {
|
||||
if apierrors.IsNotFound(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
|
||||
}
|
||||
resource, err := c.client.GetResource(gr.Spec.Resource.Kind, gr.Spec.Resource.Namespace, gr.Spec.Resource.Name)
|
||||
if err != nil {
|
||||
logger.V(4).Info("Generated resource is deleted")
|
||||
return nil, 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
|
||||
}
|
||||
}
|
||||
|
||||
return nil, nil
|
||||
}
|
||||
logger.Error(err, "error in getting policy")
|
||||
return nil, err
|
||||
}
|
||||
|
||||
resourceRaw, err := resource.MarshalJSON()
|
||||
|
|
Loading…
Add table
Reference in a new issue