Skip to content

Commit

Permalink
SKS-1573: Add DeleteMachineAnnotation to the failed CP Machine when s…
Browse files Browse the repository at this point in the history
…caling down KCP after a failed rolling update (#128)
  • Loading branch information
haijianyang authored Jul 25, 2023
1 parent e296203 commit 8c924e6
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
1 change: 1 addition & 0 deletions controllers/elfmachine_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1465,6 +1465,7 @@ var _ = Describe("ElfMachineReconciler", func() {
kcp.Spec.Replicas = pointer.Int32(1)
kcp.Status.Replicas = 2
kcp.Status.UpdatedReplicas = kcp.Status.Replicas
conditions.MarkFalse(kcp, controlplanev1.ResizedCondition, controlplanev1.ScalingDownReason, clusterv1.ConditionSeverityWarning, "")
host := fake.NewTowerHost()
elfMachine1, machine1 := fake.NewMachineObjects(elfCluster, cluster)
fake.ToControlPlaneMachine(machine1, kcp)
Expand Down
12 changes: 8 additions & 4 deletions pkg/util/kcp/kcp.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@ limitations under the License.
*/

import (
clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1"
controlplanev1 "sigs.k8s.io/cluster-api/controlplane/kubeadm/api/v1beta1"
"sigs.k8s.io/cluster-api/util/conditions"
)

// IsKCPRollingUpdateFirstMachine returns true if KCP is in rolling update and creating the first CP Machine.
Expand All @@ -41,10 +43,12 @@ func IsKCPRollingUpdateFirstMachine(kcp *controlplanev1.KubeadmControlPlane) boo

// IsKCPInScalingDown returns whether KCP is in scaling down.
//
// When KCP is in scaling down, machines managed by KCP is greater than kcp.Spec.Replicas,
// and these machines are up to date with the control plane's configuration.
// When KCP is in scaling down/rolling update, KCP controller marks
// ResizedCondition to false and ScalingDownReason as Reason.
//
// For more information about KCP replicas, refer to https://github.com/kubernetes-sigs/cluster-api/blob/main/controlplane/kubeadm/api/v1beta1/kubeadm_control_plane_types.go
// For more information about KCP ResizedCondition and ScalingDownReason, refer to https://github.com/kubernetes-sigs/cluster-api/blob/main/api/v1beta1/condition_consts.go
func IsKCPInScalingDown(kcp *controlplanev1.KubeadmControlPlane) bool {
return *kcp.Spec.Replicas < kcp.Status.Replicas && kcp.Status.Replicas == kcp.Status.UpdatedReplicas
return conditions.IsFalse(kcp, clusterv1.ResizedCondition) &&
conditions.GetReason(kcp, controlplanev1.ResizedCondition) == controlplanev1.ScalingDownReason &&
*kcp.Spec.Replicas < kcp.Status.UpdatedReplicas
}

0 comments on commit 8c924e6

Please sign in to comment.