Skip to content

Commit 4dc7f0a

Browse files
authored
Merge pull request #2872 from Nordix/lentzi90/capi-v1b2-osm
✨ CAPI v1beta2 conditions and deprecations for OSM
2 parents de34a9f + 722610f commit 4dc7f0a

File tree

12 files changed

+474
-12
lines changed

12 files changed

+474
-12
lines changed

.golangci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ linters:
188188
text: 'SA1019: "sigs.k8s.io/cluster-api/util/deprecated/v1beta1/conditions" is deprecated: This package is deprecated and is going to be removed when support for v1beta1 will be dropped. Please see https://github.com/kubernetes-sigs/cluster-api/blob/main/docs/proposals/20240916-improve-status-in-CAPI-resources.md for more details.'
189189
- linters:
190190
- staticcheck
191-
text: 'SA1019: .*.Status.Ready is deprecated: This field is deprecated and will be removed in a future API version. Use status.conditions to determine the ready state of the cluster.'
191+
text: 'SA1019: .*.Status.Ready is deprecated: This field is deprecated and will be removed in a future API version. Use status.conditions to determine the ready state of the *'
192192
- linters:
193193
- staticcheck
194194
text: 'SA1019: .*.Status.FailureReason is deprecated: This field is deprecated and will be removed in a future API version. Use status.conditions to report failures.'

api/v1beta1/openstackmachine_types.go

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,12 +185,27 @@ type ServerMetadata struct {
185185
Value string `json:"value"`
186186
}
187187

