From 8493f4e190f06d20ba18b9d1635a0da4726005aa Mon Sep 17 00:00:00 2001 From: Christian Schlotter Date: Thu, 21 Nov 2024 13:49:02 +0100 Subject: [PATCH] cluster: split MachinesReady and MachinesUpToDate for ControlPlane and Worker --- api/v1beta1/cluster_types.go | 104 ++++-- .../controllers/cluster/cluster_controller.go | 6 +- .../cluster/cluster_controller_status.go | 158 +++++---- .../cluster/cluster_controller_status_test.go | 335 +++++++++++++++--- util/conditions/v1beta2/sort.go | 12 +- 5 files changed, 465 insertions(+), 150 deletions(-) diff --git a/api/v1beta1/cluster_types.go b/api/v1beta1/cluster_types.go index 0c90be618820..b573429366fa 100644 --- a/api/v1beta1/cluster_types.go +++ b/api/v1beta1/cluster_types.go @@ -221,50 +221,96 @@ const ( ClusterWorkersAvailableInternalErrorV1Beta2Reason = InternalErrorV1Beta2Reason ) -// Cluster's MachinesReady condition and corresponding reasons that will be used in v1Beta2 API version. +// Cluster's ControlPlaneMachinesReady condition and corresponding reasons that will be used in v1Beta2 API version. const ( - // ClusterMachinesReadyV1Beta2Condition surfaces detail of issues on the controlled machines, if any. - ClusterMachinesReadyV1Beta2Condition = MachinesReadyV1Beta2Condition + // ClusterControlPlaneMachinesReadyV1Beta2Condition surfaces detail of issues on control plane machines, if any. + ClusterControlPlaneMachinesReadyV1Beta2Condition = "ControlPlaneMachinesReady" - // ClusterMachinesReadyV1Beta2Reason surfaces when all the controlled machine's Ready conditions are true. - ClusterMachinesReadyV1Beta2Reason = ReadyV1Beta2Reason + // ClusterControlPlaneMachinesReadyV1Beta2Reason surfaces when all control plane machine's Ready conditions are true. + ClusterControlPlaneMachinesReadyV1Beta2Reason = ReadyV1Beta2Reason - // ClusterMachinesNotReadyV1Beta2Reason surfaces when at least one of the controlled machine's Ready conditions is false. - ClusterMachinesNotReadyV1Beta2Reason = NotReadyV1Beta2Reason + // ClusterControlPlaneMachinesNotReadyV1Beta2Reason surfaces when at least one of control plane machine's Ready conditions is false. + ClusterControlPlaneMachinesNotReadyV1Beta2Reason = NotReadyV1Beta2Reason - // ClusterMachinesReadyUnknownV1Beta2Reason surfaces when at least one of the controlled machine's Ready conditions is unknown - // and none of the controlled machine's Ready conditions is false. - ClusterMachinesReadyUnknownV1Beta2Reason = ReadyUnknownV1Beta2Reason + // ClusterControlPlaneMachinesReadyUnknownV1Beta2Reason surfaces when at least one of control plane machine's Ready conditions is unknown + // and none of control plane machine's Ready conditions is false. + ClusterControlPlaneMachinesReadyUnknownV1Beta2Reason = ReadyUnknownV1Beta2Reason - // ClusterMachinesReadyNoReplicasV1Beta2Reason surfaces when no machines exist for the Cluster. - ClusterMachinesReadyNoReplicasV1Beta2Reason = NoReplicasV1Beta2Reason + // ClusterControlPlaneMachinesReadyNoReplicasV1Beta2Reason surfaces when no control plane machines exist for the Cluster. + ClusterControlPlaneMachinesReadyNoReplicasV1Beta2Reason = NoReplicasV1Beta2Reason - // ClusterMachinesReadyInternalErrorV1Beta2Reason surfaces unexpected failures when listing machines - // or aggregating machine's conditions. - ClusterMachinesReadyInternalErrorV1Beta2Reason = InternalErrorV1Beta2Reason + // ClusterControlPlaneMachinesReadyInternalErrorV1Beta2Reason surfaces unexpected failures when listing control plane machines + // or aggregating control plane machine's conditions. + ClusterControlPlaneMachinesReadyInternalErrorV1Beta2Reason = InternalErrorV1Beta2Reason ) -// Cluster's MachinesUpToDate condition and corresponding reasons that will be used in v1Beta2 API version. +// Cluster's WorkerMachinesReady condition and corresponding reasons that will be used in v1Beta2 API version. const ( - // ClusterMachinesUpToDateV1Beta2Condition surfaces details of Cluster's machines not up to date, if any. - ClusterMachinesUpToDateV1Beta2Condition = MachinesUpToDateV1Beta2Condition + // ClusterWorkerMachinesReadyV1Beta2Condition surfaces detail of issues on the worker machines, if any. + ClusterWorkerMachinesReadyV1Beta2Condition = "WorkerMachinesReady" - // ClusterMachinesUpToDateV1Beta2Reason surfaces when all the controlled machine's UpToDate conditions are true. - ClusterMachinesUpToDateV1Beta2Reason = UpToDateV1Beta2Reason + // ClusterWorkerMachinesReadyV1Beta2Reason surfaces when all the worker machine's Ready conditions are true. + ClusterWorkerMachinesReadyV1Beta2Reason = ReadyV1Beta2Reason - // ClusterMachinesNotUpToDateV1Beta2Reason surfaces when at least one of the controlled machine's UpToDate conditions is false. - ClusterMachinesNotUpToDateV1Beta2Reason = NotUpToDateV1Beta2Reason + // ClusterWorkerMachinesNotReadyV1Beta2Reason surfaces when at least one of the worker machine's Ready conditions is false. + ClusterWorkerMachinesNotReadyV1Beta2Reason = NotReadyV1Beta2Reason - // ClusterMachinesUpToDateUnknownV1Beta2Reason surfaces when at least one of the controlled machine's UpToDate conditions is unknown - // and none of the controlled machine's UpToDate conditions is false. - ClusterMachinesUpToDateUnknownV1Beta2Reason = UpToDateUnknownV1Beta2Reason + // ClusterWorkerMachinesReadyUnknownV1Beta2Reason surfaces when at least one of the worker machine's Ready conditions is unknown + // and none of the worker machine's Ready conditions is false. + ClusterWorkerMachinesReadyUnknownV1Beta2Reason = ReadyUnknownV1Beta2Reason - // ClusterMachinesUpToDateNoReplicasV1Beta2Reason surfaces when no machines exist for the Cluster. - ClusterMachinesUpToDateNoReplicasV1Beta2Reason = NoReplicasV1Beta2Reason + // ClusterWorkerMachinesReadyNoReplicasV1Beta2Reason surfaces when no worker machines exist for the Cluster. + ClusterWorkerMachinesReadyNoReplicasV1Beta2Reason = NoReplicasV1Beta2Reason - // ClusterMachinesUpToDateInternalErrorV1Beta2Reason surfaces unexpected failures when listing machines + // ClusterWorkerMachinesReadyInternalErrorV1Beta2Reason surfaces unexpected failures when listing worker machines + // or aggregating worker machine's conditions. + ClusterWorkerMachinesReadyInternalErrorV1Beta2Reason = InternalErrorV1Beta2Reason +) + +// Cluster's ControlPlaneMachinesUpToDate condition and corresponding reasons that will be used in v1Beta2 API version. +const ( + // ClusterControlPlaneMachinesUpToDateV1Beta2Condition surfaces details of control plane machines not up to date, if any. + ClusterControlPlaneMachinesUpToDateV1Beta2Condition = "ControlPlaneMachinesUpToDate" + + // ClusterControlPlaneMachinesUpToDateV1Beta2Reason surfaces when all the control plane machine's UpToDate conditions are true. + ClusterControlPlaneMachinesUpToDateV1Beta2Reason = UpToDateV1Beta2Reason + + // ClusterControlPlaneMachinesNotUpToDateV1Beta2Reason surfaces when at least one of the control plane machine's UpToDate conditions is false. + ClusterControlPlaneMachinesNotUpToDateV1Beta2Reason = NotUpToDateV1Beta2Reason + + // ClusterControlPlaneMachinesUpToDateUnknownV1Beta2Reason surfaces when at least one of the control plane machine's UpToDate conditions is unknown + // and none of the control plane machine's UpToDate conditions is false. + ClusterControlPlaneMachinesUpToDateUnknownV1Beta2Reason = UpToDateUnknownV1Beta2Reason + + // ClusterControlPlaneMachinesUpToDateNoReplicasV1Beta2Reason surfaces when no control plane machines exist for the Cluster. + ClusterControlPlaneMachinesUpToDateNoReplicasV1Beta2Reason = NoReplicasV1Beta2Reason + + // ClusterControlPlaneMachinesUpToDateInternalErrorV1Beta2Reason surfaces unexpected failures when listing control plane machines + // or aggregating status. + ClusterControlPlaneMachinesUpToDateInternalErrorV1Beta2Reason = InternalErrorV1Beta2Reason +) + +// Cluster's WorkerMachinesUpToDate condition and corresponding reasons that will be used in v1Beta2 API version. +const ( + // ClusterWorkerMachinesUpToDateV1Beta2Condition surfaces details of worker machines not up to date, if any. + ClusterWorkerMachinesUpToDateV1Beta2Condition = "WorkerMachinesUpToDate" + + // ClusterWorkerMachinesUpToDateV1Beta2Reason surfaces when all the worker machine's UpToDate conditions are true. + ClusterWorkerMachinesUpToDateV1Beta2Reason = UpToDateV1Beta2Reason + + // ClusterWorkerMachinesNotUpToDateV1Beta2Reason surfaces when at least one of the worker machine's UpToDate conditions is false. + ClusterWorkerMachinesNotUpToDateV1Beta2Reason = NotUpToDateV1Beta2Reason + + // ClusterWorkerMachinesUpToDateUnknownV1Beta2Reason surfaces when at least one of the worker machine's UpToDate conditions is unknown + // and none of the worker machine's UpToDate conditions is false. + ClusterWorkerMachinesUpToDateUnknownV1Beta2Reason = UpToDateUnknownV1Beta2Reason + + // ClusterWorkerMachinesUpToDateNoReplicasV1Beta2Reason surfaces when no worker machines exist for the Cluster. + ClusterWorkerMachinesUpToDateNoReplicasV1Beta2Reason = NoReplicasV1Beta2Reason + + // ClusterWorkerMachinesUpToDateInternalErrorV1Beta2Reason surfaces unexpected failures when listing worker machines // or aggregating status. - ClusterMachinesUpToDateInternalErrorV1Beta2Reason = InternalErrorV1Beta2Reason + ClusterWorkerMachinesUpToDateInternalErrorV1Beta2Reason = InternalErrorV1Beta2Reason ) // Cluster's RemoteConnectionProbe condition and corresponding reasons that will be used in v1Beta2 API version. diff --git a/internal/controllers/cluster/cluster_controller.go b/internal/controllers/cluster/cluster_controller.go index e30414d94ce2..21de8193b298 100644 --- a/internal/controllers/cluster/cluster_controller.go +++ b/internal/controllers/cluster/cluster_controller.go @@ -261,9 +261,11 @@ func patchCluster(ctx context.Context, patchHelper *patch.Helper, cluster *clust clusterv1.ClusterInfrastructureReadyV1Beta2Condition, clusterv1.ClusterControlPlaneAvailableV1Beta2Condition, clusterv1.ClusterControlPlaneInitializedV1Beta2Condition, + clusterv1.ClusterControlPlaneMachinesReadyV1Beta2Condition, + clusterv1.ClusterControlPlaneMachinesUpToDateV1Beta2Condition, clusterv1.ClusterWorkersAvailableV1Beta2Condition, - clusterv1.ClusterMachinesReadyV1Beta2Condition, - clusterv1.ClusterMachinesUpToDateV1Beta2Condition, + clusterv1.ClusterWorkerMachinesReadyV1Beta2Condition, + clusterv1.ClusterWorkerMachinesUpToDateV1Beta2Condition, clusterv1.ClusterRemoteConnectionProbeV1Beta2Condition, clusterv1.ClusterRollingOutV1Beta2Condition, clusterv1.ClusterScalingUpV1Beta2Condition, diff --git a/internal/controllers/cluster/cluster_controller_status.go b/internal/controllers/cluster/cluster_controller_status.go index 46d250c6f545..4b070a98476e 100644 --- a/internal/controllers/cluster/cluster_controller_status.go +++ b/internal/controllers/cluster/cluster_controller_status.go @@ -51,7 +51,7 @@ func (r *Reconciler) updateStatus(ctx context.Context, s *scope) { _, isMachinePoolMachine := machine.Labels[clusterv1.MachinePoolNameLabel] return isMachinePoolMachine } - allMachines := s.descendants.allMachines.Filter(collections.Not(isMachinePoolMachine)) + controlPlaneMachines := s.descendants.controlPlaneMachines workerMachines := s.descendants.workerMachines.Filter(collections.Not(isMachinePoolMachine)) machinesToBeRemediated := s.descendants.machinesToBeRemediated.Filter(collections.Not(isMachinePoolMachine)) unhealthyMachines := s.descendants.unhealthyMachines.Filter(collections.Not(isMachinePoolMachine)) @@ -65,8 +65,10 @@ func (r *Reconciler) updateStatus(ctx context.Context, s *scope) { setControlPlaneAvailableCondition(ctx, s.cluster, s.controlPlane, s.controlPlaneIsNotFound) setControlPlaneInitializedCondition(ctx, s.cluster, s.controlPlane, s.descendants.controlPlaneMachines, s.infraClusterIsNotFound, s.getDescendantsSucceeded) setWorkersAvailableCondition(ctx, s.cluster, expv1.MachinePoolList{}, s.descendants.machineDeployments, s.getDescendantsSucceeded) - setMachinesReadyCondition(ctx, s.cluster, allMachines, s.getDescendantsSucceeded) - setMachinesUpToDateCondition(ctx, s.cluster, allMachines, s.getDescendantsSucceeded) + setControlPlaneMachinesReadyCondition(ctx, s.cluster, controlPlaneMachines, s.getDescendantsSucceeded) + setWorkerMachinesReadyCondition(ctx, s.cluster, workerMachines, s.getDescendantsSucceeded) + setControlPlaneMachinesUpToDateCondition(ctx, s.cluster, controlPlaneMachines, s.getDescendantsSucceeded) + setWorkerMachinesUpToDateCondition(ctx, s.cluster, workerMachines, s.getDescendantsSucceeded) setRollingOutCondition(ctx, s.cluster, s.controlPlane, expv1.MachinePoolList{}, s.descendants.machineDeployments, s.controlPlaneIsNotFound, s.getDescendantsSucceeded) setScalingUpCondition(ctx, s.cluster, s.controlPlane, expv1.MachinePoolList{}, s.descendants.machineDeployments, s.descendants.machineSets, s.controlPlaneIsNotFound, s.getDescendantsSucceeded) setScalingDownCondition(ctx, s.cluster, s.controlPlane, expv1.MachinePoolList{}, s.descendants.machineDeployments, s.descendants.machineSets, s.controlPlaneIsNotFound, s.getDescendantsSucceeded) @@ -603,113 +605,127 @@ func setWorkersAvailableCondition(ctx context.Context, cluster *clusterv1.Cluste v1beta2conditions.Set(cluster, *workersAvailableCondition) } -func setMachinesReadyCondition(ctx context.Context, cluster *clusterv1.Cluster, machines collections.Machines, getDescendantsSucceeded bool) { - log := ctrl.LoggerFrom(ctx) +func setControlPlaneMachinesReadyCondition(ctx context.Context, cluster *clusterv1.Cluster, machines collections.Machines, getDescendantsSucceeded bool) { + machinesConditionSetter{ + condition: clusterv1.ClusterControlPlaneMachinesReadyV1Beta2Condition, + machineAggregationCondition: clusterv1.MachineReadyV1Beta2Condition, + internalErrorReason: clusterv1.ClusterControlPlaneMachinesReadyInternalErrorV1Beta2Reason, + noReplicasReason: clusterv1.ClusterControlPlaneMachinesReadyNoReplicasV1Beta2Reason, + issueReason: clusterv1.ClusterControlPlaneMachinesNotReadyV1Beta2Reason, + unknownReason: clusterv1.ClusterControlPlaneMachinesReadyUnknownV1Beta2Reason, + infoReason: clusterv1.ClusterControlPlaneMachinesReadyV1Beta2Reason, + }.setMachinesCondition(ctx, cluster, machines, getDescendantsSucceeded) +} - // If there was some unexpected errors in listing descendants (this should never happen), surface it. - if !getDescendantsSucceeded { - v1beta2conditions.Set(cluster, metav1.Condition{ - Type: clusterv1.ClusterMachinesReadyV1Beta2Condition, - Status: metav1.ConditionUnknown, - Reason: clusterv1.ClusterMachinesReadyInternalErrorV1Beta2Reason, - Message: "Please check controller logs for errors", - }) - return - } +func setWorkerMachinesReadyCondition(ctx context.Context, cluster *clusterv1.Cluster, machines collections.Machines, getDescendantsSucceeded bool) { + machinesConditionSetter{ + condition: clusterv1.ClusterWorkerMachinesReadyV1Beta2Condition, + machineAggregationCondition: clusterv1.MachineReadyV1Beta2Condition, + internalErrorReason: clusterv1.ClusterWorkerMachinesReadyInternalErrorV1Beta2Reason, + noReplicasReason: clusterv1.ClusterWorkerMachinesReadyNoReplicasV1Beta2Reason, + issueReason: clusterv1.ClusterWorkerMachinesNotReadyV1Beta2Reason, + unknownReason: clusterv1.ClusterWorkerMachinesReadyUnknownV1Beta2Reason, + infoReason: clusterv1.ClusterWorkerMachinesReadyV1Beta2Reason, + }.setMachinesCondition(ctx, cluster, machines, getDescendantsSucceeded) +} - if len(machines) == 0 { - v1beta2conditions.Set(cluster, metav1.Condition{ - Type: clusterv1.ClusterMachinesReadyV1Beta2Condition, - Status: metav1.ConditionTrue, - Reason: clusterv1.ClusterMachinesReadyNoReplicasV1Beta2Reason, - }) - return - } +func setControlPlaneMachinesUpToDateCondition(ctx context.Context, cluster *clusterv1.Cluster, machines collections.Machines, getDescendantsSucceeded bool) { + // Only consider Machines that have an UpToDate condition or are older than 10s. + // This is done to ensure the MachinesUpToDate condition doesn't flicker after a new Machine is created, + // because it can take a bit until the UpToDate condition is set on a new Machine. + machines = machines.Filter(func(machine *clusterv1.Machine) bool { + return v1beta2conditions.Has(machine, clusterv1.MachineUpToDateV1Beta2Condition) || time.Since(machine.CreationTimestamp.Time) > 10*time.Second + }) - readyCondition, err := v1beta2conditions.NewAggregateCondition( - machines.UnsortedList(), clusterv1.MachineReadyV1Beta2Condition, - v1beta2conditions.TargetConditionType(clusterv1.ClusterMachinesReadyV1Beta2Condition), - // Using a custom merge strategy to override reasons applied during merge - v1beta2conditions.CustomMergeStrategy{ - MergeStrategy: v1beta2conditions.DefaultMergeStrategy( - v1beta2conditions.ComputeReasonFunc(v1beta2conditions.GetDefaultComputeMergeReasonFunc( - clusterv1.ClusterMachinesNotReadyV1Beta2Reason, - clusterv1.ClusterMachinesReadyUnknownV1Beta2Reason, - clusterv1.ClusterMachinesReadyV1Beta2Reason, - )), - ), - }, - ) - if err != nil { - log.Error(err, "Failed to aggregate Machine's Ready conditions") - v1beta2conditions.Set(cluster, metav1.Condition{ - Type: clusterv1.ClusterMachinesReadyV1Beta2Condition, - Status: metav1.ConditionUnknown, - Reason: clusterv1.ClusterMachinesReadyInternalErrorV1Beta2Reason, - Message: "Please check controller logs for errors", - }) - return - } + machinesConditionSetter{ + condition: clusterv1.ClusterControlPlaneMachinesUpToDateV1Beta2Condition, + machineAggregationCondition: clusterv1.MachineUpToDateV1Beta2Condition, + internalErrorReason: clusterv1.ClusterControlPlaneMachinesUpToDateInternalErrorV1Beta2Reason, + noReplicasReason: clusterv1.ClusterControlPlaneMachinesUpToDateNoReplicasV1Beta2Reason, + issueReason: clusterv1.ClusterControlPlaneMachinesNotUpToDateV1Beta2Reason, + unknownReason: clusterv1.ClusterControlPlaneMachinesUpToDateUnknownV1Beta2Reason, + infoReason: clusterv1.ClusterControlPlaneMachinesUpToDateV1Beta2Reason, + }.setMachinesCondition(ctx, cluster, machines, getDescendantsSucceeded) +} + +func setWorkerMachinesUpToDateCondition(ctx context.Context, cluster *clusterv1.Cluster, machines collections.Machines, getDescendantsSucceeded bool) { + // Only consider Machines that have an UpToDate condition or are older than 10s. + // This is done to ensure the MachinesUpToDate condition doesn't flicker after a new Machine is created, + // because it can take a bit until the UpToDate condition is set on a new Machine. + machines = machines.Filter(func(machine *clusterv1.Machine) bool { + return v1beta2conditions.Has(machine, clusterv1.MachineUpToDateV1Beta2Condition) || time.Since(machine.CreationTimestamp.Time) > 10*time.Second + }) - v1beta2conditions.Set(cluster, *readyCondition) + machinesConditionSetter{ + condition: clusterv1.ClusterWorkerMachinesUpToDateV1Beta2Condition, + machineAggregationCondition: clusterv1.MachineUpToDateV1Beta2Condition, + internalErrorReason: clusterv1.ClusterWorkerMachinesUpToDateInternalErrorV1Beta2Reason, + noReplicasReason: clusterv1.ClusterWorkerMachinesUpToDateNoReplicasV1Beta2Reason, + issueReason: clusterv1.ClusterWorkerMachinesNotUpToDateV1Beta2Reason, + unknownReason: clusterv1.ClusterWorkerMachinesUpToDateUnknownV1Beta2Reason, + infoReason: clusterv1.ClusterWorkerMachinesUpToDateV1Beta2Reason, + }.setMachinesCondition(ctx, cluster, machines, getDescendantsSucceeded) } -func setMachinesUpToDateCondition(ctx context.Context, cluster *clusterv1.Cluster, machines collections.Machines, getDescendantsSucceeded bool) { +type machinesConditionSetter struct { + condition string + machineAggregationCondition string + internalErrorReason string + noReplicasReason string + issueReason string + unknownReason string + infoReason string +} + +func (s machinesConditionSetter) setMachinesCondition(ctx context.Context, cluster *clusterv1.Cluster, machines collections.Machines, getDescendantsSucceeded bool) { log := ctrl.LoggerFrom(ctx) - // If we got unexpected errors in listing the machines (this should never happen), surface them. + // If there was some unexpected errors in listing descendants (this should never happen), surface it. if !getDescendantsSucceeded { v1beta2conditions.Set(cluster, metav1.Condition{ - Type: clusterv1.ClusterMachinesUpToDateV1Beta2Condition, + Type: s.condition, Status: metav1.ConditionUnknown, - Reason: clusterv1.ClusterMachinesUpToDateInternalErrorV1Beta2Reason, + Reason: s.internalErrorReason, Message: "Please check controller logs for errors", }) return } - // Only consider Machines that have an UpToDate condition or are older than 10s. - // This is done to ensure the MachinesUpToDate condition doesn't flicker after a new Machine is created, - // because it can take a bit until the UpToDate condition is set on a new Machine. - machines = machines.Filter(func(machine *clusterv1.Machine) bool { - return v1beta2conditions.Has(machine, clusterv1.MachineUpToDateV1Beta2Condition) || time.Since(machine.CreationTimestamp.Time) > 10*time.Second - }) - if len(machines) == 0 { v1beta2conditions.Set(cluster, metav1.Condition{ - Type: clusterv1.ClusterMachinesUpToDateV1Beta2Condition, + Type: s.condition, Status: metav1.ConditionTrue, - Reason: clusterv1.ClusterMachinesUpToDateNoReplicasV1Beta2Reason, + Reason: s.noReplicasReason, }) return } - upToDateCondition, err := v1beta2conditions.NewAggregateCondition( - machines.UnsortedList(), clusterv1.MachineUpToDateV1Beta2Condition, - v1beta2conditions.TargetConditionType(clusterv1.ClusterMachinesUpToDateV1Beta2Condition), + machinesCondition, err := v1beta2conditions.NewAggregateCondition( + machines.UnsortedList(), s.machineAggregationCondition, + v1beta2conditions.TargetConditionType(s.condition), // Using a custom merge strategy to override reasons applied during merge v1beta2conditions.CustomMergeStrategy{ MergeStrategy: v1beta2conditions.DefaultMergeStrategy( v1beta2conditions.ComputeReasonFunc(v1beta2conditions.GetDefaultComputeMergeReasonFunc( - clusterv1.ClusterMachinesNotUpToDateV1Beta2Reason, - clusterv1.ClusterMachinesUpToDateUnknownV1Beta2Reason, - clusterv1.ClusterMachinesUpToDateV1Beta2Reason, + s.issueReason, + s.unknownReason, + s.infoReason, )), ), }, ) if err != nil { - log.Error(err, "Failed to aggregate Machine's UpToDate conditions") + log.Error(err, fmt.Sprintf("Failed to aggregate Machine's %s conditions", s.condition)) v1beta2conditions.Set(cluster, metav1.Condition{ - Type: clusterv1.ClusterMachinesUpToDateV1Beta2Condition, + Type: s.condition, Status: metav1.ConditionUnknown, - Reason: clusterv1.ClusterMachinesUpToDateInternalErrorV1Beta2Reason, + Reason: s.internalErrorReason, Message: "Please check controller logs for errors", }) return } - v1beta2conditions.Set(cluster, *upToDateCondition) + v1beta2conditions.Set(cluster, *machinesCondition) } func setRemediatingCondition(ctx context.Context, cluster *clusterv1.Cluster, machinesToBeRemediated, unhealthyMachines collections.Machines, getMachinesSucceeded bool) { diff --git a/internal/controllers/cluster/cluster_controller_status_test.go b/internal/controllers/cluster/cluster_controller_status_test.go index c4c525b045b1..897531db4ceb 100644 --- a/internal/controllers/cluster/cluster_controller_status_test.go +++ b/internal/controllers/cluster/cluster_controller_status_test.go @@ -765,7 +765,7 @@ func TestSetWorkersAvailableCondition(t *testing.T) { } } -func TestSetMachinesReadyCondition(t *testing.T) { +func TestSetControlPlaneMachinesReadyCondition(t *testing.T) { readyCondition := metav1.Condition{ Type: clusterv1.MachineReadyV1Beta2Condition, Status: metav1.ConditionTrue, @@ -785,9 +785,9 @@ func TestSetMachinesReadyCondition(t *testing.T) { machines: nil, getDescendantsSucceeded: false, expectCondition: metav1.Condition{ - Type: clusterv1.ClusterMachinesReadyV1Beta2Condition, + Type: clusterv1.ClusterControlPlaneMachinesReadyV1Beta2Condition, Status: metav1.ConditionUnknown, - Reason: clusterv1.ClusterMachinesReadyInternalErrorV1Beta2Reason, + Reason: clusterv1.ClusterControlPlaneMachinesReadyInternalErrorV1Beta2Reason, Message: "Please check controller logs for errors", }, }, @@ -797,37 +797,37 @@ func TestSetMachinesReadyCondition(t *testing.T) { machines: []*clusterv1.Machine{}, getDescendantsSucceeded: true, expectCondition: metav1.Condition{ - Type: clusterv1.ClusterMachinesReadyV1Beta2Condition, + Type: clusterv1.ClusterControlPlaneMachinesReadyV1Beta2Condition, Status: metav1.ConditionTrue, - Reason: clusterv1.ClusterMachinesReadyNoReplicasV1Beta2Reason, + Reason: clusterv1.ClusterControlPlaneMachinesReadyNoReplicasV1Beta2Reason, }, }, { name: "all machines are ready", cluster: fakeCluster("c"), machines: []*clusterv1.Machine{ - fakeMachine("machine-1", v1beta2Condition(readyCondition)), - fakeMachine("machine-2", v1beta2Condition(readyCondition)), + fakeMachine("machine-1", controlPlane(true), v1beta2Condition(readyCondition)), + fakeMachine("machine-2", controlPlane(true), v1beta2Condition(readyCondition)), }, getDescendantsSucceeded: true, expectCondition: metav1.Condition{ - Type: clusterv1.ClusterMachinesReadyV1Beta2Condition, + Type: clusterv1.ClusterControlPlaneMachinesReadyV1Beta2Condition, Status: metav1.ConditionTrue, - Reason: clusterv1.ClusterMachinesReadyV1Beta2Reason, + Reason: clusterv1.ClusterControlPlaneMachinesReadyV1Beta2Reason, }, }, { name: "one ready, one has nothing reported", cluster: fakeCluster("c"), machines: []*clusterv1.Machine{ - fakeMachine("machine-1", v1beta2Condition(readyCondition)), - fakeMachine("machine-2"), + fakeMachine("machine-1", controlPlane(true), v1beta2Condition(readyCondition)), + fakeMachine("machine-2", controlPlane(true)), }, getDescendantsSucceeded: true, expectCondition: metav1.Condition{ - Type: clusterv1.ClusterMachinesReadyV1Beta2Condition, + Type: clusterv1.ClusterControlPlaneMachinesReadyV1Beta2Condition, Status: metav1.ConditionUnknown, - Reason: clusterv1.ClusterMachinesReadyUnknownV1Beta2Reason, + Reason: clusterv1.ClusterControlPlaneMachinesReadyUnknownV1Beta2Reason, Message: "* Machine machine-2: Condition Ready not yet reported", }, }, @@ -835,20 +835,20 @@ func TestSetMachinesReadyCondition(t *testing.T) { name: "one ready, one reporting not ready, one reporting unknown, one reporting deleting", cluster: fakeCluster("c"), machines: []*clusterv1.Machine{ - fakeMachine("machine-1", v1beta2Condition(readyCondition)), - fakeMachine("machine-2", v1beta2Condition(metav1.Condition{ + fakeMachine("machine-1", controlPlane(true), v1beta2Condition(readyCondition)), + fakeMachine("machine-2", controlPlane(true), v1beta2Condition(metav1.Condition{ Type: clusterv1.MachineReadyV1Beta2Condition, Status: metav1.ConditionFalse, Reason: "SomeReason", Message: "HealthCheckSucceeded: Some message", })), - fakeMachine("machine-3", v1beta2Condition(metav1.Condition{ + fakeMachine("machine-3", controlPlane(true), v1beta2Condition(metav1.Condition{ Type: clusterv1.MachineReadyV1Beta2Condition, Status: metav1.ConditionUnknown, Reason: "SomeUnknownReason", Message: "Some unknown message", })), - fakeMachine("machine-4", v1beta2Condition(metav1.Condition{ + fakeMachine("machine-4", controlPlane(true), v1beta2Condition(metav1.Condition{ Type: clusterv1.MachineReadyV1Beta2Condition, Status: metav1.ConditionFalse, Reason: clusterv1.MachineDeletingV1Beta2Reason, @@ -857,26 +857,110 @@ func TestSetMachinesReadyCondition(t *testing.T) { }, getDescendantsSucceeded: true, expectCondition: metav1.Condition{ - Type: clusterv1.ClusterMachinesReadyV1Beta2Condition, + Type: clusterv1.ClusterControlPlaneMachinesReadyV1Beta2Condition, Status: metav1.ConditionFalse, - Reason: clusterv1.ClusterMachinesNotReadyV1Beta2Reason, + Reason: clusterv1.ClusterControlPlaneMachinesNotReadyV1Beta2Reason, Message: "* Machine machine-2: HealthCheckSucceeded: Some message\n" + "* Machine machine-4: Deleting: Machine deletion in progress, stage: DrainingNode\n" + "* Machine machine-3: Some unknown message", }, }, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + g := NewWithT(t) + + var machines collections.Machines + if tt.machines != nil { + machines = collections.FromMachines(tt.machines...) + } + setControlPlaneMachinesReadyCondition(ctx, tt.cluster, machines, tt.getDescendantsSucceeded) + + condition := v1beta2conditions.Get(tt.cluster, clusterv1.ClusterControlPlaneMachinesReadyV1Beta2Condition) + g.Expect(condition).ToNot(BeNil()) + g.Expect(*condition).To(v1beta2conditions.MatchCondition(tt.expectCondition, v1beta2conditions.IgnoreLastTransitionTime(true))) + }) + } +} + +func TestSetWorkerMachinesReadyCondition(t *testing.T) { + readyCondition := metav1.Condition{ + Type: clusterv1.MachineReadyV1Beta2Condition, + Status: metav1.ConditionTrue, + Reason: clusterv1.MachineReadyV1Beta2Reason, + } + + tests := []struct { + name string + cluster *clusterv1.Cluster + machines []*clusterv1.Machine + getDescendantsSucceeded bool + expectCondition metav1.Condition + }{ + { + name: "get descendant failed", + cluster: fakeCluster("c"), + machines: nil, + getDescendantsSucceeded: false, + expectCondition: metav1.Condition{ + Type: clusterv1.ClusterWorkerMachinesReadyV1Beta2Condition, + Status: metav1.ConditionUnknown, + Reason: clusterv1.ClusterWorkerMachinesReadyInternalErrorV1Beta2Reason, + Message: "Please check controller logs for errors", + }, + }, + { + name: "no machines", + cluster: fakeCluster("c"), + machines: []*clusterv1.Machine{}, + getDescendantsSucceeded: true, + expectCondition: metav1.Condition{ + Type: clusterv1.ClusterWorkerMachinesReadyV1Beta2Condition, + Status: metav1.ConditionTrue, + Reason: clusterv1.ClusterWorkerMachinesReadyNoReplicasV1Beta2Reason, + }, + }, + { + name: "all machines are ready", + cluster: fakeCluster("c"), + machines: []*clusterv1.Machine{ + fakeMachine("machine-1", v1beta2Condition(readyCondition)), + fakeMachine("machine-2", v1beta2Condition(readyCondition)), + }, + getDescendantsSucceeded: true, + expectCondition: metav1.Condition{ + Type: clusterv1.ClusterWorkerMachinesReadyV1Beta2Condition, + Status: metav1.ConditionTrue, + Reason: clusterv1.ClusterWorkerMachinesReadyV1Beta2Reason, + }, + }, + { + name: "one ready, one has nothing reported", + cluster: fakeCluster("c"), + machines: []*clusterv1.Machine{ + fakeMachine("machine-1", v1beta2Condition(readyCondition)), + fakeMachine("machine-2"), + }, + getDescendantsSucceeded: true, + expectCondition: metav1.Condition{ + Type: clusterv1.ClusterWorkerMachinesReadyV1Beta2Condition, + Status: metav1.ConditionUnknown, + Reason: clusterv1.ClusterWorkerMachinesReadyUnknownV1Beta2Reason, + Message: "* Machine machine-2: Condition Ready not yet reported", + }, + }, { - name: "control plane goes first", + name: "one ready, one reporting not ready, one reporting unknown, one reporting deleting", cluster: fakeCluster("c"), machines: []*clusterv1.Machine{ fakeMachine("machine-1", v1beta2Condition(readyCondition)), fakeMachine("machine-2", v1beta2Condition(metav1.Condition{ Type: clusterv1.MachineReadyV1Beta2Condition, Status: metav1.ConditionFalse, - Reason: clusterv1.MachineDeletingV1Beta2Reason, - Message: "Deleting: Machine deletion in progress, stage: DrainingNode", + Reason: "SomeReason", + Message: "HealthCheckSucceeded: Some message", })), - fakeMachine("machine-3", controlPlane(true), v1beta2Condition(metav1.Condition{ // control plane always must go first + fakeMachine("machine-3", v1beta2Condition(metav1.Condition{ Type: clusterv1.MachineReadyV1Beta2Condition, Status: metav1.ConditionUnknown, Reason: "SomeUnknownReason", @@ -891,11 +975,12 @@ func TestSetMachinesReadyCondition(t *testing.T) { }, getDescendantsSucceeded: true, expectCondition: metav1.Condition{ - Type: clusterv1.ClusterMachinesReadyV1Beta2Condition, + Type: clusterv1.ClusterWorkerMachinesReadyV1Beta2Condition, Status: metav1.ConditionFalse, - Reason: clusterv1.ClusterMachinesNotReadyV1Beta2Reason, - Message: "* Machine machine-3: Some unknown message\n" + - "* Machines machine-2, machine-4: Deleting: Machine deletion in progress, stage: DrainingNode", + Reason: clusterv1.ClusterWorkerMachinesNotReadyV1Beta2Reason, + Message: "* Machine machine-2: HealthCheckSucceeded: Some message\n" + + "* Machine machine-4: Deleting: Machine deletion in progress, stage: DrainingNode\n" + + "* Machine machine-3: Some unknown message", }, }, } @@ -907,16 +992,174 @@ func TestSetMachinesReadyCondition(t *testing.T) { if tt.machines != nil { machines = collections.FromMachines(tt.machines...) } - setMachinesReadyCondition(ctx, tt.cluster, machines, tt.getDescendantsSucceeded) + setWorkerMachinesReadyCondition(ctx, tt.cluster, machines, tt.getDescendantsSucceeded) - condition := v1beta2conditions.Get(tt.cluster, clusterv1.ClusterMachinesReadyV1Beta2Condition) + condition := v1beta2conditions.Get(tt.cluster, clusterv1.ClusterWorkerMachinesReadyV1Beta2Condition) g.Expect(condition).ToNot(BeNil()) g.Expect(*condition).To(v1beta2conditions.MatchCondition(tt.expectCondition, v1beta2conditions.IgnoreLastTransitionTime(true))) }) } } -func TestSetMachinesUpToDateCondition(t *testing.T) { +func TestSetControlPlaneMachinesUpToDateCondition(t *testing.T) { + tests := []struct { + name string + cluster *clusterv1.Cluster + machines []*clusterv1.Machine + getDescendantsSucceeded bool + expectCondition metav1.Condition + }{ + { + name: "get descendant failed", + cluster: fakeCluster("c"), + machines: nil, + getDescendantsSucceeded: false, + expectCondition: metav1.Condition{ + Type: clusterv1.ClusterControlPlaneMachinesUpToDateV1Beta2Condition, + Status: metav1.ConditionUnknown, + Reason: clusterv1.ClusterControlPlaneMachinesUpToDateInternalErrorV1Beta2Reason, + Message: "Please check controller logs for errors", + }, + }, + { + name: "no machines", + cluster: fakeCluster("c"), + machines: []*clusterv1.Machine{}, + getDescendantsSucceeded: true, + expectCondition: metav1.Condition{ + Type: clusterv1.ClusterControlPlaneMachinesUpToDateV1Beta2Condition, + Status: metav1.ConditionTrue, + Reason: clusterv1.ClusterControlPlaneMachinesUpToDateNoReplicasV1Beta2Reason, + Message: "", + }, + }, + { + name: "One machine up-to-date", + cluster: fakeCluster("c"), + machines: []*clusterv1.Machine{ + fakeMachine("up-to-date-1", controlPlane(true), v1beta2Condition(metav1.Condition{ + Type: clusterv1.MachineUpToDateV1Beta2Condition, + Status: metav1.ConditionTrue, + Reason: "some-reason-1", + })), + }, + getDescendantsSucceeded: true, + expectCondition: metav1.Condition{ + Type: clusterv1.ClusterControlPlaneMachinesUpToDateV1Beta2Condition, + Status: metav1.ConditionTrue, + Reason: clusterv1.ClusterControlPlaneMachinesUpToDateV1Beta2Reason, + Message: "", + }, + }, + { + name: "One machine unknown", + cluster: fakeCluster("c"), + machines: []*clusterv1.Machine{ + fakeMachine("unknown-1", controlPlane(true), v1beta2Condition(metav1.Condition{ + Type: clusterv1.MachineUpToDateV1Beta2Condition, + Status: metav1.ConditionUnknown, + Reason: "some-unknown-reason-1", + Message: "some unknown message", + })), + }, + getDescendantsSucceeded: true, + expectCondition: metav1.Condition{ + Type: clusterv1.ClusterControlPlaneMachinesUpToDateV1Beta2Condition, + Status: metav1.ConditionUnknown, + Reason: clusterv1.ClusterControlPlaneMachinesUpToDateUnknownV1Beta2Reason, + Message: "* Machine unknown-1: some unknown message", + }, + }, + { + name: "One machine not up-to-date", + cluster: fakeCluster("c"), + machines: []*clusterv1.Machine{ + fakeMachine("not-up-to-date-machine-1", controlPlane(true), v1beta2Condition(metav1.Condition{ + Type: clusterv1.MachineUpToDateV1Beta2Condition, + Status: metav1.ConditionFalse, + Reason: "some-not-up-to-date-reason", + Message: "some not up-to-date message", + })), + }, + getDescendantsSucceeded: true, + expectCondition: metav1.Condition{ + Type: clusterv1.ClusterControlPlaneMachinesUpToDateV1Beta2Condition, + Status: metav1.ConditionFalse, + Reason: clusterv1.ClusterControlPlaneMachinesNotUpToDateV1Beta2Reason, + Message: "* Machine not-up-to-date-machine-1: some not up-to-date message", + }, + }, + { + name: "One machine without up-to-date condition, one new Machines without up-to-date condition", + cluster: fakeCluster("c"), + machines: []*clusterv1.Machine{ + fakeMachine("no-condition-machine-1", controlPlane(true)), + fakeMachine("no-condition-machine-2-new", controlPlane(true), creationTimestamp{Time: time.Now().Add(-5 * time.Second)}), // ignored because it's new + }, + getDescendantsSucceeded: true, + expectCondition: metav1.Condition{ + Type: clusterv1.ClusterControlPlaneMachinesUpToDateV1Beta2Condition, + Status: metav1.ConditionUnknown, + Reason: clusterv1.ClusterControlPlaneMachinesUpToDateUnknownV1Beta2Reason, + Message: "* Machine no-condition-machine-1: Condition UpToDate not yet reported", + }, + }, + { + name: "Two machines not up-to-date, two up-to-date, two not reported", + cluster: fakeCluster("c"), + machines: []*clusterv1.Machine{ + fakeMachine("up-to-date-1", controlPlane(true), v1beta2Condition(metav1.Condition{ + Type: clusterv1.MachineUpToDateV1Beta2Condition, + Status: metav1.ConditionTrue, + Reason: "TestUpToDate", + })), + fakeMachine("up-to-date-2", controlPlane(true), v1beta2Condition(metav1.Condition{ + Type: clusterv1.MachineUpToDateV1Beta2Condition, + Status: metav1.ConditionTrue, + Reason: "TestUpToDate", + })), + fakeMachine("not-up-to-date-machine-1", controlPlane(true), v1beta2Condition(metav1.Condition{ + Type: clusterv1.MachineUpToDateV1Beta2Condition, + Status: metav1.ConditionFalse, + Reason: "TestNotUpToDate", + Message: "This is not up-to-date message", + })), + fakeMachine("not-up-to-date-machine-2", controlPlane(true), v1beta2Condition(metav1.Condition{ + Type: clusterv1.MachineUpToDateV1Beta2Condition, + Status: metav1.ConditionFalse, + Reason: "TestNotUpToDate", + Message: "This is not up-to-date message", + })), + fakeMachine("no-condition-machine-1", controlPlane(true)), + fakeMachine("no-condition-machine-2", controlPlane(true)), + }, + getDescendantsSucceeded: true, + expectCondition: metav1.Condition{ + Type: clusterv1.ClusterControlPlaneMachinesUpToDateV1Beta2Condition, + Status: metav1.ConditionFalse, + Reason: clusterv1.ClusterControlPlaneMachinesNotUpToDateV1Beta2Reason, + Message: "* Machines not-up-to-date-machine-1, not-up-to-date-machine-2: This is not up-to-date message\n" + + "* Machines no-condition-machine-1, no-condition-machine-2: Condition UpToDate not yet reported", + }, + }, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + g := NewWithT(t) + + var machines collections.Machines + if tt.machines != nil { + machines = collections.FromMachines(tt.machines...) + } + setControlPlaneMachinesUpToDateCondition(ctx, tt.cluster, machines, tt.getDescendantsSucceeded) + + condition := v1beta2conditions.Get(tt.cluster, clusterv1.ClusterControlPlaneMachinesUpToDateV1Beta2Condition) + g.Expect(condition).ToNot(BeNil()) + g.Expect(*condition).To(v1beta2conditions.MatchCondition(tt.expectCondition, v1beta2conditions.IgnoreLastTransitionTime(true))) + }) + } +} +func TestSetWorkerMachinesUpToDateCondition(t *testing.T) { tests := []struct { name string cluster *clusterv1.Cluster @@ -930,9 +1173,9 @@ func TestSetMachinesUpToDateCondition(t *testing.T) { machines: nil, getDescendantsSucceeded: false, expectCondition: metav1.Condition{ - Type: clusterv1.ClusterMachinesUpToDateV1Beta2Condition, + Type: clusterv1.ClusterWorkerMachinesUpToDateV1Beta2Condition, Status: metav1.ConditionUnknown, - Reason: clusterv1.ClusterMachinesUpToDateInternalErrorV1Beta2Reason, + Reason: clusterv1.ClusterWorkerMachinesUpToDateInternalErrorV1Beta2Reason, Message: "Please check controller logs for errors", }, }, @@ -942,9 +1185,9 @@ func TestSetMachinesUpToDateCondition(t *testing.T) { machines: []*clusterv1.Machine{}, getDescendantsSucceeded: true, expectCondition: metav1.Condition{ - Type: clusterv1.ClusterMachinesUpToDateV1Beta2Condition, + Type: clusterv1.ClusterWorkerMachinesUpToDateV1Beta2Condition, Status: metav1.ConditionTrue, - Reason: clusterv1.ClusterMachinesUpToDateNoReplicasV1Beta2Reason, + Reason: clusterv1.ClusterWorkerMachinesUpToDateNoReplicasV1Beta2Reason, Message: "", }, }, @@ -960,9 +1203,9 @@ func TestSetMachinesUpToDateCondition(t *testing.T) { }, getDescendantsSucceeded: true, expectCondition: metav1.Condition{ - Type: clusterv1.ClusterMachinesUpToDateV1Beta2Condition, + Type: clusterv1.ClusterWorkerMachinesUpToDateV1Beta2Condition, Status: metav1.ConditionTrue, - Reason: clusterv1.ClusterMachinesUpToDateV1Beta2Reason, + Reason: clusterv1.ClusterWorkerMachinesUpToDateV1Beta2Reason, Message: "", }, }, @@ -979,9 +1222,9 @@ func TestSetMachinesUpToDateCondition(t *testing.T) { }, getDescendantsSucceeded: true, expectCondition: metav1.Condition{ - Type: clusterv1.ClusterMachinesUpToDateV1Beta2Condition, + Type: clusterv1.ClusterWorkerMachinesUpToDateV1Beta2Condition, Status: metav1.ConditionUnknown, - Reason: clusterv1.ClusterMachinesUpToDateUnknownV1Beta2Reason, + Reason: clusterv1.ClusterWorkerMachinesUpToDateUnknownV1Beta2Reason, Message: "* Machine unknown-1: some unknown message", }, }, @@ -998,9 +1241,9 @@ func TestSetMachinesUpToDateCondition(t *testing.T) { }, getDescendantsSucceeded: true, expectCondition: metav1.Condition{ - Type: clusterv1.ClusterMachinesUpToDateV1Beta2Condition, + Type: clusterv1.ClusterWorkerMachinesUpToDateV1Beta2Condition, Status: metav1.ConditionFalse, - Reason: clusterv1.ClusterMachinesNotUpToDateV1Beta2Reason, + Reason: clusterv1.ClusterWorkerMachinesNotUpToDateV1Beta2Reason, Message: "* Machine not-up-to-date-machine-1: some not up-to-date message", }, }, @@ -1013,9 +1256,9 @@ func TestSetMachinesUpToDateCondition(t *testing.T) { }, getDescendantsSucceeded: true, expectCondition: metav1.Condition{ - Type: clusterv1.ClusterMachinesUpToDateV1Beta2Condition, + Type: clusterv1.ClusterWorkerMachinesUpToDateV1Beta2Condition, Status: metav1.ConditionUnknown, - Reason: clusterv1.ClusterMachinesUpToDateUnknownV1Beta2Reason, + Reason: clusterv1.ClusterWorkerMachinesUpToDateUnknownV1Beta2Reason, Message: "* Machine no-condition-machine-1: Condition UpToDate not yet reported", }, }, @@ -1050,9 +1293,9 @@ func TestSetMachinesUpToDateCondition(t *testing.T) { }, getDescendantsSucceeded: true, expectCondition: metav1.Condition{ - Type: clusterv1.ClusterMachinesUpToDateV1Beta2Condition, + Type: clusterv1.ClusterWorkerMachinesUpToDateV1Beta2Condition, Status: metav1.ConditionFalse, - Reason: clusterv1.ClusterMachinesNotUpToDateV1Beta2Reason, + Reason: clusterv1.ClusterWorkerMachinesNotUpToDateV1Beta2Reason, Message: "* Machines not-up-to-date-machine-1, not-up-to-date-machine-2: This is not up-to-date message\n" + "* Machines no-condition-machine-1, no-condition-machine-2: Condition UpToDate not yet reported", }, @@ -1066,9 +1309,9 @@ func TestSetMachinesUpToDateCondition(t *testing.T) { if tt.machines != nil { machines = collections.FromMachines(tt.machines...) } - setMachinesUpToDateCondition(ctx, tt.cluster, machines, tt.getDescendantsSucceeded) + setWorkerMachinesUpToDateCondition(ctx, tt.cluster, machines, tt.getDescendantsSucceeded) - condition := v1beta2conditions.Get(tt.cluster, clusterv1.ClusterMachinesUpToDateV1Beta2Condition) + condition := v1beta2conditions.Get(tt.cluster, clusterv1.ClusterWorkerMachinesUpToDateV1Beta2Condition) g.Expect(condition).ToNot(BeNil()) g.Expect(*condition).To(v1beta2conditions.MatchCondition(tt.expectCondition, v1beta2conditions.IgnoreLastTransitionTime(true))) }) diff --git a/util/conditions/v1beta2/sort.go b/util/conditions/v1beta2/sort.go index 4f96fac52cbf..f48a03b8983d 100644 --- a/util/conditions/v1beta2/sort.go +++ b/util/conditions/v1beta2/sort.go @@ -81,8 +81,12 @@ func defaultSortLessFunc(i, j metav1.Condition) bool { // | ScalingDown | x | x | x | x | x | | // | ScalingUp | x | x | x | x | x | | // | -- Aggregated from Machines -- | | | | | | | -// | MachinesReady | x | x | x | x | x | | -// | MachinesUpToDate | x | x | x | x | x | | +// | MachinesReady | | x | x | x | x | | +// | ControlPlaneMachinesReady | x | | | | | | +// | WorkerMachinesReady | x | | | | | | +// | MachinesUpToDate | | x | x | x | x | | +// | ControlPlaneMachinesUpToDate | x | | | | | | +// | WorkerMachinesUpToDate | x | | | | | | // | -- From other controllers -- | | | | | | | // | Readiness/Availability gates | x | | | | | x | // | -- Misc -- | | | | | | | @@ -118,7 +122,11 @@ var order = []string{ clusterv1.ScalingDownV1Beta2Condition, clusterv1.ScalingUpV1Beta2Condition, clusterv1.MachinesReadyV1Beta2Condition, + clusterv1.ClusterControlPlaneMachinesReadyV1Beta2Condition, + clusterv1.ClusterWorkerMachinesReadyV1Beta2Condition, clusterv1.MachinesUpToDateV1Beta2Condition, + clusterv1.ClusterControlPlaneMachinesUpToDateV1Beta2Condition, + clusterv1.ClusterWorkerMachinesUpToDateV1Beta2Condition, readinessAndAvailabilityGates, clusterv1.PausedV1Beta2Condition, clusterv1.DeletingV1Beta2Condition,