Skip to content

Commit 917cab3

Browse files
update status with v1beta2 conditions
1 parent b836e45 commit 917cab3

13 files changed

+1452
-672
lines changed

api/v1beta1/machine_types.go

+136
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,142 @@ const (
8686
ManagedNodeLabelDomain = "node.cluster.x-k8s.io"
8787
)
8888

89+
// Machine's Available condition and corresponding reasons that will be used in v1Beta2 API version.
90+
const (
91+
// MachineAvailableV1Beta2Condition is true if the machine is Ready for at least MinReadySeconds, as defined by the Machine's MinReadySeconds field.
92+
MachineAvailableV1Beta2Condition = AvailableV1Beta2Condition
93+
94+
// MachineNotReadyV1Beta2Reason surfaces when a machine is not yet ready (and thus not yet available).
95+
MachineNotReadyV1Beta2Reason = "NotReady"
96+
97+
// MachineWaitingForMinReadySecondsV1Beta2Reason surfaces when a machine is ready for less then MinReadySeconds (and thus not yet available).
98+
MachineWaitingForMinReadySecondsV1Beta2Reason = "WaitingForMinReadySeconds"
99+
100+
// MachineReadyNotYetReportedV1Beta2Reason surfaces when a machine ready is not reported yet.
101+
// Note: this should never happen and it is a signal of some internal error.
102+
MachineReadyNotYetReportedV1Beta2Reason = "ReadyNotYetReported"
103+
104+
// MachineAvailableV1Beta2Reason surfaces when a machine ready for at least MinReadySeconds.
105+
MachineAvailableV1Beta2Reason = "MachineAvailable"
106+
)
107+
108+
// Machine's Ready condition and corresponding reasons that will be used in v1Beta2 API version.
109+
// Note: when possible, Ready condition will use reasons from the conditions it summarizes.
110+
const (
111+
// MachineReadyV1Beta2Condition is true if the Machine is not deleted, Machine's BootstrapConfigReady, InfrastructureReady,
112+
// NodeHealthy and HealthCheckSucceeded (if present) are true; if other conditions are defined in spec.readinessGates,
113+
// these conditions must be true as well.
114+
MachineReadyV1Beta2Condition = ReadyV1Beta2Condition
115+
116+
// MachineErrorComputingReadyV1Beta2Reason surfaces when there was an error computing the ready condition.
117+
// Note: this should never happen and it is a signal of some internal error.
118+
MachineErrorComputingReadyV1Beta2Reason = "ErrorComputingReady"
119+
)
120+
121+
// Machine's UpToDate condition and corresponding reasons that will be used in v1Beta2 API version.
122+
// Note: UpToDate condition is set by the controller owning the machine.
123+
const (
124+
// MachineUpToDateV1Beta2Condition is true if the Machine spec matches the spec of the Machine's owner resource, e.g. KubeadmControlPlane or MachineDeployment.
125+
// The Machine's owner (e.g MachineDeployment) is authoritative to set their owned Machine's UpToDate conditions based on its current spec.
126+
MachineUpToDateV1Beta2Condition = "UpToDate"
127+
)
128+
129+
// Machine's BootstrapConfigReady condition and corresponding reasons that will be used in v1Beta2 API version.
130+
// Note: when possible, BootstrapConfigReady condition will use reasons surfaced from the underlying bootstrap config object.
131+
const (
132+
// MachineBootstrapConfigReadyV1Beta2Condition condition mirrors the corresponding Ready condition from the Machine's BootstrapConfig resource.
133+
MachineBootstrapConfigReadyV1Beta2Condition = BootstrapConfigReadyV1Beta2Condition
134+
135+
// MachineBootstrapDataSecretDataSecretUserProvidedV1Beta2Reason surfaces when a bootstrap data secret is provided by the user (without a ConfigRef).
136+
MachineBootstrapDataSecretDataSecretUserProvidedV1Beta2Reason = "DataSecretUserProvided"
137+
138+
// MachineBootstrapInvalidConfigV1Beta2Reason surfaces when MachineBootstrap doesn't have the Boostrap.ConfigRef nor a
139+
// Bootstrap.DataSecretName specified by the users.
140+
MachineBootstrapInvalidConfigV1Beta2Reason = "InvalidConfig"
141+
142+
// MachineBootstrapConfigInvalidConditionReportedV1Beta2Reason surfaces a BootstrapConfig Ready condition (read from a bootstrap config object) which is invalid.
143+
// (e.g. it is status is missing).
144+
MachineBootstrapConfigInvalidConditionReportedV1Beta2Reason = InvalidConditionReported
145+
146+
// MachineBootstrapConfigReadyNoV1Beta2ReasonReported applies to a BootstrapConfig Ready condition (read from a bootstrap config object) that reports no reason.
147+
MachineBootstrapConfigReadyNoV1Beta2ReasonReported = NoV1Beta2ReasonReported
148+
149+
// MachineBootstrapConfigNotFoundV1Beta2Reason surfaces when a referenced bootstrap config object cannot be found.
150+
// Note: this could happen when creating the machine. However, this state should be treated as an error if it last indefinitely.
151+
MachineBootstrapConfigNotFoundV1Beta2Reason = RefObjectNotFoundV1Beta2Reason
152+
153+
// MachineBootstrapConfigDeletedV1Beta2Reason surfaces when a referenced bootstrap config object has been deleted.
154+
// Note: controllers can't identify if the deletion process has been initiated by the controller itself, e.g.
155+
// during the deletion workflow, or by a users.
156+
MachineBootstrapConfigDeletedV1Beta2Reason = RefObjectDeletedV1Beta2Reason
157+
)
158+
159+
// Machine's InfrastructureReady condition and corresponding reasons that will be used in v1Beta2 API version.
160+
// Note: when possible, InfrastructureReady condition will use reasons surfaced from the underlying infra machine object.
161+
const (
162+
// MachineInfrastructureReadyV1Beta2Condition mirrors the corresponding Ready condition from the Machine's Infrastructure resource.
163+
MachineInfrastructureReadyV1Beta2Condition = InfrastructureReadyV1Beta2Condition
164+
165+
// MachineInfrastructureInvalidConditionReportedV1Beta2Reason surfaces a infrastructure Ready condition (read from an infra machine object) which is invalid.
166+
// (e.g. it is status is missing).
167+
MachineInfrastructureInvalidConditionReportedV1Beta2Reason = InvalidConditionReported
168+
169+
// MachineInfrastructureReadyNoV1Beta2ReasonReported applies to a infrastructure Ready condition (read from an infra machine object) that reports no reason.
170+
MachineInfrastructureReadyNoV1Beta2ReasonReported = NoV1Beta2ReasonReported
171+
172+
// MachineInfrastructureNotFoundV1Beta2Reason surfaces when a referenced infrastructure object cannot be found.
173+
// Note: this could happen when creating the machine. However, this state should be treated as an error if it last indefinitely.
174+
MachineInfrastructureNotFoundV1Beta2Reason = RefObjectNotFoundV1Beta2Reason
175+
176+
// MachineInfrastructureDeletedV1Beta2Reason surfaces when a referenced infrastructure object has been deleted.
177+
// Note: controllers can't identify if the deletion process has been initiated by the controller itself, e.g.
178+
// during the deletion workflow, or by a users.
179+
MachineInfrastructureDeletedV1Beta2Reason = RefObjectDeletedV1Beta2Reason
180+
)
181+
182+
// Machine's NodeHealthy and NodeReady conditions and corresponding reasons that will be used in v1Beta2 API version.
183+
// Note: when possible, NodeHealthy and NodeReady conditions will use reasons surfaced from the underlying node.
184+
const (
185+
// MachineNodeHealthyV1Beta2Condition is true if the Machine's Node is ready and it does not report MemoryPressure, DiskPressure and PIDPressure.
186+
MachineNodeHealthyV1Beta2Condition = "NodeHealthy"
187+
188+
// MachineNodeReadyV1Beta2Condition is true if the Machine's Node is ready.
189+
MachineNodeReadyV1Beta2Condition = "NodeReady"
190+
191+
// MachineNodeNotFoundV1Beta2Reason surfaces when the node hosted on the machine cannot be found.
192+
// Note: this could happen when creating the machine. However, this state should be treated as an error if it last indefinitely.
193+
MachineNodeNotFoundV1Beta2Reason = "NodeNotFound"
194+
195+
// MachineNodeDeletedV1Beta2Reason surfaces when the node hosted on the machine has been deleted.
196+
// Note: controllers can't identify if the deletion process has been initiated by the controller itself, e.g.
197+
// during the deletion workflow, or by a users.
198+
MachineNodeDeletedV1Beta2Reason = "NodeDeleted"
199+
)
200+
201+
// Machine's HealthCheckSucceeded and OwnerRemediated conditions and corresponding reasons that will be used in v1Beta2 API version.
202+
// Note: HealthCheckSucceeded and OwnerRemediated condition are set by the MachineHealthCheck controller.
203+
const (
204+
// MachineHealthCheckSucceededV1Beta2Condition is true if MHC instances targeting this machine report the Machine
205+
// is healthy according to the definition of healthy present in the spec of the MachineHealthCheck object.
206+
MachineHealthCheckSucceededV1Beta2Condition = "HealthCheckSucceeded"
207+
208+
// MachineOwnerRemediatedV1Beta2Condition is only present if MHC instances targeting this machine
209+
// determine that the controller owning this machine should perform remediation.
210+
MachineOwnerRemediatedV1Beta2Condition = "OwnerRemediated"
211+
)
212+
213+
// Machine's Deleting condition and corresponding reasons that will be used in v1Beta2 API version.
214+
const (
215+
// MachineDeletingV1Beta2Condition surfaces details about progress in the machine deletion workflow.
216+
MachineDeletingV1Beta2Condition = DeletingV1Beta2Condition
217+
)
218+
219+
// Machine's Paused condition and corresponding reasons that will be used in v1Beta2 API version.
220+
const (
221+
// MachinePausedV1Beta2Condition is true if the Machine or the Cluster it belongs to are paused.
222+
MachinePausedV1Beta2Condition = PausedV1Beta2Condition
223+
)
224+
89225
// ANCHOR: MachineSpec
90226

