Skip to content

Commit f8a2970

Browse files
authored
Merge pull request #11338 from fabriziopandini/update-v1beta2-status-md-controller
✨ Add v1beta2 condition to MD controller
2 parents 7c0dd0c + 24b2644 commit f8a2970

16 files changed

+2013
-89
lines changed

api/v1beta1/machinedeployment_types.go

Lines changed: 123 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,129 @@ const (
7777
MachineDeploymentUniqueLabel = "machine-template-hash"
7878
)
7979

80+
// MachineDeployment's Available condition and corresponding reasons that will be used in v1Beta2 API version.
81+
const (
82+
// MachineDeploymentAvailableV1Beta2Condition is true if the MachineDeployment is not deleted, and it has minimum
83+
// availability according to parameters specified in the deployment strategy, e.g. If using RollingUpgrade strategy,
84+
// availableReplicas must be greater or equal than desired replicas - MaxUnavailable replicas.
85+
MachineDeploymentAvailableV1Beta2Condition = AvailableV1Beta2Condition
86+
87+
// MachineDeploymentAvailableWaitingForReplicasSetV1Beta2Reason surfaces when the .spec.replicas
88+
// field of the MachineDeployment is not set.
89+
MachineDeploymentAvailableWaitingForReplicasSetV1Beta2Reason = WaitingForReplicasSetV1Beta2Reason
90+
91+
// MachineDeploymentAvailableWaitingForAvailableReplicasSetV1Beta2Reason surfaces when the .status.v1beta2.availableReplicas
92+
// field of the MachineDeployment is not set.
93+
MachineDeploymentAvailableWaitingForAvailableReplicasSetV1Beta2Reason = "WaitingForAvailableReplicasSet"
94+
95+
// MachineDeploymentAvailableV1Beta2Reason surfaces when a Deployment is available.
96+
MachineDeploymentAvailableV1Beta2Reason = AvailableV1Beta2Reason
97+
98+
// MachineDeploymentNotAvailableV1Beta2Reason surfaces when a Deployment is not available.
99+
MachineDeploymentNotAvailableV1Beta2Reason = NotAvailableV1Beta2Reason
100+
101+
// MachineDeploymentAvailableInternalErrorV1Beta2Reason surfaces unexpected failures when computing the Available condition.
102+
MachineDeploymentAvailableInternalErrorV1Beta2Reason = InternalErrorV1Beta2Reason
103+
)
104+
105+
// MachineDeployment's MachinesReady condition and corresponding reasons that will be used in v1Beta2 API version.
106+
const (
107+
// MachineDeploymentMachinesReadyV1Beta2Condition surfaces detail of issues on the controlled machines, if any.
108+
MachineDeploymentMachinesReadyV1Beta2Condition = MachinesReadyV1Beta2Condition
109+
110+
// MachineDeploymentMachinesReadyNoReplicasV1Beta2Reason surfaces when no machines exist for the MachineDeployment.
111+
MachineDeploymentMachinesReadyNoReplicasV1Beta2Reason = NoReplicasV1Beta2Reason
112+
113+
// MachineDeploymentMachinesReadyInternalErrorV1Beta2Reason surfaces unexpected failures when listing machines
114+
// or aggregating machine's conditions.
115+
MachineDeploymentMachinesReadyInternalErrorV1Beta2Reason = InternalErrorV1Beta2Reason
116+
)
117+
118+
// MachineDeployment's MachinesUpToDate condition and corresponding reasons that will be used in v1Beta2 API version.
119+
const (
120+
// MachineDeploymentMachinesUpToDateV1Beta2Condition surfaces details of controlled machines not up to date, if any.
121+
MachineDeploymentMachinesUpToDateV1Beta2Condition = MachinesUpToDateV1Beta2Condition
122+
123+
// MachineDeploymentMachinesUpToDateNoReplicasV1Beta2Reason surfaces when no machines exist for the MachineDeployment.
124+
MachineDeploymentMachinesUpToDateNoReplicasV1Beta2Reason = NoReplicasV1Beta2Reason
125+
126+
// MachineDeploymentMachinesUpToDateInternalErrorV1Beta2Reason surfaces unexpected failures when listing machines
127+
// or aggregating status.
128+
MachineDeploymentMachinesUpToDateInternalErrorV1Beta2Reason = InternalErrorV1Beta2Reason
129+
)
130+
131+
// MachineDeployment's ScalingUp condition and corresponding reasons that will be used in v1Beta2 API version.
132+
const (
133+
// MachineDeploymentScalingUpV1Beta2Condition is true if actual replicas < desired replicas.
134+
MachineDeploymentScalingUpV1Beta2Condition = ScalingUpV1Beta2Condition
135+
136+
// MachineDeploymentScalingUpV1Beta2Reason surfaces when actual replicas < desired replicas.
137+
MachineDeploymentScalingUpV1Beta2Reason = ScalingUpV1Beta2Reason
138+
139+
// MachineDeploymentNotScalingUpV1Beta2Reason surfaces when actual replicas >= desired replicas.
140+
MachineDeploymentNotScalingUpV1Beta2Reason = NotScalingUpV1Beta2Reason
141+
142+
// MachineDeploymentScalingUpInternalErrorV1Beta2Reason surfaces unexpected failures when listing machines.
143+
MachineDeploymentScalingUpInternalErrorV1Beta2Reason = InternalErrorV1Beta2Reason
144+
145+
// MachineDeploymentScalingUpWaitingForReplicasSetV1Beta2Reason surfaces when the .spec.replicas
146+
// field of the MachineDeployment is not set.
147+
MachineDeploymentScalingUpWaitingForReplicasSetV1Beta2Reason = WaitingForReplicasSetV1Beta2Reason
148+
)
149+
150+
// MachineDeployment's ScalingDown condition and corresponding reasons that will be used in v1Beta2 API version.
151+
const (
152+
// MachineDeploymentScalingDownV1Beta2Condition is true if actual replicas > desired replicas.
153+
MachineDeploymentScalingDownV1Beta2Condition = ScalingDownV1Beta2Condition
154+
155+
// MachineDeploymentScalingDownV1Beta2Reason surfaces when actual replicas > desired replicas.
156+
MachineDeploymentScalingDownV1Beta2Reason = ScalingDownV1Beta2Reason
157+
158+
// MachineDeploymentNotScalingDownV1Beta2Reason surfaces when actual replicas <= desired replicas.
159+
MachineDeploymentNotScalingDownV1Beta2Reason = NotScalingDownV1Beta2Reason
160+
161+
// MachineDeploymentScalingDownInternalErrorV1Beta2Reason surfaces unexpected failures when listing machines.
162+
MachineDeploymentScalingDownInternalErrorV1Beta2Reason = InternalErrorV1Beta2Reason
163+
164+
// MachineDeploymentScalingDownWaitingForReplicasSetV1Beta2Reason surfaces when the .spec.replicas
165+
// field of the MachineDeployment is not set.
166+
MachineDeploymentScalingDownWaitingForReplicasSetV1Beta2Reason = WaitingForReplicasSetV1Beta2Reason
167+
)
168+
169+
// MachineDeployment's Remediating condition and corresponding reasons that will be used in v1Beta2 API version.
170+
const (
171+
// MachineDeploymentRemediatingV1Beta2Condition surfaces details about ongoing remediation of the controlled machines, if any.
172+
MachineDeploymentRemediatingV1Beta2Condition = RemediatingV1Beta2Condition
173+
174+
// MachineDeploymentRemediatingV1Beta2Reason surfaces when the MachineDeployment has at least one machine with HealthCheckSucceeded set to false
175+
// and with the OwnerRemediated condition set to false.
176+
MachineDeploymentRemediatingV1Beta2Reason = RemediatingV1Beta2Reason
177+
178+
// MachineDeploymentNotRemediatingV1Beta2Reason surfaces when the MachineDeployment does not have any machine with HealthCheckSucceeded set to false
179+
// and with the OwnerRemediated condition set to false.
180+
MachineDeploymentNotRemediatingV1Beta2Reason = NotRemediatingV1Beta2Reason
181+
182+
// MachineDeploymentRemediatingInternalErrorV1Beta2Reason surfaces unexpected failures when computing the Remediating condition.
183+
MachineDeploymentRemediatingInternalErrorV1Beta2Reason = InternalErrorV1Beta2Reason
184+
)
185+
186+
// MachineDeployment's Deleting condition and corresponding reasons that will be used in v1Beta2 API version.
187+
const (
188+
// MachineDeploymentDeletingV1Beta2Condition surfaces details about ongoing deletion of the controlled machines.
189+
MachineDeploymentDeletingV1Beta2Condition = DeletingV1Beta2Condition
190+
191+
// MachineDeploymentDeletingDeletionTimestampNotSetV1Beta2Reason surfaces when the MachineDeployment is not deleting because the
192+
// DeletionTimestamp is not set.
193+
MachineDeploymentDeletingDeletionTimestampNotSetV1Beta2Reason = DeletionTimestampNotSetV1Beta2Reason
194+
195+
// MachineDeploymentDeletingDeletionTimestampSetV1Beta2Reason surfaces when the MachineDeployment is deleting because the
196+
// DeletionTimestamp is set.
197+
MachineDeploymentDeletingDeletionTimestampSetV1Beta2Reason = DeletionTimestampSetV1Beta2Reason
198+
199+
// MachineDeploymentDeletingInternalErrorV1Beta2Reason surfaces unexpected failures when deleting a MachineDeployment.
200+
MachineDeploymentDeletingInternalErrorV1Beta2Reason = InternalErrorV1Beta2Reason
201+
)
202+
80203
// ANCHOR: MachineDeploymentSpec
81204

