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 c96fef5 commit ad0d8ff
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 5 deletions.
16 changes: 16 additions & 0 deletions controllers/operator_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,17 @@ func (r *OperatorReconciler) reconcile(ctx context.Context, op *operatorsv1alpha
return ctrl.Result{}, err
}

if isBundleDepStale(existingTypedBundleDeployment) {
apimeta.SetStatusCondition(&op.Status.Conditions, 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.", existingTypedBundleDeployment.Name),
ObservedGeneration: op.GetGeneration(),
})
return ctrl.Result{}, nil
}

// 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 @@ -338,3 +349,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()
}
39 changes: 34 additions & 5 deletions 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,16 +387,18 @@ 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() {
apimeta.SetStatusCondition(&bd.Status.Conditions, metav1.Condition{
Type: rukpakv1alpha1.TypeHasValidBundle,
Status: metav1.ConditionFalse,
Message: "failed to unpack",
Reason: rukpakv1alpha1.ReasonUnpackFailed,
Type: rukpakv1alpha1.TypeHasValidBundle,
Status: metav1.ConditionFalse,
Message: "failed to unpack",
Reason: rukpakv1alpha1.ReasonUnpackFailed,
ObservedGeneration: 1,
})
bd.Status.ObservedGeneration = bd.GetGeneration()

By("updating the status of bundleDeployment")
err := cl.Status().Update(ctx, bd)
Expand Down Expand Up @@ -404,6 +429,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 +460,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 +498,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 +529,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 ad0d8ff

Please sign in to comment.