Skip to content

Commit 835429d

Browse files
committed
Fix UpToDateResult struct and variable names
Signed-off-by: Stefan Büringer [email protected]
1 parent 41b6683 commit 835429d

File tree

7 files changed

+71
-71
lines changed

7 files changed

+71
-71
lines changed

controlplane/kubeadm/internal/control_plane.go

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -51,12 +51,12 @@ type ControlPlane struct {
5151
machinesPatchHelpers map[string]*patch.Helper
5252

5353
// MachinesNotUpToDate is the source of truth for Machines that are not up-to-date.
54-
// It should be used to check if a Machine is up-to-date (not machinesNotUpToDateResults).
54+
// It should be used to check if a Machine is up-to-date (not machinesUpToDateResults).
5555
MachinesNotUpToDate collections.Machines
56-
// machinesNotUpToDateResults is used to store the result of the UpToDate call for all Machines
56+
// machinesUpToDateResults is used to store the result of the UpToDate call for all Machines
5757
// (even for Machines that are up-to-date).
5858
// MachinesNotUpToDate should always be used instead to check if a Machine is up-to-date.
59-
machinesNotUpToDateResults map[string]NotUpToDateResult
59+
machinesUpToDateResults map[string]UpToDateResult
6060

6161
// reconciliationTime is the time of the current reconciliation, and should be used for all "now" calculations
6262
reconciliationTime metav1.Time
@@ -122,9 +122,9 @@ func NewControlPlane(ctx context.Context, managementCluster ManagementCluster, c
122122
// Select machines that should be rolled out because of an outdated configuration or because rolloutAfter/Before expired.
123123
reconciliationTime := metav1.Now()
124124
machinesNotUptoDate := make(collections.Machines, len(ownedMachines))
125-
machinesNotUpToDateResults := map[string]NotUpToDateResult{}
125+
machinesUpToDateResults := map[string]UpToDateResult{}
126126
for _, m := range ownedMachines {
127-
upToDate, notUpToDateResult, err := UpToDate(ctx, client, cluster, m, kcp, &reconciliationTime, infraMachines, kubeadmConfigs)
127+
upToDate, upToDateResult, err := UpToDate(ctx, client, cluster, m, kcp, &reconciliationTime, infraMachines, kubeadmConfigs)
128128
if err != nil {
129129
return nil, err
130130
}
@@ -133,20 +133,20 @@ func NewControlPlane(ctx context.Context, managementCluster ManagementCluster, c
133133
}
134134
// Set this even if machine is UpToDate. This is needed to complete triggering in-place updates
135135
// MachinesNotUpToDate should always be used instead to check if a Machine is up-to-date.
136-
machinesNotUpToDateResults[m.Name] = *notUpToDateResult
136+
machinesUpToDateResults[m.Name] = *upToDateResult
137137
}
138138

139139
return &ControlPlane{
140-
KCP: kcp,
141-
Cluster: cluster,
142-
Machines: ownedMachines,
143-
machinesPatchHelpers: patchHelpers,
144-
MachinesNotUpToDate: machinesNotUptoDate,
145-
machinesNotUpToDateResults: machinesNotUpToDateResults,
146-
KubeadmConfigs: kubeadmConfigs,
147-
InfraResources: infraMachines,
148-
reconciliationTime: reconciliationTime,
149-
managementCluster: managementCluster,
140+
KCP: kcp,
141+
Cluster: cluster,
142+
Machines: ownedMachines,
143+
machinesPatchHelpers: patchHelpers,
144+
MachinesNotUpToDate: machinesNotUptoDate,
145+
machinesUpToDateResults: machinesUpToDateResults,
146+
KubeadmConfigs: kubeadmConfigs,
147+
InfraResources: infraMachines,
148+
reconciliationTime: reconciliationTime,
149+
managementCluster: managementCluster,
150150
}, nil
151151
}
152152

@@ -240,15 +240,15 @@ func (c *ControlPlane) GetKubeadmConfig(machineName string) (*bootstrapv1.Kubead
240240
}
241241

242242
// MachinesNeedingRollout return a list of machines that need to be rolled out.
243-
func (c *ControlPlane) MachinesNeedingRollout() (collections.Machines, map[string]NotUpToDateResult) {
243+
func (c *ControlPlane) MachinesNeedingRollout() (collections.Machines, map[string]UpToDateResult) {
244244
// Note: Machines already deleted are dropped because they will be replaced by new machines after deletion completes.
245-
return c.MachinesNotUpToDate.Filter(collections.Not(collections.HasDeletionTimestamp)), c.machinesNotUpToDateResults
245+
return c.MachinesNotUpToDate.Filter(collections.Not(collections.HasDeletionTimestamp)), c.machinesUpToDateResults
246246
}
247247

248248
// NotUpToDateMachines return a list of machines that are not up to date with the control
249249
// plane's configuration.
250-
func (c *ControlPlane) NotUpToDateMachines() (collections.Machines, map[string]NotUpToDateResult) {
251-
return c.MachinesNotUpToDate, c.machinesNotUpToDateResults
250+
func (c *ControlPlane) NotUpToDateMachines() (collections.Machines, map[string]UpToDateResult) {
251+
return c.MachinesNotUpToDate, c.machinesUpToDateResults
252252
}
253253

254254
// UpToDateMachines returns the machines that are up to date with the control

controlplane/kubeadm/internal/control_plane_test.go

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -122,19 +122,19 @@ func TestControlPlane(t *testing.T) {
122122

123123
g.Expect(controlPlane.Machines).To(HaveLen(5))
124124

125-
machinesNotUptoDate, machinesNotUpToDateResults := controlPlane.NotUpToDateMachines()
125+
machinesNotUptoDate, machinesUpToDateResults := controlPlane.NotUpToDateMachines()
126126
g.Expect(machinesNotUptoDate.Names()).To(ConsistOf("m2", "m3"))
127-
// machinesNotUpToDateResults contains results for all Machines (including up-to-date Machines).
128-
g.Expect(machinesNotUpToDateResults).To(HaveLen(5))
129-
g.Expect(machinesNotUpToDateResults["m2"].ConditionMessages).To(Equal([]string{"Version v1.29.0, v1.31.0 required"}))
130-
g.Expect(machinesNotUpToDateResults["m3"].ConditionMessages).To(Equal([]string{"Version v1.29.3, v1.31.0 required"}))
127+
// machinesUpToDateResults contains results for all Machines (including up-to-date Machines).
128+
g.Expect(machinesUpToDateResults).To(HaveLen(5))
129+
g.Expect(machinesUpToDateResults["m2"].ConditionMessages).To(Equal([]string{"Version v1.29.0, v1.31.0 required"}))
130+
g.Expect(machinesUpToDateResults["m3"].ConditionMessages).To(Equal([]string{"Version v1.29.3, v1.31.0 required"}))
131131

132-
machinesNeedingRollout, machinesNotUpToDateResults := controlPlane.MachinesNeedingRollout()
132+
machinesNeedingRollout, machinesUpToDateResults := controlPlane.MachinesNeedingRollout()
133133
g.Expect(machinesNeedingRollout.Names()).To(ConsistOf("m2"))
134-
// machinesNotUpToDateResults contains results for all Machines (including up-to-date Machines).
135-
g.Expect(machinesNotUpToDateResults).To(HaveLen(5))
136-
g.Expect(machinesNotUpToDateResults["m2"].LogMessages).To(Equal([]string{"Machine version \"v1.29.0\" is not equal to KCP version \"v1.31.0\""}))
137-
g.Expect(machinesNotUpToDateResults["m3"].LogMessages).To(Equal([]string{"Machine version \"v1.29.3\" is not equal to KCP version \"v1.31.0\""}))
134+
// machinesUpToDateResults contains results for all Machines (including up-to-date Machines).
135+
g.Expect(machinesUpToDateResults).To(HaveLen(5))
136+
g.Expect(machinesUpToDateResults["m2"].LogMessages).To(Equal([]string{"Machine version \"v1.29.0\" is not equal to KCP version \"v1.31.0\""}))
137+
g.Expect(machinesUpToDateResults["m3"].LogMessages).To(Equal([]string{"Machine version \"v1.29.3\" is not equal to KCP version \"v1.31.0\""}))
138138

139139
upToDateMachines := controlPlane.UpToDateMachines()
140140
g.Expect(upToDateMachines).To(HaveLen(3))

controlplane/kubeadm/internal/controllers/controller.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ type KubeadmControlPlaneReconciler struct {
9797
ssaCache ssa.Cache
9898

9999
// Only used for testing
100-
overrideTryInPlaceUpdateFunc func(ctx context.Context, controlPlane *internal.ControlPlane, machineToInPlaceUpdate *clusterv1.Machine, machinesNeedingRolloutResult internal.NotUpToDateResult) (bool, ctrl.Result, error)
100+
overrideTryInPlaceUpdateFunc func(ctx context.Context, controlPlane *internal.ControlPlane, machineToInPlaceUpdate *clusterv1.Machine, machineUpToDateResult internal.UpToDateResult) (bool, ctrl.Result, error)
101101
overrideScaleUpControlPlaneFunc func(ctx context.Context, controlPlane *internal.ControlPlane) (ctrl.Result, error)
102102
overrideScaleDownControlPlaneFunc func(ctx context.Context, controlPlane *internal.ControlPlane, machineToDelete *clusterv1.Machine) (ctrl.Result, error)
103103
}
@@ -472,16 +472,16 @@ func (r *KubeadmControlPlaneReconciler) reconcile(ctx context.Context, controlPl
472472
}
473473

474474
// Control plane machines rollout due to configuration changes (e.g. upgrades) takes precedence over other operations.
475-
machinesNeedingRollout, machinesNeedingRolloutResults := controlPlane.MachinesNeedingRollout()
475+
machinesNeedingRollout, machinesUpToDateResults := controlPlane.MachinesNeedingRollout()
476476
switch {
477477
case len(machinesNeedingRollout) > 0:
478478
var allMessages []string
479-
for machine, machinesNeedingRolloutResult := range machinesNeedingRolloutResults {
480-
allMessages = append(allMessages, fmt.Sprintf("Machine %s needs rollout: %s", machine, strings.Join(machinesNeedingRolloutResult.LogMessages, ",")))
479+
for machine, machineUpToDateResult := range machinesUpToDateResults {
480+
allMessages = append(allMessages, fmt.Sprintf("Machine %s needs rollout: %s", machine, strings.Join(machineUpToDateResult.LogMessages, ",")))
481481
}
482482
log.Info(fmt.Sprintf("Rolling out Control Plane machines: %s", strings.Join(allMessages, ",")), "machinesNeedingRollout", machinesNeedingRollout.Names())
483483
v1beta1conditions.MarkFalse(controlPlane.KCP, controlplanev1.MachinesSpecUpToDateV1Beta1Condition, controlplanev1.RollingUpdateInProgressV1Beta1Reason, clusterv1.ConditionSeverityWarning, "Rolling %d replicas with outdated spec (%d replicas up to date)", len(machinesNeedingRollout), len(controlPlane.Machines)-len(machinesNeedingRollout))
484-
return r.updateControlPlane(ctx, controlPlane, machinesNeedingRollout, machinesNeedingRolloutResults)
484+
return r.updateControlPlane(ctx, controlPlane, machinesNeedingRollout, machinesUpToDateResults)
485485
default:
486486
// make sure last upgrade operation is marked as completed.
487487
// NOTE: we are checking the condition already exists in order to avoid to set this condition at the first
@@ -985,16 +985,16 @@ func (r *KubeadmControlPlaneReconciler) reconcileControlPlaneAndMachinesConditio
985985
}
986986

987987
func reconcileMachineUpToDateCondition(_ context.Context, controlPlane *internal.ControlPlane) {
988-
machinesNotUptoDate, machinesNotUpToDateResults := controlPlane.NotUpToDateMachines()
988+
machinesNotUptoDate, machinesUpToDateResults := controlPlane.NotUpToDateMachines()
989989
machinesNotUptoDateNames := sets.New(machinesNotUptoDate.Names()...)
990990

991991
for _, machine := range controlPlane.Machines {
992992
if machinesNotUptoDateNames.Has(machine.Name) {
993993
// Note: the code computing the message for KCP's RolloutOut condition is making assumptions on the format/content of this message.
994994
message := ""
995-
if machinesNotUpToDateResult, ok := machinesNotUpToDateResults[machine.Name]; ok && len(machinesNotUpToDateResult.ConditionMessages) > 0 {
995+
if machineUpToDateResult, ok := machinesUpToDateResults[machine.Name]; ok && len(machineUpToDateResult.ConditionMessages) > 0 {
996996
var reasons []string
997-
for _, conditionMessage := range machinesNotUpToDateResult.ConditionMessages {
997+
for _, conditionMessage := range machineUpToDateResult.ConditionMessages {
998998
reasons = append(reasons, fmt.Sprintf("* %s", conditionMessage))
999999
}
10001000
message = strings.Join(reasons, "\n")

controlplane/kubeadm/internal/controllers/inplace.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,10 @@ func (r *KubeadmControlPlaneReconciler) tryInPlaceUpdate(
2929
ctx context.Context,
3030
controlPlane *internal.ControlPlane,
3131
machineToInPlaceUpdate *clusterv1.Machine,
32-
machinesNeedingRolloutResult internal.NotUpToDateResult,
32+
machineUpToDateResult internal.UpToDateResult,
3333
) (fallbackToScaleDown bool, _ ctrl.Result, _ error) {
3434
if r.overrideTryInPlaceUpdateFunc != nil {
35-
return r.overrideTryInPlaceUpdateFunc(ctx, controlPlane, machineToInPlaceUpdate, machinesNeedingRolloutResult)
35+
return r.overrideTryInPlaceUpdateFunc(ctx, controlPlane, machineToInPlaceUpdate, machineUpToDateResult)
3636
}
3737

3838
// Always fallback to scale down until in-place is implemented.

controlplane/kubeadm/internal/controllers/upgrade.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ func (r *KubeadmControlPlaneReconciler) updateControlPlane(
3535
ctx context.Context,
3636
controlPlane *internal.ControlPlane,
3737
machinesNeedingRollout collections.Machines,
38-
machinesNeedingRolloutResults map[string]internal.NotUpToDateResult,
38+
machinesUpToDateResults map[string]internal.UpToDateResult,
3939
) (ctrl.Result, error) {
4040
log := ctrl.LoggerFrom(ctx)
4141

@@ -89,7 +89,7 @@ func (r *KubeadmControlPlaneReconciler) updateControlPlane(
8989
switch controlPlane.KCP.Spec.Rollout.Strategy.Type {
9090
case controlplanev1.RollingUpdateStrategyType:
9191
// RolloutStrategy is currently defaulted and validated to be RollingUpdate
92-
res, err := r.rollingUpdate(ctx, controlPlane, machinesNeedingRollout, machinesNeedingRolloutResults)
92+
res, err := r.rollingUpdate(ctx, controlPlane, machinesNeedingRollout, machinesUpToDateResults)
9393
if err != nil {
9494
return ctrl.Result{}, errors.Wrapf(err, "failed to update control plane")
9595
}
@@ -104,7 +104,7 @@ func (r *KubeadmControlPlaneReconciler) rollingUpdate(
104104
ctx context.Context,
105105
controlPlane *internal.ControlPlane,
106106
machinesNeedingRollout collections.Machines,
107-
machinesNeedingRolloutResults map[string]internal.NotUpToDateResult,
107+
machinesUpToDateResults map[string]internal.UpToDateResult,
108108
) (ctrl.Result, error) {
109109
currentReplicas := int32(controlPlane.Machines.Len())
110110
currentUpToDateReplicas := int32(controlPlane.UpToDateMachines().Len())
@@ -129,19 +129,19 @@ func (r *KubeadmControlPlaneReconciler) rollingUpdate(
129129
if err != nil {
130130
return ctrl.Result{}, errors.Wrap(err, "failed to select next Machine for rollout")
131131
}
132-
machinesNeedingRolloutResult, ok := machinesNeedingRolloutResults[machineToInPlaceUpdateOrScaleDown.Name]
132+
machineUpToDateResult, ok := machinesUpToDateResults[machineToInPlaceUpdateOrScaleDown.Name]
133133
if !ok {
134-
// Note: This should never happen as we store results for all Machines in machinesNeedingRolloutResults.
134+
// Note: This should never happen as we store results for all Machines in machinesUpToDateResults.
135135
return ctrl.Result{}, errors.Errorf("failed to check if Machine %s is UpToDate", machineToInPlaceUpdateOrScaleDown.Name)
136136
}
137137

138138
// If the selected Machine is eligible for in-place update and we don't already have enough up-to-date replicas, try in-place update.
139139
// Note: To be safe we only try an in-place update when we would otherwise delete a Machine. This ensures we could
140140
// afford if the in-place update fails and the Machine becomes unavailable (and eventually MHC kicks in and the Machine is recreated).
141141
if feature.Gates.Enabled(feature.InPlaceUpdates) &&
142-
machinesNeedingRolloutResult.EligibleForInPlaceUpdate &&
142+
machineUpToDateResult.EligibleForInPlaceUpdate &&
143143
currentUpToDateReplicas < desiredReplicas {
144-
fallbackToScaleDown, res, err := r.tryInPlaceUpdate(ctx, controlPlane, machineToInPlaceUpdateOrScaleDown, machinesNeedingRolloutResult)
144+
fallbackToScaleDown, res, err := r.tryInPlaceUpdate(ctx, controlPlane, machineToInPlaceUpdateOrScaleDown, machineUpToDateResult)
145145
if err != nil {
146146
return ctrl.Result{}, err
147147
}

0 commit comments

Comments
 (0)