Skip to content
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

Conditions: Map out-of-date bundleDeployment with an operator condition #134

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
21 changes: 16 additions & 5 deletions controllers/operator_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -294,10 +294,6 @@ func verifyBDStatus(dep *rukpakv1alpha1.BundleDeployment) (metav1.ConditionStatu
isValidBundleCond := apimeta.FindStatusCondition(dep.Status.Conditions, rukpakv1alpha1.TypeHasValidBundle)
isInstalledCond := apimeta.FindStatusCondition(dep.Status.Conditions, rukpakv1alpha1.TypeInstalled)

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
}
Expand All @@ -309,11 +305,21 @@ func verifyBDStatus(dep *rukpakv1alpha1.BundleDeployment) (metav1.ConditionStatu
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)
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 {
// if BundleDeployment status is stale, return an unknown condition.
if isBundleDepStale(existingBD) {
return metav1.Condition{
Type: operatorsv1alpha1.TypeReady,
Status: metav1.ConditionUnknown,
Reason: operatorsv1alpha1.ReasonInstallationStatusUnknown,
Message: fmt.Sprintf("waiting for BundleDeployment %q status to be updated. BundleDeployment conditions out of date.", existingBD.Name),
ObservedGeneration: observedGeneration,
}
}
// 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.
Expand All @@ -338,3 +344,8 @@ func mapBDStatusToReadyCondition(existingBD *rukpakv1alpha1.BundleDeployment, ob
ObservedGeneration: observedGeneration,
}
}

// isBundleDepStale returns true if conditions are out of date.
func isBundleDepStale(bd *rukpakv1alpha1.BundleDeployment) bool {
return bd != nil && bd.Status.ObservedGeneration != bd.GetGeneration()
}
Loading