Propagate PreTerminateHookCleanupAnnotation on old machines
- Lint fixes Signed-off-by: Danil-Grigorev <danil.grigorev@suse.com>
This commit is contained in:
parent
eb09be3882
commit
931e7cc55a
|
|
@ -550,6 +550,21 @@ func (r *RKE2ControlPlaneReconciler) reconcileNormal(
|
||||||
desiredReplicas := int(*rcp.Spec.Replicas)
|
desiredReplicas := int(*rcp.Spec.Replicas)
|
||||||
|
|
||||||
switch {
|
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
|
// We are creating the first replica
|
||||||
case numMachines < desiredReplicas && numMachines == 0:
|
case numMachines < desiredReplicas && numMachines == 0:
|
||||||
// Create new Machine w/ init
|
// Create new Machine w/ init
|
||||||
|
|
@ -945,7 +960,7 @@ func (r *RKE2ControlPlaneReconciler) reconcilePreTerminateHook(ctx context.Conte
|
||||||
}
|
}
|
||||||
|
|
||||||
// Return early if there are other pre-terminate hooks for the Machine.
|
// Return early if there are other pre-terminate hooks for the Machine.
|
||||||
// The KCP pre-terminate hook should be the one executed last, so that kubelet
|
// The CAPRKE2 pre-terminate hook should be the one executed last, so that kubelet
|
||||||
// is still working while other pre-terminate hooks are run.
|
// is still working while other pre-terminate hooks are run.
|
||||||
// Note: This is done only for Kubernetes >= v1.31 to reduce the blast radius of this check.
|
// Note: This is done only for Kubernetes >= v1.31 to reduce the blast radius of this check.
|
||||||
if version.Compare(parsedVersion, semver.MustParse("1.31.0"), version.WithoutPreReleases()) >= 0 {
|
if version.Compare(parsedVersion, semver.MustParse("1.31.0"), version.WithoutPreReleases()) >= 0 {
|
||||||
|
|
@ -967,7 +982,8 @@ func (r *RKE2ControlPlaneReconciler) reconcilePreTerminateHook(ctx context.Conte
|
||||||
if controlPlane.Machines.Len() > 1 {
|
if controlPlane.Machines.Len() > 1 {
|
||||||
workloadCluster, err := r.GetWorkloadCluster(ctx, controlPlane)
|
workloadCluster, err := r.GetWorkloadCluster(ctx, controlPlane)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return ctrl.Result{}, errors.Wrapf(err, "failed to remove etcd member for deleting Machine %s: failed to create client to workload cluster", klog.KObj(deletingMachine))
|
return ctrl.Result{}, errors.Wrapf(err,
|
||||||
|
"failed to remove etcd member for deleting Machine %s: failed to create client to workload cluster", klog.KObj(deletingMachine))
|
||||||
}
|
}
|
||||||
|
|
||||||
// Note: In regular deletion cases (remediation, scale down) the leader should have been already moved.
|
// Note: In regular deletion cases (remediation, scale down) the leader should have been already moved.
|
||||||
|
|
@ -994,7 +1010,9 @@ func (r *RKE2ControlPlaneReconciler) reconcilePreTerminateHook(ctx context.Conte
|
||||||
return ctrl.Result{}, err
|
return ctrl.Result{}, err
|
||||||
}
|
}
|
||||||
|
|
||||||
log.Info("Waiting for Machines to be deleted", "machines", strings.Join(controlPlane.Machines.Filter(collections.HasDeletionTimestamp).Names(), ", "))
|
log.Info("Waiting for Machines to be deleted", "machines",
|
||||||
|
strings.Join(controlPlane.Machines.Filter(collections.HasDeletionTimestamp).Names(), ", "))
|
||||||
|
|
||||||
return ctrl.Result{RequeueAfter: deleteRequeueAfter}, nil
|
return ctrl.Result{RequeueAfter: deleteRequeueAfter}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -1004,6 +1022,7 @@ func machineHasOtherPreTerminateHooks(machine *clusterv1.Machine) bool {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -164,7 +164,6 @@ func (r *RKE2ControlPlaneReconciler) scaleDownControlPlane(
|
||||||
// Also in this case the reconcileDelete code of the Machine controller won't execute Node drain
|
// Also in this case the reconcileDelete code of the Machine controller won't execute Node drain
|
||||||
// and wait for volume detach.
|
// and wait for volume detach.
|
||||||
if err := r.removePreTerminateHookAnnotationFromMachine(ctx, machineToDelete); err != nil {
|
if err := r.removePreTerminateHookAnnotationFromMachine(ctx, machineToDelete); err != nil {
|
||||||
|
|
||||||
return ctrl.Result{}, err
|
return ctrl.Result{}, err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -196,9 +195,11 @@ func (r *RKE2ControlPlaneReconciler) removePreTerminateHookAnnotationFromMachine
|
||||||
|
|
||||||
machineOriginal := machine.DeepCopy()
|
machineOriginal := machine.DeepCopy()
|
||||||
delete(machine.Annotations, controlplanev1.PreTerminateHookCleanupAnnotation)
|
delete(machine.Annotations, controlplanev1.PreTerminateHookCleanupAnnotation)
|
||||||
|
|
||||||
if err := r.Client.Patch(ctx, machine, client.MergeFrom(machineOriginal)); err != nil {
|
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 errors.Wrapf(err, "failed to remove pre-terminate hook from control plane Machine %s", klog.KObj(machine))
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -280,7 +280,9 @@ func (c *ControlPlane) SortedByDeletionTimestamp(s collections.Machines) []*clus
|
||||||
for _, value := range s {
|
for _, value := range s {
|
||||||
res = append(res, value)
|
res = append(res, value)
|
||||||
}
|
}
|
||||||
|
|
||||||
sort.Sort(res)
|
sort.Sort(res)
|
||||||
|
|
||||||
return res
|
return res
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -422,5 +424,6 @@ func (o machinesByDeletionTimestamp) Less(i, j int) bool {
|
||||||
if o[i].DeletionTimestamp.Equal(o[j].DeletionTimestamp) {
|
if o[i].DeletionTimestamp.Equal(o[j].DeletionTimestamp) {
|
||||||
return o[i].Name < o[j].Name
|
return o[i].Name < o[j].Name
|
||||||
}
|
}
|
||||||
|
|
||||||
return o[i].DeletionTimestamp.Before(o[j].DeletionTimestamp)
|
return o[i].DeletionTimestamp.Before(o[j].DeletionTimestamp)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue