Skip to content

Commit ad0d8ff

Browse files
Conditions: Map out-of-date bundleDeployment with an operator condition
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 <[email protected]>
1 parent c96fef5 commit ad0d8ff

File tree

2 files changed

+50
-5
lines changed

2 files changed

+50
-5
lines changed

controllers/operator_controller.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,17 @@ func (r *OperatorReconciler) reconcile(ctx context.Context, op *operatorsv1alpha
175175
return ctrl.Result{}, err
176176
}
177177

178+
if isBundleDepStale(existingTypedBundleDeployment) {
179+
apimeta.SetStatusCondition(&op.Status.Conditions, metav1.Condition{
180+
Type: operatorsv1alpha1.TypeReady,
181+
Status: metav1.ConditionUnknown,
182+
Reason: operatorsv1alpha1.ReasonInstallationStatusUnknown,
183+
Message: fmt.Sprintf("waiting for bundleDeployment %q status to be updated. BundleDeployment conditions out of date.", existingTypedBundleDeployment.Name),
184+
ObservedGeneration: op.GetGeneration(),
185+
})
186+
return ctrl.Result{}, nil
187+
}
188+
178189
// set the status of the operator based on the respective bundle deployment status conditions.
179190
apimeta.SetStatusCondition(&op.Status.Conditions, mapBDStatusToReadyCondition(existingTypedBundleDeployment, op.GetGeneration()))
180191
return ctrl.Result{}, nil
@@ -338,3 +349,8 @@ func mapBDStatusToReadyCondition(existingBD *rukpakv1alpha1.BundleDeployment, ob
338349
ObservedGeneration: observedGeneration,
339350
}
340351
}
352+
353+
// isBundleDepStale returns true if conditions are out of date.
354+
func isBundleDepStale(existingTypedBundleDeployment *rukpakv1alpha1.BundleDeployment) bool {
355+
return existingTypedBundleDeployment != nil && existingTypedBundleDeployment.Status.ObservedGeneration != existingTypedBundleDeployment.GetGeneration()
356+
}

controllers/operator_controller_test.go

Lines changed: 34 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -348,8 +348,31 @@ var _ = Describe("Reconcile Test", func() {
348348
Expect(err).NotTo(HaveOccurred())
349349
})
350350

351+
It("verify operator status when bundle deployment status is stale while being created", func() {
352+
res, err := reconciler.Reconcile(ctx, ctrl.Request{NamespacedName: opKey})
353+
Expect(res).To(Equal(ctrl.Result{}))
354+
Expect(err).NotTo(HaveOccurred())
355+
356+
By("fetching the updated operator after reconcile")
357+
op := &operatorsv1alpha1.Operator{}
358+
err = cl.Get(ctx, opKey, op)
359+
Expect(err).NotTo(HaveOccurred())
360+
361+
By("checking the expected conditions")
362+
cond := apimeta.FindStatusCondition(op.Status.Conditions, operatorsv1alpha1.TypeReady)
363+
Expect(cond).NotTo(BeNil())
364+
Expect(cond.Status).To(Equal(metav1.ConditionUnknown))
365+
Expect(cond.Reason).To(Equal(operatorsv1alpha1.ReasonInstallationStatusUnknown))
366+
Expect(cond.Message).To(Equal(fmt.Sprintf("waiting for bundleDeployment %q status to be updated. BundleDeployment conditions out of date.", bd.Name)))
367+
})
368+
351369
It("verify operator status when bundle deployment is waiting to be created", func() {
352370
By("running reconcile")
371+
bd.Status.ObservedGeneration = bd.GetGeneration()
372+
By("updating the status of bundleDeployment")
373+
err := cl.Status().Update(ctx, bd)
374+
Expect(err).NotTo(HaveOccurred())
375+
353376
res, err := reconciler.Reconcile(ctx, ctrl.Request{NamespacedName: opKey})
354377
Expect(res).To(Equal(ctrl.Result{}))
355378
Expect(err).NotTo(HaveOccurred())
@@ -364,16 +387,18 @@ var _ = Describe("Reconcile Test", func() {
364387
Expect(cond).NotTo(BeNil())
365388
Expect(cond.Status).To(Equal(metav1.ConditionUnknown))
366389
Expect(cond.Reason).To(Equal(operatorsv1alpha1.ReasonInstallationStatusUnknown))
367-
Expect(cond.Message).To(ContainSubstring(`waiting for bundleDeployment`))
390+
Expect(cond.Message).To(Equal(fmt.Sprintf("waiting for bundleDeployment %q status to be updated", bd.Name)))
368391
})
369392

370393
It("verify operator status when `HasValidBundle` condition of rukpak is false", func() {
371394
apimeta.SetStatusCondition(&bd.Status.Conditions, metav1.Condition{
372-
Type: rukpakv1alpha1.TypeHasValidBundle,
373-
Status: metav1.ConditionFalse,
374-
Message: "failed to unpack",
375-
Reason: rukpakv1alpha1.ReasonUnpackFailed,
395+
Type: rukpakv1alpha1.TypeHasValidBundle,
396+
Status: metav1.ConditionFalse,
397+
Message: "failed to unpack",
398+
Reason: rukpakv1alpha1.ReasonUnpackFailed,
399+
ObservedGeneration: 1,
376400
})
401+
bd.Status.ObservedGeneration = bd.GetGeneration()
377402

378403
By("updating the status of bundleDeployment")
379404
err := cl.Status().Update(ctx, bd)
@@ -404,6 +429,7 @@ var _ = Describe("Reconcile Test", func() {
404429
Message: "failed to install",
405430
Reason: rukpakv1alpha1.ReasonInstallFailed,
406431
})
432+
bd.Status.ObservedGeneration = bd.GetGeneration()
407433

408434
By("updating the status of bundleDeployment")
409435
err := cl.Status().Update(ctx, bd)
@@ -434,6 +460,7 @@ var _ = Describe("Reconcile Test", func() {
434460
Message: "operator installed successfully",
435461
Reason: rukpakv1alpha1.ReasonInstallationSucceeded,
436462
})
463+
bd.Status.ObservedGeneration = bd.GetGeneration()
437464

438465
By("updating the status of bundleDeployment")
439466
err := cl.Status().Update(ctx, bd)
@@ -471,6 +498,7 @@ var _ = Describe("Reconcile Test", func() {
471498
Message: "installing",
472499
Reason: rukpakv1alpha1.ReasonInstallationSucceeded,
473500
})
501+
bd.Status.ObservedGeneration = bd.GetGeneration()
474502

475503
By("updating the status of bundleDeployment")
476504
err := cl.Status().Update(ctx, bd)
@@ -501,6 +529,7 @@ var _ = Describe("Reconcile Test", func() {
501529
Message: "installing",
502530
Reason: rukpakv1alpha1.ReasonInstallationSucceeded,
503531
})
532+
bd.Status.ObservedGeneration = bd.GetGeneration()
504533

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

0 commit comments

Comments
 (0)