From d4bd6c718eb3160ad5e468b2af707fba69a75e54 Mon Sep 17 00:00:00 2001 From: Jian Qiu Date: Mon, 20 Jul 2020 11:12:29 +0800 Subject: [PATCH] Follow up of pr28 --- .../manifestwork_finalize_controller.go | 31 +++++-------------- 1 file changed, 8 insertions(+), 23 deletions(-) diff --git a/pkg/spoke/controllers/finalizercontroller/manifestwork_finalize_controller.go b/pkg/spoke/controllers/finalizercontroller/manifestwork_finalize_controller.go index 26a7da2b0..771e204e7 100644 --- a/pkg/spoke/controllers/finalizercontroller/manifestwork_finalize_controller.go +++ b/pkg/spoke/controllers/finalizercontroller/manifestwork_finalize_controller.go @@ -64,9 +64,6 @@ func (m *ManifestWorkFinalizeController) sync(ctx context.Context, controllerCon klog.V(4).Infof("Reconciling ManifestWork %q", manifestWorkName) manifestWork, err := m.manifestWorkLister.Get(manifestWorkName) - if err != nil && !errors.IsNotFound(err) { - return err - } // Delete appliedmanifestwork if relating manfiestwork is not found or being deleted switch { @@ -86,15 +83,17 @@ func (m *ManifestWorkFinalizeController) sync(ctx context.Context, controllerCon return nil } - appliedManifestWorkPresent, err := m.ifAppliedManifestWorkPresent(ctx, appliedManifestWorkName) - if err != nil { + _, err = m.appliedManifestWorkLister.Get(appliedManifestWorkName) + switch { + case errors.IsNotFound(err): + // if the instance is not found, then we simply continue below this block to remove the finalizer + case err != nil: return err - } - - // If appliedmanifestwork found, requeue the manifestwork to check in the next loop. - if appliedManifestWorkPresent { + default: + // appliedmanifestwork still exists, requeue the manifestwork to check in the next loop. controllerContext.Queue().AddAfter(manifestWorkName, m.rateLimiter.When(manifestWorkName)) return nil + } // Now we can remove manifestwork finalizer @@ -127,17 +126,3 @@ func (m *ManifestWorkFinalizeController) deleteAppliedManifestWork(ctx context.C return m.appliedManifestWorkClient.Delete(ctx, appliedManifestWorkName, metav1.DeleteOptions{}) } - -// ifAppliedManifestWorkPresent checks appliedmanifestwork is present. -// It returns false only when appliedmanifestwork is not found, otherwise returns true. -func (m *ManifestWorkFinalizeController) ifAppliedManifestWorkPresent(ctx context.Context, appliedManifestWorkName string) (bool, error) { - _, err := m.appliedManifestWorkLister.Get(appliedManifestWorkName) - switch { - case errors.IsNotFound(err): - return false, nil - case err != nil: - return true, err - } - - return true, nil -}