Skip to content

Commit

Permalink
Conditions: Map out-of-date bundleDeployment with an operator condition
Browse files Browse the repository at this point in the history
This PR brings in the change that sets the operator condition to Unknown
when the BundleDeployment's conditions are out od date.

Signed-off-by: Varsha Prasad Narsing <varshaprasad96@gmail.com>
  • Loading branch information
varshaprasad96 committed Mar 1, 2023
1 parent 07ae744 commit cc2c737
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 1 deletion.
15 changes: 15 additions & 0 deletions controllers/operator_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -314,6 +314,16 @@ func verifyBDStatus(dep *rukpakv1alpha1.BundleDeployment) (metav1.ConditionStatu

// 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 +348,8 @@ func mapBDStatusToReadyCondition(existingBD *rukpakv1alpha1.BundleDeployment, ob
ObservedGeneration: observedGeneration,
}
}

// isBundleDepStale returns true if conditions are out of date.
func isBundleDepStale(existingTypedBundleDeployment *rukpakv1alpha1.BundleDeployment) bool {
return existingTypedBundleDeployment != nil && existingTypedBundleDeployment.Status.ObservedGeneration != existingTypedBundleDeployment.GetGeneration()
}
30 changes: 29 additions & 1 deletion controllers/operator_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -348,8 +348,31 @@ var _ = Describe("Reconcile Test", func() {
Expect(err).NotTo(HaveOccurred())
})

It("verify operator status when bundle deployment status is stale while being created", func() {
res, err := reconciler.Reconcile(ctx, ctrl.Request{NamespacedName: opKey})
Expect(res).To(Equal(ctrl.Result{}))
Expect(err).NotTo(HaveOccurred())

By("fetching the updated operator after reconcile")
op := &operatorsv1alpha1.Operator{}
err = cl.Get(ctx, opKey, op)
Expect(err).NotTo(HaveOccurred())

By("checking the expected conditions")
cond := apimeta.FindStatusCondition(op.Status.Conditions, operatorsv1alpha1.TypeReady)
Expect(cond).NotTo(BeNil())
Expect(cond.Status).To(Equal(metav1.ConditionUnknown))
Expect(cond.Reason).To(Equal(operatorsv1alpha1.ReasonInstallationStatusUnknown))
Expect(cond.Message).To(Equal(fmt.Sprintf("waiting for bundleDeployment %q status to be updated. BundleDeployment conditions out of date.", bd.Name)))
})

It("verify operator status when bundle deployment is waiting to be created", func() {
By("running reconcile")
bd.Status.ObservedGeneration = bd.GetGeneration()
By("updating the status of bundleDeployment")
err := cl.Status().Update(ctx, bd)
Expect(err).NotTo(HaveOccurred())

res, err := reconciler.Reconcile(ctx, ctrl.Request{NamespacedName: opKey})
Expect(res).To(Equal(ctrl.Result{}))
Expect(err).NotTo(HaveOccurred())
Expand All @@ -364,7 +387,7 @@ var _ = Describe("Reconcile Test", func() {
Expect(cond).NotTo(BeNil())
Expect(cond.Status).To(Equal(metav1.ConditionUnknown))
Expect(cond.Reason).To(Equal(operatorsv1alpha1.ReasonInstallationStatusUnknown))
Expect(cond.Message).To(ContainSubstring(`waiting for bundleDeployment`))
Expect(cond.Message).To(Equal(fmt.Sprintf("waiting for bundleDeployment %q status to be updated", bd.Name)))
})

It("verify operator status when `HasValidBundle` condition of rukpak is false", func() {
Expand All @@ -374,6 +397,7 @@ var _ = Describe("Reconcile Test", func() {
Message: "failed to unpack",
Reason: rukpakv1alpha1.ReasonUnpackFailed,
})
bd.Status.ObservedGeneration = bd.GetGeneration()

By("updating the status of bundleDeployment")
err := cl.Status().Update(ctx, bd)
Expand Down Expand Up @@ -404,6 +428,7 @@ var _ = Describe("Reconcile Test", func() {
Message: "failed to install",
Reason: rukpakv1alpha1.ReasonInstallFailed,
})
bd.Status.ObservedGeneration = bd.GetGeneration()

By("updating the status of bundleDeployment")
err := cl.Status().Update(ctx, bd)
Expand Down Expand Up @@ -434,6 +459,7 @@ var _ = Describe("Reconcile Test", func() {
Message: "operator installed successfully",
Reason: rukpakv1alpha1.ReasonInstallationSucceeded,
})
bd.Status.ObservedGeneration = bd.GetGeneration()

By("updating the status of bundleDeployment")
err := cl.Status().Update(ctx, bd)
Expand Down Expand Up @@ -471,6 +497,7 @@ var _ = Describe("Reconcile Test", func() {
Message: "installing",
Reason: rukpakv1alpha1.ReasonInstallationSucceeded,
})
bd.Status.ObservedGeneration = bd.GetGeneration()

By("updating the status of bundleDeployment")
err := cl.Status().Update(ctx, bd)
Expand Down Expand Up @@ -501,6 +528,7 @@ var _ = Describe("Reconcile Test", func() {
Message: "installing",
Reason: rukpakv1alpha1.ReasonInstallationSucceeded,
})
bd.Status.ObservedGeneration = bd.GetGeneration()

By("updating the status of bundleDeployment")
err := cl.Status().Update(ctx, bd)
Expand Down

0 comments on commit cc2c737

Please sign in to comment.