Skip to content

Commit

Permalink
Remove finalizer when cloud resource is found absent (#220)
Browse files Browse the repository at this point in the history
This is to ensure that reconciles can complete even when cloud resources
(droplets, LBs) cannot be referenced anymore.
  • Loading branch information
timoreimann authored Dec 10, 2020
1 parent 778b783 commit 4fc3ece
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 1 deletion.
3 changes: 2 additions & 1 deletion controllers/docluster_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -166,14 +166,15 @@ func (r *DOClusterReconciler) reconcileDelete(ctx context.Context, clusterScope
if loadbalancer == nil {
clusterScope.V(2).Info("Unable to locate load balancer")
r.Recorder.Eventf(docluster, corev1.EventTypeWarning, "NoLoadBalancerFound", "Unable to find matching load balancer")
controllerutil.RemoveFinalizer(docluster, infrav1.ClusterFinalizer)
return reconcile.Result{}, nil
}

if err := networkingsvc.DeleteLoadBalancer(loadbalancer.ID); err != nil {
return reconcile.Result{}, errors.Wrapf(err, "error deleting load balancer for DOCluster %s/%s", docluster.Namespace, docluster.Name)
}

r.Recorder.Eventf(docluster, corev1.EventTypeNormal, "LoadBalancerDeleted", "Deleted a instance - %s", loadbalancer.Name)
r.Recorder.Eventf(docluster, corev1.EventTypeNormal, "LoadBalancerDeleted", "Deleted an LoadBalancer - %s", loadbalancer.Name)
// Cluster is deleted so remove the finalizer.
controllerutil.RemoveFinalizer(docluster, infrav1.ClusterFinalizer)
return reconcile.Result{}, nil
Expand Down
1 change: 1 addition & 0 deletions controllers/domachine_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,7 @@ func (r *DOMachineReconciler) reconcileDelete(ctx context.Context, machineScope
if droplet == nil {
clusterScope.V(2).Info("Unable to locate droplet instance")
r.Recorder.Eventf(domachine, corev1.EventTypeWarning, "NoInstanceFound", "Skip deleting")
controllerutil.RemoveFinalizer(domachine, infrav1.MachineFinalizer)
return reconcile.Result{}, nil
}

Expand Down

0 comments on commit 4fc3ece

Please sign in to comment.