Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 83
[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
Uh oh!
There was an error while loading. Please reload this page.
Changes from all commits
6fe1673858ed852dc4a5e207ab8fFile filter
Filter by extension
Conversations
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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, | ||
| Reason: operatorsv1alpha1.ReasonInstallationSucceeded, | ||
| ||
| Message: err.Error(), | ||
| ObservedGeneration: op.GetGeneration(), | ||
| }) | ||
| return ctrl.Result{}, err | ||
varshaprasad96 marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| } | ||
| // 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 | ||
| } | ||
| @@ -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")) | ||
| } | ||
| @@ -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
Member There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 | ||
Member There was a problem hiding this comment. Choose a reason for hiding this commentThe 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, | ||
| } | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Leaving it to
Unknowninstead ofFalse, since an error in converting to typed object does not necessarily mean that install was unsuccessful.