Skip to content

Commit 6df8e19

Browse files
authored
Merge pull request #12412 from sbueringer/pr-ensure-pointer-deref
🐛 Ensure all pointer status fields are dereferenced correctly
2 parents d900123 + ee406dc commit 6df8e19

File tree

5 files changed

+6
-6
lines changed

5 files changed

+6
-6
lines changed

exp/internal/controllers/machinepool_controller_noderef.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ func (r *MachinePoolReconciler) reconcileNodeRefs(ctx context.Context, s *scope)
126126
}
127127

128128
if ptr.Deref(mp.Status.Replicas, 0) != mp.Status.Deprecated.V1Beta1.ReadyReplicas || len(nodeRefsResult.references) != int(mp.Status.Deprecated.V1Beta1.ReadyReplicas) {
129-
log.Info("Not enough ready replicas or node references", "nodeRefs", len(nodeRefsResult.references), "readyReplicas", mp.Status.ReadyReplicas, "replicas", ptr.Deref(mp.Status.Replicas, 0))
129+
log.Info("Not enough ready replicas or node references", "nodeRefs", len(nodeRefsResult.references), "readyReplicas", ptr.Deref(mp.Status.ReadyReplicas, 0), "replicas", ptr.Deref(mp.Status.Replicas, 0))
130130
v1beta1conditions.MarkFalse(mp, clusterv1.ReplicasReadyV1Beta1Condition, clusterv1.WaitingForReplicasReadyV1Beta1Reason, clusterv1.ConditionSeverityInfo, "")
131131
return ctrl.Result{RequeueAfter: 30 * time.Second}, nil
132132
}

internal/controllers/cluster/cluster_controller_status.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -134,10 +134,10 @@ func setControlPlaneReplicas(_ context.Context, cluster *clusterv1.Cluster, cont
134134
}
135135

136136
if replicas, err := contract.ControlPlane().Replicas().Get(controlPlane); err == nil && replicas != nil {
137-
cluster.Status.ControlPlane.DesiredReplicas = ptr.To(*replicas)
137+
cluster.Status.ControlPlane.DesiredReplicas = replicas
138138
}
139139
if replicas, err := contract.ControlPlane().StatusReplicas().Get(controlPlane); err == nil && replicas != nil {
140-
cluster.Status.ControlPlane.Replicas = ptr.To(*replicas)
140+
cluster.Status.ControlPlane.Replicas = replicas
141141
}
142142
if replicas, err := contract.ControlPlane().ReadyReplicas().Get(controlPlane); err == nil && replicas != nil {
143143
cluster.Status.ControlPlane.ReadyReplicas = replicas

internal/controllers/machinedeployment/machinedeployment_rolling.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ func (r *Reconciler) reconcileOldMachineSets(ctx context.Context, allMSs []*clus
125125

126126
allMachinesCount := mdutil.GetReplicaCountForMachineSets(allMSs)
127127
log.V(4).Info("New MachineSet has available machines",
128-
"machineset", client.ObjectKeyFromObject(newMS).String(), "available-replicas", newMS.Status.AvailableReplicas)
128+
"machineset", client.ObjectKeyFromObject(newMS).String(), "available-replicas", ptr.Deref(newMS.Status.AvailableReplicas, 0))
129129
maxUnavailable := mdutil.MaxUnavailable(*deployment)
130130

131131
// Check if we can scale down. We can scale down in the following 2 cases:

internal/controllers/machinedeployment/machinedeployment_sync.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -492,7 +492,7 @@ func (r *Reconciler) syncDeploymentStatus(allMSs []*clusterv1.MachineSet, newMS
492492
// NOTE: The structure of calculateV1Beta1Status() does not allow us to update the machinedeployment directly, we can only update the status obj it returns. Ideally, we should change calculateV1Beta1Status() --> updateStatus() to be consistent with the rest of the code base, until then, we update conditions here.
493493
v1beta1conditions.MarkTrue(md, clusterv1.MachineDeploymentAvailableV1Beta1Condition)
494494
} else {
495-
v1beta1conditions.MarkFalse(md, clusterv1.MachineDeploymentAvailableV1Beta1Condition, clusterv1.WaitingForAvailableMachinesV1Beta1Reason, clusterv1.ConditionSeverityWarning, "Minimum availability requires %d replicas, current %d available", minReplicasNeeded, ptr.Deref[int32](md.Status.AvailableReplicas, 0))
495+
v1beta1conditions.MarkFalse(md, clusterv1.MachineDeploymentAvailableV1Beta1Condition, clusterv1.WaitingForAvailableMachinesV1Beta1Reason, clusterv1.ConditionSeverityWarning, "Minimum availability requires %d replicas, current %d available", minReplicasNeeded, ptr.Deref(md.Status.AvailableReplicas, 0))
496496
}
497497

498498
if newMS != nil {

internal/util/tree/tree.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -586,7 +586,7 @@ func newRowDescriptor(obj ctrlclient.Object) rowDescriptor {
586586
if obj.Spec.Replicas != nil {
587587
v.replicas = fmt.Sprintf("%d/%d", *obj.Spec.Replicas, ptr.Deref(obj.Status.Replicas, 0))
588588
}
589-
if obj.Status.ReadyReplicas != nil {
589+
if obj.Status.AvailableReplicas != nil {
590590
v.availableCounters = fmt.Sprintf("%d", *obj.Status.AvailableReplicas)
591591
}
592592
if obj.Status.ReadyReplicas != nil {

0 commit comments

Comments
 (0)