188+
// MachineInitialization contains information about the initialization status of the machine.
189+
type MachineInitialization struct {
190+
// Provisioned is set to true when the initial provisioning of the machine infrastructure is completed.
191+
// The value of this field is never updated after provisioning is completed.
192+
// +optional
193+
Provisioned bool `json:"provisioned,omitempty"`
194+
}
195+
188196
// OpenStackMachineStatus defines the observed state of OpenStackMachine.
189197
type OpenStackMachineStatus struct {
190198
// Ready is true when the provider resource is ready.
199+
//
200+
// Deprecated: This field is deprecated and will be removed in a future API version.
201+
// Use status.conditions to determine the ready state of the machine.
191202
// +optional
192203
Ready bool `json:"ready"`
193204

205+
// Initialization contains information about the initialization status of the machine.
206+
// +optional
207+
Initialization *MachineInitialization `json:"initialization,omitempty"`
208+
194209
// InstanceID is the OpenStack instance ID for this machine.
195210
// +optional
196211
InstanceID optional.String `json:"instanceID,omitempty"`
@@ -213,6 +228,11 @@ type OpenStackMachineStatus struct {
213228
// +optional
214229
Resources *MachineResources `json:"resources,omitempty"`
215230

231+
// FailureReason explains the reson behind a failure.
232+
//
233+
// Deprecated: This field is deprecated and will be removed in a future API version.
234+
// Use status.conditions to report failures.
235+
// +optional
216236
FailureReason *capoerrors.DeprecatedCAPIMachineStatusError `json:"failureReason,omitempty"`
217237

218238
// FailureMessage will be set in the event that there is a terminal problem
@@ -231,9 +251,17 @@ type OpenStackMachineStatus struct {
231251
// Any transient errors that occur during the reconciliation of Machines
232252
// can be added as events to the Machine object and/or logged in the
233253
// controller's output.
254+
//
255+
// Deprecated: This field is deprecated and will be removed in a future API version.
256+
// Use status.conditions to report failures.
234257
// +optional
235258
FailureMessage *string `json:"failureMessage,omitempty"`
236259

260+
// Conditions defines current service state of the OpenStackMachine.
261+
// This field surfaces into Machine's status.conditions[InfrastructureReady] condition.
262+
// The Ready condition must surface issues during the entire lifecycle of the OpenStackMachine
263+
// (both during initial provisioning and after the initial provisioning is completed).
264+
// +optional
237265
Conditions clusterv1beta1.Conditions `json:"conditions,omitempty"`
238266
}
239267

api/v1beta1/zz_generated.deepcopy.go

Lines changed: 20 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

cmd/models-schema/zz_generated.openapi.go

Lines changed: 35 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

config/crd/bases/infrastructure.cluster.x-k8s.io_openstackmachines.yaml

Lines changed: 28 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

controllers/openstackmachine_controller.go

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -382,6 +382,7 @@ func (r *OpenStackMachineReconciler) reconcileNormal(ctx context.Context, scope
382382

383383
if instanceStatus == nil {
384384
v1beta1conditions.MarkFalse(openStackMachine, infrav1.InstanceReadyCondition, infrav1.InstanceDeletedReason, clusterv1beta1.ConditionSeverityError, infrav1.ServerUnexpectedDeletedMessage)
385+
v1beta1conditions.MarkFalse(openStackMachine, clusterv1beta1.ReadyCondition, infrav1.InstanceDeletedReason, clusterv1beta1.ConditionSeverityError, infrav1.ServerUnexpectedDeletedMessage)
385386
openStackMachine.SetFailure(capoerrors.DeprecatedCAPIUpdateMachineError, errors.New(infrav1.ServerUnexpectedDeletedMessage)) //nolint:staticcheck // This error is not used as an error
386387
return ctrl.Result{}, nil
387388
}
@@ -437,6 +438,22 @@ func (r *OpenStackMachineReconciler) reconcileMachineState(scope *scope.WithLogg
437438
openStackMachine.Spec.ProviderID = ptr.To(fmt.Sprintf("openstack://%s/%s", region, *openStackServer.Status.InstanceID))
438439
openStackMachine.Status.InstanceID = openStackServer.Status.InstanceID
439440
openStackMachine.Status.Ready = true
441+
442+
// Set initialization.provisioned to true when initial infrastructure provisioning is complete.
443+
// This field should only be set once and never changed afterward, as per CAPI v1beta2 contract.
444+
// We set it here when the machine becomes ACTIVE for the first time.
445+
if openStackMachine.Status.Initialization == nil {
446+
openStackMachine.Status.Initialization = &infrav1.MachineInitialization{}
447+
}
448+
if !openStackMachine.Status.Initialization.Provisioned {
449+
openStackMachine.Status.Initialization.Provisioned = true
450+
scope.Logger().Info("Initial machine infrastructure provisioning completed")
451+
}
452+
453+
// Set the Ready condition to True when infrastructure is ready.
454+
// This condition surfaces into Machine's status.conditions[InfrastructureReady].
455+
// It reflects the current operational state of the machine infrastructure.
456+
v1beta1conditions.MarkTrue(openStackMachine, clusterv1beta1.ReadyCondition)
440457
case infrav1.InstanceStateError:
441458
// If the machine has a NodeRef then it must have been working at some point,
442459
// so the error could be something temporary.
@@ -447,20 +464,24 @@ func (r *OpenStackMachineReconciler) reconcileMachineState(scope *scope.WithLogg
447464
openStackMachine.SetFailure(capoerrors.DeprecatedCAPIUpdateMachineError, err)
448465
}
449466
v1beta1conditions.MarkFalse(openStackMachine, infrav1.InstanceReadyCondition, infrav1.InstanceStateErrorReason, clusterv1beta1.ConditionSeverityError, "")
467+
v1beta1conditions.MarkFalse(openStackMachine, clusterv1beta1.ReadyCondition, infrav1.InstanceStateErrorReason, clusterv1beta1.ConditionSeverityError, "Instance is in ERROR state")
450468
return &ctrl.Result{}
451469
case infrav1.InstanceStateDeleted:
452470
// we should avoid further actions for DELETED VM
453471
scope.Logger().Info("Machine instance state is DELETED, no actions")
454472
v1beta1conditions.MarkFalse(openStackMachine, infrav1.InstanceReadyCondition, infrav1.InstanceDeletedReason, clusterv1beta1.ConditionSeverityError, "")
473+
v1beta1conditions.MarkFalse(openStackMachine, clusterv1beta1.ReadyCondition, infrav1.InstanceDeletedReason, clusterv1beta1.ConditionSeverityError, "Instance has been deleted")
455474
return &ctrl.Result{}
456475
case infrav1.InstanceStateBuild, infrav1.InstanceStateUndefined:
457476
scope.Logger().Info("Waiting for instance to become ACTIVE", "id", openStackServer.Status.InstanceID, "status", openStackServer.Status.InstanceState)
477+
v1beta1conditions.MarkFalse(openStackMachine, clusterv1beta1.ReadyCondition, infrav1.InstanceNotReadyReason, clusterv1beta1.ConditionSeverityInfo, "Instance is building")
458478
return &ctrl.Result{RequeueAfter: waitForBuildingInstanceToReconcile}
459479
default:
460480
// The other state is normal (for example, migrating, shutoff) but we don't want to proceed until it's ACTIVE
461481
// due to potential conflict or unexpected actions
462482
scope.Logger().Info("Waiting for instance to become ACTIVE", "id", openStackServer.Status.InstanceID, "status", openStackServer.Status.InstanceState)
463483
v1beta1conditions.MarkUnknown(openStackMachine, infrav1.InstanceReadyCondition, infrav1.InstanceNotReadyReason, "Instance state is not handled: %v", ptr.Deref(openStackServer.Status.InstanceState, infrav1.InstanceStateUndefined))
484+
v1beta1conditions.MarkUnknown(openStackMachine, clusterv1beta1.ReadyCondition, infrav1.InstanceNotReadyReason, "Instance state is: %v", ptr.Deref(openStackServer.Status.InstanceState, infrav1.InstanceStateUndefined))
464485

465486
return &ctrl.Result{RequeueAfter: waitForInstanceBecomeActiveToReconcile}
466487
}

0 commit comments

Comments
 (0)