diff --git a/controllers/tf_controller.go b/controllers/tf_controller.go index 616fc690..7f85e407 100644 --- a/controllers/tf_controller.go +++ b/controllers/tf_controller.go @@ -598,6 +598,11 @@ func (r *TerraformReconciler) shouldReconcile(terraform *infrav1.Terraform, sour return true, "source revision has changed since last reconciliation attempt", 0 } + // reconcile if we were last blocked on a not ready dependency + if conditions.HasAnyReason(terraform, meta.ReadyCondition, infrav1.DependencyNotReadyReason) { + return true, "previously blocked on not ready dependency", 0 + } + // reconcile if the last reconciliation failed, and we are within the retry interval if terraform.Status.ReconciliationFailures > 0 && terraform.Status.LastPlanAt != nil && !conditions.IsTrue(terraform, meta.ReadyCondition) { nextRetry := terraform.Status.LastPlanAt.Add(terraform.GetRetryInterval()) diff --git a/controllers/tf_controller_interval_test.go b/controllers/tf_controller_interval_test.go index d096dea3..be8db4c5 100644 --- a/controllers/tf_controller_interval_test.go +++ b/controllers/tf_controller_interval_test.go @@ -227,6 +227,40 @@ func TestShouldReconcileWhenForceEnabled(t *testing.T) { g.Expect(requeueAfter).To(Equal(time.Duration(0))) } +func TestShouldReconcileWhenDependencyNotReady(t *testing.T) { + Spec("This spec covers reconciling when a dependency is not ready.") + It("should return true without delay.") + + g := NewWithT(t) + reconciler := &TerraformReconciler{} + + tf := &infrav1.Terraform{ + ObjectMeta: metav1.ObjectMeta{ + Generation: 1, + }, + Spec: infrav1.TerraformSpec{ + Interval: metav1.Duration{Duration: 24 * time.Hour}, + }, + Status: infrav1.TerraformStatus{ + LastPlanAt: &metav1.Time{Time: time.Now()}, + ObservedGeneration: 1, + Conditions: []metav1.Condition{ + { + Message: "Dependencies do not meet ready condition, retrying in 30s", + Reason: infrav1.DependencyNotReadyReason, + Type: meta.ReadyCondition, + Status: metav1.ConditionFalse, + }, + }, + }, + } + + shouldReconcile, reason, requeueAfter := reconciler.shouldReconcile(tf, nil) + g.Expect(shouldReconcile).To(BeTrue()) + g.Expect(reason).To(Equal("previously blocked on not ready dependency")) + g.Expect(requeueAfter).To(Equal(time.Duration(0))) +} + func TestShouldReconcileWhenSourceRevisionChanges(t *testing.T) { Spec("This spec covers reconciling when the source revision has changed.") It("should return true without delay.")