Skip to content

Commit

Permalink
Merge pull request #146 from abays/standardize_status
Browse files Browse the repository at this point in the history
Align with standardized status pattern used across operators
  • Loading branch information
openshift-merge-bot[bot] authored Mar 13, 2024
2 parents bd8cbae + e06ce91 commit 9abb739
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 18 deletions.
4 changes: 2 additions & 2 deletions api/v1beta1/openstackbaremetalset_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -270,9 +270,9 @@ type DiskSSDReq struct {
// will need some of those functions to exist in this module/package to avoid import cycle errors
//

// IsReady - returns true if all requested BMHs are provisioned
// IsReady - returns true if OpenStackBaremetalSet is reconciled successfully
func (instance *OpenStackBaremetalSet) IsReady() bool {
return instance.Status.Conditions.IsTrue(OpenStackBaremetalSetBmhProvisioningReadyCondition)
return instance.Status.Conditions.IsTrue(condition.ReadyCondition)
}

//
Expand Down
4 changes: 2 additions & 2 deletions api/v1beta1/openstackprovisionserver_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,9 +87,9 @@ type OpenStackProvisionServerStatus struct {
LocalImageURL string `json:"localImageUrl,omitempty"`
}

// IsReady - returns true if service is ready to serve requests
// IsReady - returns true if OpenStackProvisionServer is reconciled successfully
func (instance *OpenStackProvisionServer) IsReady() bool {
return instance.Status.ReadyCount > 0 && instance.Status.LocalImageURL != ""
return instance.Status.Conditions.IsTrue(condition.ReadyCondition)
}

// +kubebuilder:object:root=true
Expand Down
19 changes: 10 additions & 9 deletions controllers/openstackbaremetalset_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,17 +97,18 @@ func (r *OpenStackBaremetalSetReconciler) Reconcile(ctx context.Context, req ctr

// Always patch the instance status when exiting this function so we can persist any changes.
defer func() {
// update the overall status condition if service is ready
if instance.IsReady() {
instance.Status.Conditions.MarkTrue(condition.ReadyCondition, condition.ReadyMessage)
// update the Ready condition based on the sub conditions
if instance.Status.Conditions.AllSubConditionIsTrue() {
instance.Status.Conditions.MarkTrue(
condition.ReadyCondition, condition.ReadyMessage)
} else {
instance.Status.Conditions.MarkFalse(
condition.ReadyCondition,
condition.RequestedReason,
condition.SeverityInfo,
condition.ReadyInitMessage)
// something is not ready so reset the Ready condition
instance.Status.Conditions.MarkUnknown(
condition.ReadyCondition, condition.InitReason, condition.ReadyInitMessage)
// and recalculate it based on the state of the rest of the conditions
instance.Status.Conditions.Set(
instance.Status.Conditions.Mirror(condition.ReadyCondition))
}

err := helper.PatchInstance(ctx, instance)
if err != nil {
_err = err
Expand Down
27 changes: 22 additions & 5 deletions controllers/openstackprovisionserver_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,11 +119,18 @@ func (r *OpenStackProvisionServerReconciler) Reconcile(ctx context.Context, req

// Always patch the instance status when exiting this function so we can persist any changes.
defer func() {
// update the overall status condition if service is ready
if instance.IsReady() {
instance.Status.Conditions.MarkTrue(condition.ReadyCondition, condition.ReadyMessage)
// update the Ready condition based on the sub conditions
if instance.Status.Conditions.AllSubConditionIsTrue() {
instance.Status.Conditions.MarkTrue(
condition.ReadyCondition, condition.ReadyMessage)
} else {
// something is not ready so reset the Ready condition
instance.Status.Conditions.MarkUnknown(
condition.ReadyCondition, condition.InitReason, condition.ReadyInitMessage)
// and recalculate it based on the state of the rest of the conditions
instance.Status.Conditions.Set(
instance.Status.Conditions.Mirror(condition.ReadyCondition))
}

err := helper.PatchInstance(ctx, instance)
if err != nil {
_err = err
Expand Down Expand Up @@ -433,7 +440,17 @@ func (r *OpenStackProvisionServerReconciler) reconcileNormal(ctx context.Context
r.Log.Info(fmt.Sprintf("OpenStackProvisionServer LocalImageURL changed: %s", instance.Status.LocalImageURL))
}

instance.Status.Conditions.MarkTrue(baremetalv1.OpenStackProvisionServerLocalImageURLReadyCondition, baremetalv1.OpenStackProvisionServerLocalImageURLReadyMessage)
if instance.Status.LocalImageURL != "" {
instance.Status.Conditions.MarkTrue(baremetalv1.OpenStackProvisionServerLocalImageURLReadyCondition, baremetalv1.OpenStackProvisionServerLocalImageURLReadyMessage)
} else {
instance.Status.Conditions.Set(condition.FalseCondition(
baremetalv1.OpenStackProvisionServerLocalImageURLReadyCondition,
condition.RequestedReason,
condition.SeverityInfo,
baremetalv1.OpenStackProvisionServerLocalImageURLReadyRunningMessage))

return ctrl.Result{RequeueAfter: time.Duration(10) * time.Second}, nil
}
// check ProvisionIp/LocalImageURL - end

r.Log.Info(fmt.Sprintf("Reconciled OpenStackProvisionServer '%s' successfully", instance.Name))
Expand Down

0 comments on commit 9abb739

Please sign in to comment.