82205
// MachineDeploymentSpec defines the desired state of MachineDeployment.

api/v1beta1/v1beta2_condition_consts.go

Lines changed: 3 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,9 @@ const (
9090
// AvailableV1Beta2Reason applies to a condition surfacing object availability.
9191
AvailableV1Beta2Reason = "Available"
9292

93+
// NotAvailableV1Beta2Reason applies to a condition surfacing object not satisfying availability criteria.
94+
NotAvailableV1Beta2Reason = "NotAvailable"
95+
9396
// ScalingUpV1Beta2Reason surfaces when an object is scaling up.
9497
ScalingUpV1Beta2Reason = "ScalingUp"
9598

@@ -163,32 +166,6 @@ const (
163166
InspectionFailedV1Beta2Reason = "InspectionFailed"
164167
)
165168

166-
// Conditions that will be used for the MachineDeployment object in v1Beta2 API version.
167-
const (
168-
// MachineDeploymentAvailableV1Beta2Condition is true if the MachineDeployment is not deleted, and it has minimum
169-
// availability according to parameters specified in the deployment strategy, e.g. If using RollingUpgrade strategy,
170-
// availableReplicas must be greater or equal than desired replicas - MaxUnavailable replicas.
171-
MachineDeploymentAvailableV1Beta2Condition = AvailableV1Beta2Condition
172-
173-
// MachineDeploymentMachinesReadyV1Beta2Condition surfaces detail of issues on the controlled machines, if any.
174-
MachineDeploymentMachinesReadyV1Beta2Condition = MachinesReadyV1Beta2Condition
175-
176-
// MachineDeploymentMachinesUpToDateV1Beta2Condition surfaces details of controlled machines not up to date, if any.
177-
MachineDeploymentMachinesUpToDateV1Beta2Condition = MachinesUpToDateV1Beta2Condition
178-
179-
// MachineDeploymentScalingUpV1Beta2Condition is true if available replicas < desired replicas.
180-
MachineDeploymentScalingUpV1Beta2Condition = ScalingUpV1Beta2Condition
181-
182-
// MachineDeploymentScalingDownV1Beta2Condition is true if replicas > desired replicas.
183-
MachineDeploymentScalingDownV1Beta2Condition = ScalingDownV1Beta2Condition
184-
185-
// MachineDeploymentRemediatingV1Beta2Condition details about ongoing remediation of the controlled machines, if any.
186-
MachineDeploymentRemediatingV1Beta2Condition = RemediatingV1Beta2Condition
187-
188-
// MachineDeploymentDeletingV1Beta2Condition surfaces details about ongoing deletion of the controlled machines.
189-
MachineDeploymentDeletingV1Beta2Condition = DeletingV1Beta2Condition
190-
)
191-
192169
// Conditions that will be used for the Cluster object in v1Beta2 API version.
193170
const (
194171
// ClusterAvailableV1Beta2Condition is true if the Cluster's is not deleted, and RemoteConnectionProbe, InfrastructureReady,

controlplane/kubeadm/api/v1beta1/v1beta2_condition_consts.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -176,11 +176,11 @@ const (
176176
// Note: KubeadmControlPlane only remediates machines with HealthCheckSucceeded set to false and with the OwnerRemediated condition set to false.
177177
KubeadmControlPlaneRemediatingV1Beta2Condition = clusterv1.RemediatingV1Beta2Condition
178178

179-
// KubeadmControlPlaneRemediatingV1Beta2Reason surfaces when kcp has at least one machine with HealthCheckSucceeded set to false
179+
// KubeadmControlPlaneRemediatingV1Beta2Reason surfaces when the KubeadmControlPlane has at least one machine with HealthCheckSucceeded set to false
180180
// and with the OwnerRemediated condition set to false.
181181
KubeadmControlPlaneRemediatingV1Beta2Reason = clusterv1.RemediatingV1Beta2Reason
182182

183-
// KubeadmControlPlaneNotRemediatingV1Beta2Reason surfaces when kcp does not have any machine with HealthCheckSucceeded set to false
183+
// KubeadmControlPlaneNotRemediatingV1Beta2Reason surfaces when the KubeadmControlPlane does not have any machine with HealthCheckSucceeded set to false
184184
// and with the OwnerRemediated condition set to false.
185185
KubeadmControlPlaneNotRemediatingV1Beta2Reason = clusterv1.NotRemediatingV1Beta2Reason
186186

controlplane/kubeadm/internal/controllers/status.go

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,8 @@ import (
3737
clog "sigs.k8s.io/cluster-api/util/log"
3838
)
3939

40-
// updateStatus is called after every reconcilitation loop in a defer statement to always make sure we have the
41-
// resource status subresourcs up-to-date.
40+
// updateStatus is called after every reconciliation loop in a defer statement to always make sure we have the
41+
// KubeadmControlPlane status up-to-date.
4242
func (r *KubeadmControlPlaneReconciler) updateStatus(ctx context.Context, controlPlane *internal.ControlPlane) error {
4343
selector := collections.ControlPlaneSelectorForCluster(controlPlane.Cluster.Name)
4444
// Copy label selector to its status counterpart in string format.
@@ -398,7 +398,6 @@ func setRemediatingCondition(ctx context.Context, kcp *controlplanev1.KubeadmCon
398398
return
399399
}
400400

401-
// TODO: Bring together externally remediated machines and owner remediated machines
402401
remediatingCondition, err := v1beta2conditions.NewAggregateCondition(
403402
machinesToBeRemediated.UnsortedList(), clusterv1.MachineOwnerRemediatedV1Beta2Condition,
404403
v1beta2conditions.TargetConditionType(controlplanev1.KubeadmControlPlaneRemediatingV1Beta2Condition),
@@ -425,6 +424,10 @@ func setRemediatingCondition(ctx context.Context, kcp *controlplanev1.KubeadmCon
425424
}
426425

427426
func aggregateStaleMachines(machines collections.Machines) string {
427+
if len(machines) == 0 {
428+
return ""
429+
}
430+
428431
machineNames := []string{}
429432
for _, machine := range machines {
430433
if !machine.GetDeletionTimestamp().IsZero() && time.Since(machine.GetDeletionTimestamp().Time) > time.Minute*30 {
@@ -455,6 +458,10 @@ func aggregateStaleMachines(machines collections.Machines) string {
455458
}
456459

457460
func aggregateUnhealthyMachines(machines collections.Machines) string {
461+
if len(machines) == 0 {
462+
return ""
463+
}
464+
458465
machineNames := []string{}
459466
for _, machine := range machines {
460467
machineNames = append(machineNames, machine.GetName())

internal/controllers/machine/machine_controller.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,7 @@ func (r *Reconciler) Reconcile(ctx context.Context, req ctrl.Request) (_ ctrl.Re
229229
}
230230

231231
defer func() {
232-
r.reconcileStatus(ctx, s)
232+
r.updateStatus(ctx, s)
233233

234234
// Always attempt to patch the object and status after each reconciliation.
235235
// Patch ObservedGeneration only if the reconciliation completed successfully

internal/controllers/machine/machine_controller_status.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,13 +38,13 @@ import (
3838
v1beta2conditions "sigs.k8s.io/cluster-api/util/conditions/v1beta2"
3939
)
4040

41-
// reconcileStatus reconciles Machine's status during the entire lifecycle of the machine.
41+
// updateStatus update Machine's status.
4242
// This implies that the code in this function should account for several edge cases e.g. machine being partially provisioned,
4343
// machine being partially deleted but also for running machines being disrupted e.g. by deleting the node.
4444
// Additionally, this func should ensure that the conditions managed by this controller are always set in order to
4545
// comply with the recommendation in the Kubernetes API guidelines.
4646
// Note: v1beta1 conditions are not managed by this func.
47-
func (r *Reconciler) reconcileStatus(ctx context.Context, s *scope) {
47+
func (r *Reconciler) updateStatus(ctx context.Context, s *scope) {
4848
// Update status from the Bootstrap Config external resource.
4949
// Note: some of the status fields derived from the Bootstrap Config are managed in reconcileBootstrap, e.g. status.BootstrapReady, etc.
5050
// here we are taking care only of the delta (condition).

0 commit comments

Comments
 (0)