Skip to content

Commit

Permalink
Fix requeue for git commit tracking (#763)
Browse files Browse the repository at this point in the history
Fixes a bug where we were accidentally cancelling a requeue when we
intended to poll again after a minute.

Fixes #762.

---------

Co-authored-by: Eron Wright <[email protected]>
  • Loading branch information
blampe and EronWright authored Nov 27, 2024
1 parent b7c71da commit 09f8484
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ CHANGELOG
## Unreleased

- Stack Controller: watch for delete events. [#756](https://github.com/pulumi/pulumi-kubernetes-operator/pull/756)
- Stack Controller: fix an issue where new commits weren't detected when using git sources. https://github.com/pulumi/pulumi-kubernetes-operator/issues/762

## 2.0.0-beta.2 (2024-11-11)

Expand Down
16 changes: 11 additions & 5 deletions operator/internal/controller/pulumi/stack_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -752,23 +752,29 @@ func (r *StackReconciler) Reconcile(ctx context.Context, request ctrl.Request) (
}

// Requeue reconciliation as necessary to detect branch updates and
// resyncs.

// resyncs. The logic finds the smallest requeue time (if any) among various polling loops.
requeueAfter := time.Duration(0)

// Try again with exponential backoff if the update failed.
if instance.Status.LastUpdate.State == shared.FailedStackStateMessage {
requeueAfter = max(1*time.Second, time.Until(instance.Status.LastUpdate.LastResyncTime.Add(cooldown(instance))))
}
if sess.stack.ContinueResyncOnCommitMatch {
// Schedule another poll if ContinueResyncOnCommitMatch is set, for drift detection or to maintain dynamic resources.
if instance.Status.LastUpdate.State == shared.SucceededStackStateMessage && sess.stack.ContinueResyncOnCommitMatch {
requeueAfter = max(1*time.Second, time.Until(instance.Status.LastUpdate.LastResyncTime.Add(resyncFreq(instance))))
}
// Schedule another poll for source tracking.
if stack.GitSource != nil {
trackBranch := len(stack.GitSource.Branch) > 0
if trackBranch {
// Reconcile every resyncFreq to check for new commits to the branch.
pollFreq := resyncFreq(instance)
log.Info("Commit hash unchanged. Will poll for new commits.", "pollFrequency", pollFreq)
requeueAfter = min(requeueAfter, pollFreq)
if requeueAfter > 0 {
requeueAfter = max(1*time.Second, min(pollFreq, requeueAfter))
} else {
requeueAfter = max(1*time.Second, pollFreq)
}
} else {
log.Info("Commit hash unchanged.")
}
Expand Down Expand Up @@ -1079,7 +1085,7 @@ func cooldown(stack *pulumiv1.Stack) time.Duration {
func resyncFreq(stack *pulumiv1.Stack) time.Duration {
resyncFreq := time.Duration(stack.Spec.ResyncFrequencySeconds) * time.Second
if resyncFreq.Seconds() < 60 {
resyncFreq = time.Duration(60) * time.Second
resyncFreq = 60 * time.Second
}
return resyncFreq
}
Expand Down

0 comments on commit 09f8484

Please sign in to comment.