91227
// MachineSpec defines the desired state of Machine.

api/v1beta1/v1beta2_condition_consts.go

+13-35
Original file line numberDiff line numberDiff line change
@@ -85,45 +85,23 @@ const (
8585
PausedV1Beta2Condition = "Paused"
8686
)
8787

88-
// Conditions that will be used for the Machine object in v1Beta2 API version.
88+
// Reasons that are used across different objects.
8989
const (
90-
// MachineAvailableV1Beta2Condition is true if the machine is Ready for at least MinReadySeconds, as defined by the Machine's MinReadySeconds field.
91-
MachineAvailableV1Beta2Condition = AvailableV1Beta2Condition
90+
// InvalidConditionReported applies to a condition, usually read from an external object, that is invalid
91+
// (e.g. it is status is missing).
92+
InvalidConditionReported = "InvalidConditionReported"
9293

93-
// MachineReadyV1Beta2Condition is true if the Machine is not deleted, Machine's BootstrapConfigReady, InfrastructureReady,
94-
// NodeHealthy and HealthCheckSucceeded (if present) are true; if other conditions are defined in spec.readinessGates,
95-
// these conditions must be true as well.
96-
MachineReadyV1Beta2Condition = ReadyV1Beta2Condition
94+
// NoV1Beta2ReasonReported applies to a condition, usually read from an external object, that reports no reason.
95+
// Note: this could happen e.g. when an external object still uses Cluster API v1beta1 Conditions.
96+
NoV1Beta2ReasonReported = "NoReasonReported"
9797

98-
// MachineUpToDateV1Beta2Condition is true if the Machine spec matches the spec of the Machine's owner resource, e.g. KubeadmControlPlane or MachineDeployment.
99-
// The Machine's owner (e.g MachineDeployment) is authoritative to set their owned Machine's UpToDate conditions based on its current spec.
100-
MachineUpToDateV1Beta2Condition = "UpToDate"
98+
// RefObjectNotFoundV1Beta2Reason surfaces when a referenced object cannot be found.
99+
RefObjectNotFoundV1Beta2Reason = "RefObjectNotFound"
101100

102-
// MachineBootstrapConfigReadyV1Beta2Condition condition mirrors the corresponding Ready condition from the Machine's BootstrapConfig resource.
103-
MachineBootstrapConfigReadyV1Beta2Condition = BootstrapConfigReadyV1Beta2Condition
104-
105-
// MachineInfrastructureReadyV1Beta2Condition mirrors the corresponding Ready condition from the Machine's Infrastructure resource.
106-
MachineInfrastructureReadyV1Beta2Condition = InfrastructureReadyV1Beta2Condition
107-
108-
// MachineNodeHealthyV1Beta2Condition is true if the Machine's Node is ready and it does not report MemoryPressure, DiskPressure and PIDPressure.
109-
MachineNodeHealthyV1Beta2Condition = "NodeHealthy"
110-
111-
// MachineNodeReadyV1Beta2Condition is true if the Machine's Node is ready.
112-
MachineNodeReadyV1Beta2Condition = "NodeReady"
113-
114-
// MachineHealthCheckSucceededV1Beta2Condition is true if MHC instances targeting this machine report the Machine
115-
// is healthy according to the definition of healthy present in the spec of the MachineHealthCheck object.
116-
MachineHealthCheckSucceededV1Beta2Condition = "HealthCheckSucceeded"
117-
118-
// MachineOwnerRemediatedV1Beta2Condition is only present if MHC instances targeting this machine
119-
// determine that the controller owning this machine should perform remediation.
120-
MachineOwnerRemediatedV1Beta2Condition = "OwnerRemediated"
121-
122-
// MachineDeletingV1Beta2Condition surfaces details about progress in the machine deletion workflow.
123-
MachineDeletingV1Beta2Condition = DeletingV1Beta2Condition
124-
125-
// MachinePausedV1Beta2Condition is true if the Machine or the Cluster it belongs to are paused.
126-
MachinePausedV1Beta2Condition = PausedV1Beta2Condition
101+
// RefObjectDeletedV1Beta2Reason surfaces when a referenced object has been deleted.
102+
// Note: controllers can't identify if the deletion process has been initiated by the controller itself, e.g.
103+
// during the deletion workflow, or by a users.
104+
RefObjectDeletedV1Beta2Reason = "RefObjectDeleted"
127105
)
128106

