From 09773d15e1a65b658b3da2de61c36549b8600fef Mon Sep 17 00:00:00 2001 From: Furkan Date: Thu, 19 Sep 2024 13:28:15 +0300 Subject: [PATCH] controllers/finalizers: respect the enabled status of PDB Signed-off-by: Furkan --- .../operator/factory/finalize/vmagent.go | 6 ++++-- .../operator/factory/finalize/vmalert.go | 6 ++++-- .../factory/finalize/vmalertmanager.go | 6 ++++-- .../operator/factory/finalize/vmauth.go | 6 ++++-- .../operator/factory/finalize/vmcluster.go | 18 ++++++++++++------ 5 files changed, 28 insertions(+), 14 deletions(-) diff --git a/internal/controller/operator/factory/finalize/vmagent.go b/internal/controller/operator/factory/finalize/vmagent.go index 2beee9f6..9daa57f7 100644 --- a/internal/controller/operator/factory/finalize/vmagent.go +++ b/internal/controller/operator/factory/finalize/vmagent.go @@ -56,8 +56,10 @@ func OnVMAgentDelete(ctx context.Context, rclient client.Client, crd *vmv1beta1. } // check PDB - if err := finalizePBD(ctx, rclient, crd); err != nil { - return err + if crd.Spec.PodDisruptionBudget != nil { + if err := finalizePBD(ctx, rclient, crd); err != nil { + return err + } } // remove vmagents service discovery rbac. if config.IsClusterWideAccessAllowed() { diff --git a/internal/controller/operator/factory/finalize/vmalert.go b/internal/controller/operator/factory/finalize/vmalert.go index b6f9d95f..09784795 100644 --- a/internal/controller/operator/factory/finalize/vmalert.go +++ b/internal/controller/operator/factory/finalize/vmalert.go @@ -38,8 +38,10 @@ func OnVMAlertDelete(ctx context.Context, rclient client.Client, crd *vmv1beta1. } // check PDB - if err := finalizePBD(ctx, rclient, crd); err != nil { - return err + if crd.Spec.PodDisruptionBudget != nil { + if err := finalizePBD(ctx, rclient, crd); err != nil { + return err + } } if err := deleteSA(ctx, rclient, crd); err != nil { return err diff --git a/internal/controller/operator/factory/finalize/vmalertmanager.go b/internal/controller/operator/factory/finalize/vmalertmanager.go index 9a6f8181..3f15fd8a 100644 --- a/internal/controller/operator/factory/finalize/vmalertmanager.go +++ b/internal/controller/operator/factory/finalize/vmalertmanager.go @@ -37,8 +37,10 @@ func OnVMAlertManagerDelete(ctx context.Context, rclient client.Client, crd *vmv } // check PDB - if err := finalizePBD(ctx, rclient, crd); err != nil { - return err + if crd.Spec.PodDisruptionBudget != nil { + if err := finalizePBD(ctx, rclient, crd); err != nil { + return err + } } if err := deleteSA(ctx, rclient, crd); err != nil { diff --git a/internal/controller/operator/factory/finalize/vmauth.go b/internal/controller/operator/factory/finalize/vmauth.go index 151ba4e8..be13997b 100644 --- a/internal/controller/operator/factory/finalize/vmauth.go +++ b/internal/controller/operator/factory/finalize/vmauth.go @@ -51,8 +51,10 @@ func OnVMAuthDelete(ctx context.Context, rclient client.Client, crd *vmv1beta1.V } // check PDB - if err := finalizePBD(ctx, rclient, crd); err != nil { - return err + if crd.Spec.PodDisruptionBudget != nil { + if err := finalizePBD(ctx, rclient, crd); err != nil { + return err + } } // check ingress diff --git a/internal/controller/operator/factory/finalize/vmcluster.go b/internal/controller/operator/factory/finalize/vmcluster.go index b825106f..41f72815 100644 --- a/internal/controller/operator/factory/finalize/vmcluster.go +++ b/internal/controller/operator/factory/finalize/vmcluster.go @@ -57,8 +57,10 @@ func OnVMClusterDelete(ctx context.Context, rclient client.Client, crd *vmv1beta } // check PDB - if err := finalizePBDWithName(ctx, rclient, obj.GetNameWithPrefix(crd.Name), crd.Namespace); err != nil { - return err + if crd.Spec.VMInsert.PodDisruptionBudget != nil { + if err := finalizePBDWithName(ctx, rclient, obj.GetNameWithPrefix(crd.Name), crd.Namespace); err != nil { + return err + } } } @@ -84,8 +86,10 @@ func OnVMClusterDelete(ctx context.Context, rclient client.Client, crd *vmv1beta } // check PDB - if err := finalizePBDWithName(ctx, rclient, obj.GetNameWithPrefix(crd.Name), crd.Namespace); err != nil { - return err + if crd.Spec.VMSelect.PodDisruptionBudget != nil { + if err := finalizePBDWithName(ctx, rclient, obj.GetNameWithPrefix(crd.Name), crd.Namespace); err != nil { + return err + } } } if crd.Spec.VMStorage != nil { @@ -104,8 +108,10 @@ func OnVMClusterDelete(ctx context.Context, rclient client.Client, crd *vmv1beta } // check PDB - if err := finalizePBDWithName(ctx, rclient, obj.GetNameWithPrefix(crd.Name), crd.Namespace); err != nil { - return err + if crd.Spec.VMStorage.PodDisruptionBudget != nil { + if err := finalizePBDWithName(ctx, rclient, obj.GetNameWithPrefix(crd.Name), crd.Namespace); err != nil { + return err + } } }