diff --git a/cloud/scope/cluster.go b/cloud/scope/cluster.go index a99557394..484511ae5 100644 --- a/cloud/scope/cluster.go +++ b/cloud/scope/cluster.go @@ -91,9 +91,11 @@ func (s *ClusterScope) Close(ctx context.Context) error { return s.PatchObject(ctx) } -// AddFinalizer adds a finalizer and immediately patches the object to avoid any race conditions +// AddFinalizer adds a finalizer if not present and immediately patches the +// object to avoid any race conditions. func (s *ClusterScope) AddFinalizer(ctx context.Context) error { - controllerutil.AddFinalizer(s.LinodeCluster, infrav1alpha1.GroupVersion.String()) - - return s.Close(ctx) + if controllerutil.AddFinalizer(s.LinodeCluster, infrav1alpha1.GroupVersion.String()) { + return s.Close(ctx) + } + return nil } diff --git a/cloud/scope/machine.go b/cloud/scope/machine.go index 1857400d0..4b8bfdf78 100644 --- a/cloud/scope/machine.go +++ b/cloud/scope/machine.go @@ -85,11 +85,13 @@ func (s *MachineScope) Close(ctx context.Context) error { return s.PatchObject(ctx) } -// AddFinalizer adds a finalizer and immediately patches the object to avoid any race conditions +// AddFinalizer adds a finalizer if not present and immediately patches the +// object to avoid any race conditions. func (s *MachineScope) AddFinalizer(ctx context.Context) error { - controllerutil.AddFinalizer(s.LinodeMachine, infrav1alpha1.GroupVersion.String()) - - return s.Close(ctx) + if controllerutil.AddFinalizer(s.LinodeMachine, infrav1alpha1.GroupVersion.String()) { + return s.Close(ctx) + } + return nil } // GetBootstrapData returns the bootstrap data from the secret in the Machine's bootstrap.dataSecretName. diff --git a/cloud/scope/vpc.go b/cloud/scope/vpc.go index a5a68c208..823eb154b 100644 --- a/cloud/scope/vpc.go +++ b/cloud/scope/vpc.go @@ -84,9 +84,11 @@ func (s *VPCScope) Close(ctx context.Context) error { return s.PatchObject(ctx) } -// AddFinalizer adds a finalizer and immediately patches the object to avoid any race conditions +// AddFinalizer adds a finalizer if not present and immediately patches the +// object to avoid any race conditions. func (s *VPCScope) AddFinalizer(ctx context.Context) error { - controllerutil.AddFinalizer(s.LinodeVPC, infrav1alpha1.GroupVersion.String()) - - return s.Close(ctx) + if controllerutil.AddFinalizer(s.LinodeVPC, infrav1alpha1.GroupVersion.String()) { + return s.Close(ctx) + } + return nil }