From b10e2e771483ef374e539a0d69b3a2176cc6547b Mon Sep 17 00:00:00 2001 From: Artem Chernyshev Date: Thu, 13 Apr 2023 13:33:33 +0300 Subject: [PATCH] fix: properly write desired replicas count in scale conditions Fixes: https://github.com/siderolabs/cluster-api-control-plane-provider-talos/issues/155 We were reading it from `*int` pointer without dereferencing it, so it was writing pointer address to the status instead of the actual value. Signed-off-by: Artem Chernyshev --- controllers/scale.go | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/controllers/scale.go b/controllers/scale.go index e9ebbb7..48796b0 100644 --- a/controllers/scale.go +++ b/controllers/scale.go @@ -24,7 +24,11 @@ import ( func (r *TalosControlPlaneReconciler) scaleUpControlPlane(ctx context.Context, cluster *clusterv1.Cluster, tcp *controlplanev1.TalosControlPlane, controlPlane *ControlPlane) (ctrl.Result, error) { numMachines := len(controlPlane.Machines) - desiredReplicas := tcp.Spec.Replicas + desiredReplicas := 0 + + if tcp.Spec.Replicas != nil { + desiredReplicas = int(*tcp.Spec.Replicas) + } conditions.MarkFalse(tcp, controlplanev1.ResizedCondition, controlplanev1.ScalingUpReason, clusterv1.ConditionSeverityWarning, "Scaling up control plane to %d replicas (actual %d)", @@ -44,7 +48,11 @@ func (r *TalosControlPlaneReconciler) scaleDownControlPlane( machinesRequireUpgrade collections.Machines) (ctrl.Result, error) { numMachines := len(controlPlane.Machines) - desiredReplicas := tcp.Spec.Replicas + desiredReplicas := 0 + + if tcp.Spec.Replicas != nil { + desiredReplicas = int(*tcp.Spec.Replicas) + } conditions.MarkFalse(tcp, controlplanev1.ResizedCondition, controlplanev1.ScalingDownReason, clusterv1.ConditionSeverityWarning, "Scaling down control plane to %d replicas (actual %d)",