Skip to content

Commit

Permalink
Ensure running machines always contain hook annoation
Browse files Browse the repository at this point in the history
Signed-off-by: Danil-Grigorev <[email protected]>
  • Loading branch information
Danil-Grigorev committed Sep 12, 2024
1 parent 3037432 commit e1befb1
Showing 1 changed file with 16 additions and 15 deletions.
31 changes: 16 additions & 15 deletions controlplane/internal/controllers/rke2controlplane_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -550,21 +550,6 @@ func (r *RKE2ControlPlaneReconciler) reconcileNormal(
desiredReplicas := int(*rcp.Spec.Replicas)

switch {
case numMachines == desiredReplicas:
nonDeleteingMachines := controlPlane.Machines.Filter(collections.Not(collections.HasDeletionTimestamp))
for _, machine := range nonDeleteingMachines {
annotaions := machine.GetAnnotations()

if _, found := annotaions[controlplanev1.PreTerminateHookCleanupAnnotation]; !found {
annotaions[controlplanev1.PreTerminateHookCleanupAnnotation] = ""
machine.SetAnnotations(annotaions)
}
}

// Patch machine annoations
if err := controlPlane.PatchMachines(ctx); err != nil {
return ctrl.Result{}, err
}
// We are creating the first replica
case numMachines < desiredReplicas && numMachines == 0:
// Create new Machine w/ init
Expand Down Expand Up @@ -951,6 +936,22 @@ func (r *RKE2ControlPlaneReconciler) ClusterToRKE2ControlPlane(ctx context.Conte
}

func (r *RKE2ControlPlaneReconciler) reconcilePreTerminateHook(ctx context.Context, controlPlane *rke2.ControlPlane) (ctrl.Result, error) {
// Ensure that every active machine has the drain hook set
patchHookAnnotation := false
for _, machine := range controlPlane.Machines.Filter(collections.ActiveMachines) {

Check failure on line 941 in controlplane/internal/controllers/rke2controlplane_controller.go

View workflow job for this annotation

GitHub Actions / lint

ranges should only be cuddled with assignments used in the iteration (wsl)

Check failure on line 941 in controlplane/internal/controllers/rke2controlplane_controller.go

View workflow job for this annotation

GitHub Actions / lint

ranges should only be cuddled with assignments used in the iteration (wsl)
if _, exists := machine.Annotations[controlplanev1.PreTerminateHookCleanupAnnotation]; !exists {
machine.Annotations[controlplanev1.PreTerminateHookCleanupAnnotation] = ""
patchHookAnnotation = true
}
}

if patchHookAnnotation {
// Patch machine annoations
if err := controlPlane.PatchMachines(ctx); err != nil {
return ctrl.Result{}, err
}
}

if !controlPlane.HasDeletingMachine() {
return ctrl.Result{}, nil
}
Expand Down

0 comments on commit e1befb1

Please sign in to comment.