Skip to content

Commit

Permalink
Let the watches deal with missing sources
Browse files Browse the repository at this point in the history
When a flux Source is missing, we can now wait for the watch to fire
when it appears, rather than retrying. The same is true when the source
is marked as unready.

Signed-off-by: Michael Bridgen <[email protected]>
  • Loading branch information
squaremo committed Oct 25, 2022
1 parent 06cc701 commit b018080
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 12 deletions.
16 changes: 10 additions & 6 deletions pkg/controller/stack/stack_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -475,13 +475,15 @@ func (r *ReconcileStack) Reconcile(ctx context.Context, request reconcile.Reques
Name: fluxSource.SourceRef.Name,
Namespace: request.Namespace,
}, &sourceObject); err != nil {
r.markStackFailed(sess, instance, err, "", "")
reterr := fmt.Errorf("could not resolve sourceRef: %w", err)
r.markStackFailed(sess, instance, reterr, "", "")
if client.IgnoreNotFound(err) != nil {
return reconcile.Result{}, fmt.Errorf("could not resolve sourceRef: %w", err)
return reconcile.Result{}, err
}
// TODO: revisit this, if sources are watched; perhaps it should be stalled?
instance.Status.MarkReconcilingCondition(pulumiv1.ReconcilingRetryReason, err.Error())
return reconcile.Result{Requeue: true}, nil
// this is marked as stalled and not requeued; the watch mechanism will requeue it if
// the source it points to appears.
instance.Status.MarkStalledCondition(pulumiv1.StalledSourceUnavailableReason, reterr.Error())
return reconcile.Result{}, nil
}

// Watch this kind of source, if we haven't already.
Expand All @@ -494,8 +496,10 @@ func (r *ReconcileStack) Reconcile(ctx context.Context, request reconcile.Reques

if err := checkFluxSourceReady(sourceObject); err != nil {
r.markStackFailed(sess, instance, err, "", "")
// This is marked as retrying, but we're really waiting until the source is ready, at
// which time the watch mechanism will requeue it.
instance.Status.MarkReconcilingCondition(pulumiv1.ReconcilingRetryReason, err.Error())
return reconcile.Result{Requeue: true}, nil
return reconcile.Result{}, nil
}

currentCommit, err = sess.SetupWorkdirFromFluxSource(ctx, sourceObject, fluxSource)
Expand Down
9 changes: 3 additions & 6 deletions test/flux_source_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -169,14 +169,11 @@ var _ = Describe("Flux source integration", func() {
deleteAndWaitForFinalization(stack)
})

It("is marked as failed and to be retried", func() {
It("is marked as failed and stalled", func() {
waitForStackFailure(stack)
// When this is present it could say that it's retrying, or that it's in progress; since
// it's run through at least once for us to see a failed state above, either indicates a
// retry.
Expect(apimeta.IsStatusConditionTrue(stack.Status.Conditions, pulumiv1.ReconcilingCondition)).To(BeTrue())
Expect(apimeta.IsStatusConditionTrue(stack.Status.Conditions, pulumiv1.StalledCondition)).To(BeTrue())
Expect(apimeta.IsStatusConditionTrue(stack.Status.Conditions, pulumiv1.ReadyCondition)).To(BeFalse())
Expect(apimeta.FindStatusCondition(stack.Status.Conditions, pulumiv1.StalledCondition)).To(BeNil())
Expect(apimeta.FindStatusCondition(stack.Status.Conditions, pulumiv1.ReconcilingCondition)).To(BeNil())
})

When("the source is an unknown group/kind", func() {
Expand Down

0 comments on commit b018080

Please sign in to comment.