Skip to content

Commit cc2c737

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 cc2c737

File tree

2 files changed

+44
-1
lines changed

2 files changed

+44
-1
lines changed

controllers/operator_controller.go

+15
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

+29-1
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,7 +387,7 @@ 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() {
@@ -374,6 +397,7 @@ var _ = Describe("Reconcile Test", func() {
374397
Message: "failed to unpack",
375398
Reason: rukpakv1alpha1.ReasonUnpackFailed,
376399
})
400+
bd.Status.ObservedGeneration = bd.GetGeneration()
377401

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

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

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

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

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

0 commit comments

Comments
 (0)