Skip to content

Commit 91a6d6b

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 07ae744 commit 91a6d6b

File tree

2 files changed

+49
-5
lines changed

2 files changed

+49
-5
lines changed

controllers/operator_controller.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -314,6 +314,16 @@ func verifyBDStatus(dep *rukpakv1alpha1.BundleDeployment) (metav1.ConditionStatu
314314

315315
// mapBDStatusToReadyCondition returns the operator object's "TypeReady" condition based on the bundle deployment statuses.
316316
func mapBDStatusToReadyCondition(existingBD *rukpakv1alpha1.BundleDeployment, observedGeneration int64) metav1.Condition {
317+
// if BundleDeployment status is stale, return an unknown condition.
318+
if isBundleDepStale(existingBD) {
319+
return metav1.Condition{
320+
Type: operatorsv1alpha1.TypeReady,
321+
Status: metav1.ConditionUnknown,
322+
Reason: operatorsv1alpha1.ReasonInstallationStatusUnknown,
323+
Message: fmt.Sprintf("waiting for bundleDeployment %q status to be updated. BundleDeployment conditions out of date.", existingBD.Name),
324+
ObservedGeneration: observedGeneration,
325+
}
326+
}
317327
// update operator status:
318328
// 1. If the Operator "Ready" status is "Unknown": The status of successful bundleDeployment is unknown, wait till Rukpak updates the BD status.
319329
// 2. If the Operator "Ready" status is "True": Update the "successful resolution" status and return the result.
@@ -338,3 +348,8 @@ func mapBDStatusToReadyCondition(existingBD *rukpakv1alpha1.BundleDeployment, ob
338348
ObservedGeneration: observedGeneration,
339349
}
340350
}
351+
352+
// isBundleDepStale returns true if conditions are out of date.
353+
func isBundleDepStale(existingTypedBundleDeployment *rukpakv1alpha1.BundleDeployment) bool {
354+
return existingTypedBundleDeployment != nil && existingTypedBundleDeployment.Status.ObservedGeneration != existingTypedBundleDeployment.GetGeneration()
355+
}

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)