Skip to content

Commit

Permalink
Fix requeue for git commit tracking
Browse files Browse the repository at this point in the history
  • Loading branch information
blampe committed Nov 26, 2024
1 parent b7c71da commit 60b399d
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 11 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: 5 additions & 11 deletions operator/internal/controller/pulumi/stack_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -756,22 +756,16 @@ func (r *StackReconciler) Reconcile(ctx context.Context, request ctrl.Request) (

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 or if we're tracking a branch.
if sess.stack.ContinueResyncOnCommitMatch || stack.Branch != "" {
requeueAfter = max(1*time.Second, time.Until(instance.Status.LastUpdate.LastResyncTime.Add(resyncFreq(instance))))
}
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)
} else {
log.Info("Commit hash unchanged.")
}
log.Info("Commit hash unchanged. Will wait for new commit or resync.")
} else if stack.FluxSource != nil {
log.Info("Commit hash unchanged. Will wait for Source update or resync.")
} else if stack.ProgramRef != nil {
Expand Down Expand Up @@ -1079,7 +1073,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 60b399d

Please sign in to comment.