Skip to content

Commit

Permalink
Fix comment
Browse files Browse the repository at this point in the history
  • Loading branch information
haijianyang committed Aug 1, 2023
1 parent 8037ba1 commit d881627
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 14 deletions.
12 changes: 7 additions & 5 deletions controllers/elfmachine_controller_placement_group.go
Original file line number Diff line number Diff line change
Expand Up @@ -168,9 +168,9 @@ func (r *ElfMachineReconciler) preCheckPlacementGroup(ctx *context.MachineContex
return nil, err
}

// KCP is not in scaling down/rolling update.
// When KCP is not in scaling down and it's not rolling update the 1st CP Machine, just return since the placement group is full.
if !(kcputil.IsKCPRollingUpdateFirstMachine(kcp) || kcputil.IsKCPInScalingDown(kcp)) {
ctx.Logger.V(1).Info("The placement group is full, wait for enough available hosts", "placementGroup", *placementGroup.Name, "availableHosts", availableHosts.String(), "usedHostsByPG", usedHostsByPG.String())
ctx.Logger.V(1).Info("KCP is not in scaling down and it's not rolling update the 1st CP Machine, the placement group is full, wait for enough available hosts", "placementGroup", *placementGroup.Name, "availableHosts", availableHosts.String(), "usedHostsByPG", usedHostsByPG.String())

return nil, nil
}
Expand Down Expand Up @@ -211,7 +211,9 @@ func (r *ElfMachineReconciler) preCheckPlacementGroup(ctx *context.MachineContex
return nil, nil
}

// KCP is in rolling update.
// When the PlacementGroup is full and it's rolling update the 1st CP Machine and,
// place the VM on the target host without joining the PlacementGroup and power it on.
// After other CP Machine are rolled out successfully, add this 1st CP VM into the PlacementGroup.

if usedHostsByPG.Len() == usedHostsByPG.Available(*service.TowerMemory(ctx.ElfMachine.Spec.MemoryMiB)).Len() &&
int(*kcp.Spec.Replicas) == usedHostsByPG.Len() {
Expand All @@ -225,7 +227,7 @@ func (r *ElfMachineReconciler) preCheckPlacementGroup(ctx *context.MachineContex
return pointer.String(hostID), err
}

ctx.Logger.V(1).Info("The placement group is full, wait for enough available hosts", "placementGroup", *placementGroup.Name, "availableHosts", availableHosts.String(), "usedHostsByPG", usedHostsByPG.String())
ctx.Logger.V(1).Info("KCP is rolling update the 1st CP Machine, the placement group is full, wait for enough available hosts", "placementGroup", *placementGroup.Name, "availableHosts", availableHosts.String(), "usedHostsByPG", usedHostsByPG.String())

return nil, nil
}
Expand Down Expand Up @@ -448,7 +450,7 @@ func (r *ElfMachineReconciler) joinPlacementGroup(ctx *context.MachineContext, v
return false, err
}

