Skip to content

Commit

Permalink
fixup
Browse files Browse the repository at this point in the history
  • Loading branch information
sbueringer committed Sep 5, 2024
1 parent 4a3af97 commit 8ed4065
Showing 1 changed file with 16 additions and 10 deletions.
26 changes: 16 additions & 10 deletions controlplane/kubeadm/internal/controllers/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -579,11 +579,8 @@ func (r *KubeadmControlPlaneReconciler) reconcileDelete(ctx context.Context, con
// to forward etcd leadership without any member left after we went through the Machine deletion.
// Also in this case the reconcileDelete code of the Machine controller won't execute Node drain
// and wait for volume detach.
log.Info("Removing pre-terminate hook from control plane machine")
deletingMachineOriginal := machineToDelete.DeepCopy()
delete(machineToDelete.Annotations, controlplanev1.PreTerminateHookCleanupAnnotation)
if err := r.Client.Patch(ctx, machineToDelete, client.MergeFrom(deletingMachineOriginal)); err != nil {
errs = append(errs, errors.Wrapf(err, "failed to remove pre-terminate hook from control plane Machine %s", klog.KObj(machineToDelete)))
if err := r.removePreTerminateHookAnnotationFromMachine(ctx, machineToDelete); err != nil {
errs = append(errs, err)
continue
}

Expand All @@ -602,6 +599,18 @@ func (r *KubeadmControlPlaneReconciler) reconcileDelete(ctx context.Context, con
return ctrl.Result{RequeueAfter: deleteRequeueAfter}, nil
}

func (r *KubeadmControlPlaneReconciler) removePreTerminateHookAnnotationFromMachine(ctx context.Context, machine *clusterv1.Machine) error {
log := ctrl.LoggerFrom(ctx)
log.Info("Removing pre-terminate hook from control plane Machine")

machineOriginal := machine.DeepCopy()
delete(machine.Annotations, controlplanev1.PreTerminateHookCleanupAnnotation)
if err := r.Client.Patch(ctx, machine, client.MergeFrom(machineOriginal)); err != nil {
return errors.Wrapf(err, "failed to remove pre-terminate hook from control plane Machine %s", klog.KObj(machine))
}
return nil
}

// ClusterToKubeadmControlPlane is a handler.ToRequestsFunc to be used to enqueue requests for reconciliation
// for KubeadmControlPlane based on updates to a Cluster.
func (r *KubeadmControlPlaneReconciler) ClusterToKubeadmControlPlane(_ context.Context, o client.Object) []ctrl.Request {
Expand Down Expand Up @@ -882,11 +891,8 @@ func (r *KubeadmControlPlaneReconciler) reconcilePreTerminateHook(ctx context.Co
}
}

log.Info("Removing pre-terminate hook from control plane Machine")
deletingMachineOriginal := deletingMachine.DeepCopy()
delete(deletingMachine.Annotations, controlplanev1.PreTerminateHookCleanupAnnotation)
if err := r.Client.Patch(ctx, deletingMachine, client.MergeFrom(deletingMachineOriginal)); err != nil {
return ctrl.Result{}, errors.Wrapf(err, "failed to remove pre-terminate hook from control plane Machine %s", klog.KObj(deletingMachine))
if err := r.removePreTerminateHookAnnotationFromMachine(ctx, deletingMachine); err != nil {
return ctrl.Result{}, err
}

log.Info("Waiting for Machines to be deleted", "machines", strings.Join(controlPlane.Machines.Filter(collections.HasDeletionTimestamp).Names(), ", "))
Expand Down

0 comments on commit 8ed4065

Please sign in to comment.