Skip to content

Commit

Permalink
cluster: split MachinesUpToDate into ControlPlaneMachinesUpToDate and…
Browse files Browse the repository at this point in the history
… WorkerMachinesUpToDate
  • Loading branch information
chrischdi committed Nov 21, 2024
1 parent bbe8f89 commit 252c757
Show file tree
Hide file tree
Showing 4 changed files with 158 additions and 44 deletions.
54 changes: 40 additions & 14 deletions api/v1beta1/cluster_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ 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 (
// ClusterControlPlaneMachinesReadyV1Beta2Condition surfaces detail of issues on the controlled machines, if any.
ClusterControlPlaneMachinesReadyV1Beta2Condition = "ControlPlaneMachinesReady"
Expand All @@ -242,7 +242,10 @@ const (
// ClusterControlPlaneMachinesReadyInternalErrorV1Beta2Reason surfaces unexpected failures when listing machines
// or aggregating machine's conditions.
ClusterControlPlaneMachinesReadyInternalErrorV1Beta2Reason = InternalErrorV1Beta2Reason
)

// Cluster's WorkerMachinesReady condition and corresponding reasons that will be used in v1Beta2 API version.
const (
// ClusterWorkerMachinesReadyV1Beta2Condition surfaces detail of issues on the controlled machines, if any.
ClusterWorkerMachinesReadyV1Beta2Condition = "WorkerMachinesReady"

Expand All @@ -264,27 +267,50 @@ const (
ClusterWorkerMachinesReadyInternalErrorV1Beta2Reason = InternalErrorV1Beta2Reason
)

// Cluster's MachinesUpToDate condition and corresponding reasons that will be used in v1Beta2 API version.
// Cluster's ControlPlaneMachinesUpToDate condition and corresponding reasons that will be used in v1Beta2 API version.
const (
// ClusterControlPlaneMachinesUpToDateV1Beta2Condition surfaces details of Cluster's machines not up to date, if any.
ClusterControlPlaneMachinesUpToDateV1Beta2Condition = "ControlPlaneMachinesUpToDate"

// ClusterControlPlaneMachinesUpToDateV1Beta2Reason surfaces when all the controlled machine's UpToDate conditions are true.
ClusterControlPlaneMachinesUpToDateV1Beta2Reason = UpToDateV1Beta2Reason

// ClusterControlPlaneMachinesNotUpToDateV1Beta2Reason surfaces when at least one of the controlled machine's UpToDate conditions is false.
ClusterControlPlaneMachinesNotUpToDateV1Beta2Reason = NotUpToDateV1Beta2Reason

// ClusterControlPlaneMachinesUpToDateUnknownV1Beta2Reason 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.
ClusterControlPlaneMachinesUpToDateUnknownV1Beta2Reason = UpToDateUnknownV1Beta2Reason

// ClusterControlPlaneMachinesUpToDateNoReplicasV1Beta2Reason surfaces when no machines exist for the Cluster.
ClusterControlPlaneMachinesUpToDateNoReplicasV1Beta2Reason = NoReplicasV1Beta2Reason

// ClusterControlPlaneMachinesUpToDateInternalErrorV1Beta2Reason surfaces unexpected failures when listing machines
// or aggregating status.
ClusterControlPlaneMachinesUpToDateInternalErrorV1Beta2Reason = InternalErrorV1Beta2Reason
)

// Cluster's WorkerMachinesUpToDate 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
// ClusterWorkerMachinesUpToDateV1Beta2Condition surfaces details of Cluster's machines not up to date, if any.
ClusterWorkerMachinesUpToDateV1Beta2Condition = "WorkerMachinesUpToDate"

// ClusterMachinesUpToDateV1Beta2Reason surfaces when all the controlled machine's UpToDate conditions are true.
ClusterMachinesUpToDateV1Beta2Reason = UpToDateV1Beta2Reason
// ClusterWorkerMachinesUpToDateV1Beta2Reason surfaces when all the controlled machine's UpToDate conditions are true.
ClusterWorkerMachinesUpToDateV1Beta2Reason = UpToDateV1Beta2Reason

// ClusterMachinesNotUpToDateV1Beta2Reason surfaces when at least one of the controlled machine's UpToDate conditions is false.
ClusterMachinesNotUpToDateV1Beta2Reason = NotUpToDateV1Beta2Reason
// ClusterWorkerMachinesNotUpToDateV1Beta2Reason surfaces when at least one of the controlled machine's UpToDate conditions is false.
ClusterWorkerMachinesNotUpToDateV1Beta2Reason = NotUpToDateV1Beta2Reason

// ClusterMachinesUpToDateUnknownV1Beta2Reason surfaces when at least one of the controlled machine's UpToDate conditions is unknown
// ClusterWorkerMachinesUpToDateUnknownV1Beta2Reason 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
ClusterWorkerMachinesUpToDateUnknownV1Beta2Reason = UpToDateUnknownV1Beta2Reason

// ClusterMachinesUpToDateNoReplicasV1Beta2Reason surfaces when no machines exist for the Cluster.
ClusterMachinesUpToDateNoReplicasV1Beta2Reason = NoReplicasV1Beta2Reason
// ClusterWorkerMachinesUpToDateNoReplicasV1Beta2Reason surfaces when no machines exist for the Cluster.
ClusterWorkerMachinesUpToDateNoReplicasV1Beta2Reason = NoReplicasV1Beta2Reason

// ClusterMachinesUpToDateInternalErrorV1Beta2Reason surfaces unexpected failures when listing machines
// ClusterWorkerMachinesUpToDateInternalErrorV1Beta2Reason surfaces unexpected failures when listing machines
// or aggregating status.
ClusterMachinesUpToDateInternalErrorV1Beta2Reason = InternalErrorV1Beta2Reason
ClusterWorkerMachinesUpToDateInternalErrorV1Beta2Reason = InternalErrorV1Beta2Reason
)

// Cluster's RemoteConnectionProbe condition and corresponding reasons that will be used in v1Beta2 API version.
Expand Down
3 changes: 2 additions & 1 deletion internal/controllers/cluster/cluster_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,8 @@ func patchCluster(ctx context.Context, patchHelper *patch.Helper, cluster *clust
clusterv1.ClusterWorkersAvailableV1Beta2Condition,
clusterv1.ClusterControlPlaneMachinesReadyV1Beta2Condition,
clusterv1.ClusterWorkerMachinesReadyV1Beta2Condition,
clusterv1.ClusterMachinesUpToDateV1Beta2Condition,
clusterv1.ClusterControlPlaneMachinesUpToDateV1Beta2Condition,
clusterv1.ClusterWorkerMachinesUpToDateV1Beta2Condition,
clusterv1.ClusterRemoteConnectionProbeV1Beta2Condition,
clusterv1.ClusterScalingUpV1Beta2Condition,
clusterv1.ClusterScalingDownV1Beta2Condition,
Expand Down
49 changes: 36 additions & 13 deletions internal/controllers/cluster/cluster_controller_status.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ 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))
Expand Down Expand Up @@ -82,7 +81,22 @@ func (r *Reconciler) updateStatus(ctx context.Context, s *scope) {
readyUnknownReason: clusterv1.ClusterWorkerMachinesReadyUnknownV1Beta2Reason,
readyReason: clusterv1.ClusterWorkerMachinesReadyV1Beta2Reason,
}.setMachinesReadyCondition(ctx, s.cluster, workerMachines, s.getDescendantsSucceeded)
setMachinesUpToDateCondition(ctx, s.cluster, allMachines, s.getDescendantsSucceeded)
machinesUpToDateSetter{
condition: clusterv1.ClusterControlPlaneMachinesUpToDateV1Beta2Condition,
internalErrorReason: clusterv1.ClusterControlPlaneMachinesUpToDateInternalErrorV1Beta2Reason,
noReplicasReason: clusterv1.ClusterControlPlaneMachinesUpToDateNoReplicasV1Beta2Reason,
notUpToDateReason: clusterv1.ClusterControlPlaneMachinesNotUpToDateV1Beta2Reason,
upToDateUnknownReason: clusterv1.ClusterControlPlaneMachinesUpToDateUnknownV1Beta2Reason,
upToDateReason: clusterv1.ClusterControlPlaneMachinesUpToDateV1Beta2Reason,
}.setMachinesUpToDateCondition(ctx, s.cluster, controlPlaneMachines, s.getDescendantsSucceeded)
machinesUpToDateSetter{
condition: clusterv1.ClusterWorkerMachinesUpToDateV1Beta2Condition,
internalErrorReason: clusterv1.ClusterWorkerMachinesUpToDateInternalErrorV1Beta2Reason,
noReplicasReason: clusterv1.ClusterWorkerMachinesUpToDateNoReplicasV1Beta2Reason,
notUpToDateReason: clusterv1.ClusterWorkerMachinesNotUpToDateV1Beta2Reason,
upToDateUnknownReason: clusterv1.ClusterWorkerMachinesUpToDateUnknownV1Beta2Reason,
upToDateReason: clusterv1.ClusterWorkerMachinesUpToDateV1Beta2Reason,
}.setMachinesUpToDateCondition(ctx, s.cluster, workerMachines, 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)
setRemediatingCondition(ctx, s.cluster, machinesToBeRemediated, unhealthyMachines, s.getDescendantsSucceeded)
Expand Down Expand Up @@ -678,15 +692,24 @@ func (s machinesReadySetter) setMachinesReadyCondition(ctx context.Context, clus
v1beta2conditions.Set(cluster, *machinesReadyCondition)
}

func setMachinesUpToDateCondition(ctx context.Context, cluster *clusterv1.Cluster, machines collections.Machines, getDescendantsSucceeded bool) {
type machinesUpToDateSetter struct {
condition string
internalErrorReason string
noReplicasReason string
notUpToDateReason string
upToDateUnknownReason string
upToDateReason string
}

func (s machinesUpToDateSetter) setMachinesUpToDateCondition(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 !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
Expand All @@ -701,33 +724,33 @@ func setMachinesUpToDateCondition(ctx context.Context, cluster *clusterv1.Cluste

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),
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.notUpToDateReason,
s.upToDateUnknownReason,
s.upToDateReason,
)),
),
},
)
if err != nil {
log.Error(err, "Failed to aggregate Machine's UpToDate conditions")
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
Expand Down
Loading

0 comments on commit 252c757

Please sign in to comment.