if kcputil.IsKCPRollingUpdate(kcp) {
if kcputil.IsKCPInRollingUpdate(kcp) {
ctx.Logger.Info("KCP rolling update in progress, skip migrating VM", "vmRef", ctx.ElfMachine.Status.VMRef, "vmId", *vm.ID)
return true, nil
}
Expand Down
10 changes: 5 additions & 5 deletions controllers/elfmachine_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1260,7 +1260,7 @@ var _ = Describe("ElfMachineReconciler", func() {
hostID, err = reconciler.preCheckPlacementGroup(machineContext)
Expect(err).To(BeZero())
Expect(hostID).To(BeNil())
Expect(logBuffer.String()).To(ContainSubstring("The placement group is full, wait for enough available hosts"))
Expect(logBuffer.String()).To(ContainSubstring("KCP is not in scaling down and it's not rolling update the 1st CP Machine, the placement group is full, wait for enough available hosts"))
})

It("when placement group is full and KCP rolling update in progress", func() {
Expand Down Expand Up @@ -1334,7 +1334,7 @@ var _ = Describe("ElfMachineReconciler", func() {
host, err = reconciler.preCheckPlacementGroup(machineContext)
Expect(err).To(BeZero())
Expect(host).To(BeNil())
Expect(logBuffer.String()).To(ContainSubstring("The placement group is full, wait for enough available hosts"))
Expect(logBuffer.String()).To(ContainSubstring("KCP is rolling update the 1st CP Machine, the placement group is full, wait for enough available hosts"))

logBuffer = new(bytes.Buffer)
klog.SetOutput(logBuffer)
Expand All @@ -1348,7 +1348,7 @@ var _ = Describe("ElfMachineReconciler", func() {
host, err = reconciler.preCheckPlacementGroup(machineContext)
Expect(err).To(BeZero())
Expect(host).To(BeNil())
Expect(logBuffer.String()).To(ContainSubstring("The placement group is full, wait for enough available hosts"))
Expect(logBuffer.String()).To(ContainSubstring("KCP is rolling update the 1st CP Machine, the placement group is full, wait for enough available hosts"))

logBuffer = new(bytes.Buffer)
klog.SetOutput(logBuffer)
Expand All @@ -1362,7 +1362,7 @@ var _ = Describe("ElfMachineReconciler", func() {
host, err = reconciler.preCheckPlacementGroup(machineContext)
Expect(err).To(BeZero())
Expect(host).To(BeNil())
Expect(logBuffer.String()).To(ContainSubstring("The placement group is full, wait for enough available hosts"))
Expect(logBuffer.String()).To(ContainSubstring("KCP is rolling update the 1st CP Machine, the placement group is full, wait for enough available hosts"))

logBuffer = new(bytes.Buffer)
klog.SetOutput(logBuffer)
Expand Down Expand Up @@ -1458,7 +1458,7 @@ var _ = Describe("ElfMachineReconciler", func() {
hostID, err := reconciler.preCheckPlacementGroup(machineContext)
Expect(err).To(BeZero())
Expect(hostID).To(BeNil())
Expect(logBuffer.String()).To(ContainSubstring("The placement group is full, wait for enough available hosts"))
Expect(logBuffer.String()).To(ContainSubstring("KCP is not in scaling down and it's not rolling update the 1st CP Machine, the placement group is full, wait for enough available hosts"))
expectConditions(elfMachine, []conditionAssertion{{infrav1.VMProvisionedCondition, corev1.ConditionFalse, clusterv1.ConditionSeverityInfo, infrav1.WaitingForAvailableHostRequiredByPlacementGroupReason}})

elfMachine.Status.Conditions = nil
Expand Down
2 changes: 1 addition & 1 deletion pkg/service/mock_services/vm_mock.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions pkg/util/kcp/kcp.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,15 @@ import (
"sigs.k8s.io/cluster-api/util/conditions"
)

// IsKCPRollingUpdate returns whether KCP is in scaling down.
// IsKCPInRollingUpdate returns whether KCP is in scaling down.
//
// When KCP is in rolling update, KCP controller marks
// MachinesSpecUpToDateCondition to false and RollingUpdateInProgressReason as Reason.
//
// When all machines are up to date, KCP controller marks MachinesSpecUpToDateCondition to true.
//
// For more information about KCP MachinesSpecUpToDateCondition and RollingUpdateInProgressReason, refer to https://github.com/kubernetes-sigs/cluster-api/blob/main/api/v1beta1/condition_consts.go
func IsKCPRollingUpdate(kcp *controlplanev1.KubeadmControlPlane) bool {
func IsKCPInRollingUpdate(kcp *controlplanev1.KubeadmControlPlane) bool {
return conditions.IsFalse(kcp, controlplanev1.MachinesSpecUpToDateCondition) &&
conditions.GetReason(kcp, controlplanev1.MachinesSpecUpToDateCondition) == controlplanev1.RollingUpdateInProgressReason
}
Expand All @@ -51,7 +51,7 @@ func IsKCPRollingUpdate(kcp *controlplanev1.KubeadmControlPlane) bool {
// 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 rollout, refer to https://github.com/kubernetes-sigs/cluster-api/blob/main/docs/proposals/20191017-kubeadm-based-control-plane.md#kubeadmcontrolplane-rollout
func IsKCPRollingUpdateFirstMachine(kcp *controlplanev1.KubeadmControlPlane) bool {
return IsKCPRollingUpdate(kcp) && kcp.Status.UpdatedReplicas == 1
return IsKCPInRollingUpdate(kcp) && kcp.Status.UpdatedReplicas == 1
}

// IsKCPInScalingDown returns whether KCP is in scaling down.
Expand Down

0 comments on commit d881627

Please sign in to comment.