129107
// Conditions that will be used for the MachineSet object in v1Beta2 API version.

internal/contract/bootstrap.go

+5
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,11 @@ func (b *BootstrapContract) Ready() *Bool {
3939
}
4040
}
4141

42+
// ReadyConditionType returns the type of the ready condition.
43+
func (b *BootstrapContract) ReadyConditionType() string {
44+
return "Ready"
45+
}
46+
4247
// DataSecretName provide access to status.dataSecretName field in a bootstrap object.
4348
func (b *BootstrapContract) DataSecretName() *String {
4449
return &String{

internal/contract/infrastructure_machine.go

+5
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,11 @@ func (m *InfrastructureMachineContract) Ready() *Bool {
4949
}
5050
}
5151

52+
// ReadyConditionType returns the type of the ready condition.
53+
func (m *InfrastructureMachineContract) ReadyConditionType() string {
54+
return "Ready"
55+
}
56+
5257
// FailureReason provides access to the status.failureReason field in an InfrastructureMachine object. Note that this field is optional.
5358
func (m *InfrastructureMachineContract) FailureReason() *String {
5459
return &String{

internal/controllers/machine/machine_controller.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@ func (r *Reconciler) Reconcile(ctx context.Context, req ctrl.Request) (_ ctrl.Re
207207
}
208208

209209
defer func() {
210-
r.reconcilePhase(ctx, m)
210+
r.reconcileStatus(ctx, s)
211211

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

internal/controllers/machine/machine_controller_noderef.go

+1-4
Original file line numberDiff line numberDiff line change
@@ -225,10 +225,7 @@ func summarizeNodeConditions(node *corev1.Node) (corev1.ConditionStatus, string)
225225
}
226226
}
227227
}
228-
message = strings.TrimSpace(message)
229-
if strings.HasSuffix(message, ".") {
230-
message = strings.TrimSuffix(message, ".")
231-
}
228+
message = strings.TrimSuffix(message, ". ")
232229
if semanticallyFalseStatus > 0 {
233230
return corev1.ConditionFalse, message
234231
}

internal/controllers/machine/machine_controller_phases.go

-40
Original file line numberDiff line numberDiff line change
@@ -45,46 +45,6 @@ import (
4545

4646
var externalReadyWait = 30 * time.Second
4747

48-
func (r *Reconciler) reconcilePhase(_ context.Context, m *clusterv1.Machine) {
49-
originalPhase := m.Status.Phase
50-
51-
// Set the phase to "pending" if nil.
52-
if m.Status.Phase == "" {
53-
m.Status.SetTypedPhase(clusterv1.MachinePhasePending)
54-
}
55-
56-
// Set the phase to "provisioning" if bootstrap is ready and the infrastructure isn't.
57-
if m.Status.BootstrapReady && !m.Status.InfrastructureReady {
58-
m.Status.SetTypedPhase(clusterv1.MachinePhaseProvisioning)
59-
}
60-
61-
// Set the phase to "provisioned" if there is a provider ID.
62-
if m.Spec.ProviderID != nil {
63-
m.Status.SetTypedPhase(clusterv1.MachinePhaseProvisioned)
64-
}
65-
66-
// Set the phase to "running" if there is a NodeRef field and infrastructure is ready.
67-
if m.Status.NodeRef != nil && m.Status.InfrastructureReady {
68-
m.Status.SetTypedPhase(clusterv1.MachinePhaseRunning)
69-
}
70-
71-
// Set the phase to "failed" if any of Status.FailureReason or Status.FailureMessage is not-nil.
72-
if m.Status.FailureReason != nil || m.Status.FailureMessage != nil {
73-
m.Status.SetTypedPhase(clusterv1.MachinePhaseFailed)
74-
}
75-
76-
// Set the phase to "deleting" if the deletion timestamp is set.
77-
if !m.DeletionTimestamp.IsZero() {
78-
m.Status.SetTypedPhase(clusterv1.MachinePhaseDeleting)
79-
}
80-
81-
// If the phase has changed, update the LastUpdated timestamp
82-
if m.Status.Phase != originalPhase {
83-
now := metav1.Now()
84-
m.Status.LastUpdated = &now
85-
}
86-
}
87-
8848
// reconcileExternal handles generic unstructured objects referenced by a Machine.
8949
func (r *Reconciler) reconcileExternal(ctx context.Context, cluster *clusterv1.Cluster, m *clusterv1.Machine, ref *corev1.ObjectReference) (*unstructured.Unstructured, error) {
9050
if err := utilconversion.UpdateReferenceAPIContract(ctx, r.Client, ref); err != nil {

0 commit comments

Comments
 (0)