Skip to content

[controller] resurface bundledeployment errors #125

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions api/v1alpha1/operator_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ const (
// TODO(user): add more Types, here and into init()
TypeReady = "Ready"

ReasonResolutionSucceeded = "ResolutionSucceeded"
ReasonInstallationSucceeded = "InstallationSucceeded"
ReasonResolutionFailed = "ResolutionFailed"
ReasonBundleLookupFailed = "BundleLookupFailed"
ReasonBundleDeploymentFailed = "BundleDeploymentFailed"
Expand All @@ -46,7 +46,7 @@ func init() {
)
// TODO(user): add Reasons from above
operatorutil.ConditionReasons = append(operatorutil.ConditionReasons,
ReasonResolutionSucceeded,
ReasonInstallationSucceeded,
ReasonResolutionFailed,
ReasonBundleLookupFailed,
ReasonBundleDeploymentFailed,
Expand Down
74 changes: 66 additions & 8 deletions controllers/operator_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -162,14 +162,21 @@ func (r *OperatorReconciler) reconcile(ctx context.Context, op *operatorsv1alpha
return ctrl.Result{}, err
}

// update operator status
apimeta.SetStatusCondition(&op.Status.Conditions, metav1.Condition{
Type: operatorsv1alpha1.TypeReady,
Status: metav1.ConditionTrue,
Reason: operatorsv1alpha1.ReasonResolutionSucceeded,
Message: "resolution was successful",
ObservedGeneration: op.GetGeneration(),
})
// convert existing unstructured object into bundleDeployment for easier mapping of status.
existingTypedBundleDeployment := &rukpakv1alpha1.BundleDeployment{}
if err := runtime.DefaultUnstructuredConverter.FromUnstructured(dep.UnstructuredContent(), existingTypedBundleDeployment); err != nil {
apimeta.SetStatusCondition(&op.Status.Conditions, metav1.Condition{
Type: operatorsv1alpha1.TypeReady,
Status: metav1.ConditionUnknown,
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Leaving it to Unknown instead of False, since an error in converting to typed object does not necessarily mean that install was unsuccessful.

Reason: operatorsv1alpha1.ReasonInstallationSucceeded,
Copy link
Member

@joelanford joelanford Feb 17, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For follow-up: change this to a non-success reason

Message: err.Error(),
ObservedGeneration: op.GetGeneration(),
})
return ctrl.Result{}, err
}

// set the status of the operator based on the respective bundle deployment status conditions.
apimeta.SetStatusCondition(&op.Status.Conditions, mapBDStatusToReadyCondition(existingTypedBundleDeployment, op.GetGeneration()))
return ctrl.Result{}, nil
}

Expand Down Expand Up @@ -257,9 +264,12 @@ func (r *OperatorReconciler) ensureBundleDeployment(ctx context.Context, desired
}

// If the existing BD already has everything that the desired BD has, no need to contact the API server.
// Make sure the status of the existingBD from the server is as expected.
if equality.Semantic.DeepDerivative(desiredBundleDeployment, existingBundleDeployment) {
*desiredBundleDeployment = *existingBundleDeployment
return nil
}

return r.Client.Patch(ctx, desiredBundleDeployment, client.Apply, client.ForceOwnership, client.FieldOwner("operator-controller"))
}

Expand All @@ -277,3 +287,51 @@ func (r *OperatorReconciler) existingBundleDeploymentUnstructured(ctx context.Co
}
return &unstructured.Unstructured{Object: unstrExistingBundleDeploymentObj}, nil
}

// verifyBDStatus reads the various possibilities of status in bundle deployment and translates
// into corresponding operator condition status and message.
func verifyBDStatus(dep *rukpakv1alpha1.BundleDeployment) (metav1.ConditionStatus, string) {
isValidBundleCond := apimeta.FindStatusCondition(dep.Status.Conditions, rukpakv1alpha1.TypeHasValidBundle)
isInstalledCond := apimeta.FindStatusCondition(dep.Status.Conditions, rukpakv1alpha1.TypeInstalled)
Comment on lines +294 to +295
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For follow up: add code to handle case where these conditions are out of date (based on comparison of bd.metadata.generation and bd.status.observedGeneration).


if isValidBundleCond == nil && isInstalledCond == nil {
return metav1.ConditionUnknown, fmt.Sprintf("waiting for bundleDeployment %q status to be updated", dep.Name)
}

if isValidBundleCond != nil && isValidBundleCond.Status == metav1.ConditionFalse {
return metav1.ConditionFalse, isValidBundleCond.Message
}

if isInstalledCond != nil && isInstalledCond.Status == metav1.ConditionFalse {
return metav1.ConditionFalse, isInstalledCond.Message
}

if isInstalledCond != nil && isInstalledCond.Status == metav1.ConditionTrue {
return metav1.ConditionTrue, "install was successful"
}
return metav1.ConditionUnknown, fmt.Sprintf("could not determine the state of bundleDeployment %s", dep.Name)
}

// mapBDStatusToReadyCondition returns the operator object's "TypeReady" condition based on the bundle deployment statuses.
func mapBDStatusToReadyCondition(existingBD *rukpakv1alpha1.BundleDeployment, observedGeneration int64) metav1.Condition {
// update operator status:
// 1. If the Operator "Ready" status is "Unknown": The status of successful bundleDeployment is unknown, wait till Rukpak updates the BD status.
// 2. If the Operator "Ready" status is "True": Update the "successful resolution" status and return the result.
// 3. If the Operator "Ready" status is "False": There is error observed from Rukpak. Update the status accordingly.
status, message := verifyBDStatus(existingBD)
var reason string
// TODO: introduce a new reason for condition Unknown, instead of defaulting it to Installation Succeeded.
if status == metav1.ConditionTrue {
reason = operatorsv1alpha1.ReasonInstallationSucceeded
} else {
reason = operatorsv1alpha1.ReasonBundleDeploymentFailed
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For follow-up: don't leak rukpak names in Operator API (i.e. change this to "InstallationFailed")

}

return metav1.Condition{
Type: operatorsv1alpha1.TypeReady,
Status: status,
Reason: reason,
Message: message,
ObservedGeneration: observedGeneration,
}
}
Loading