Restore status fields when gitjob creation fails#4949
Merged
0xavi0 merged 1 commit intorancher:mainfrom Apr 15, 2026
Merged
Conversation
When manageGitJob fails, updateErrorStatus was persisting mutated in-memory status fields to Kubernetes even though no gitjob had been created. On the next reconcile all shouldCreateJob conditions evaluated to false, permanently losing the trigger. Three fields were affected: - status.Commit — promoted by getNextCommit before manageGitJob is called - status.UpdateGeneration — consumed by updateGenerationValuesIfNeeded before job creation - status.ObservedGeneration — consumed by the same call The fix saves the original values of all three fields before manageGitJob is called and restores them in the error path, so the next reconcile still sees the pending trigger and retries job creation. Tests are included that fail on the unfixed code and pass after the fix. Refers to: rancher#4948 Signed-off-by: Xavi Garcia <xavi.garcia@suse.com>
Contributor
There was a problem hiding this comment.
Pull request overview
Fixes a GitRepo reconciliation edge case where in-memory status fields were being persisted to Kubernetes even when GitJob creation failed, causing subsequent reconciles to miss triggers and never retry job creation (issue #4948).
Changes:
- Restore
Status.Commit,Status.UpdateGeneration, andStatus.ObservedGenerationbefore callingupdateErrorStatuswhenmanageGitJobreturns an error/requeue. - Add regression tests that assert these status fields are not persisted when GitJob creation fails due to missing secrets.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 4 comments.
| File | Description |
|---|---|
| internal/cmd/controller/gitops/reconciler/gitjob_controller.go | Restores mutated status fields on the manageGitJob error/requeue path to preserve retry triggers. |
| internal/cmd/controller/gitops/reconciler/gitjob_test.go | Adds tests covering commit promotion, force-sync generation, and observed generation behavior on GitJob creation failure. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
p-se
approved these changes
Apr 15, 2026
0xavi0
added a commit
to 0xavi0/fleet
that referenced
this pull request
Apr 15, 2026
When manageGitJob fails, updateErrorStatus was persisting mutated in-memory status fields to Kubernetes even though no gitjob had been created. On the next reconcile all shouldCreateJob conditions evaluated to false, permanently losing the trigger. Three fields were affected: - status.Commit — promoted by getNextCommit before manageGitJob is called - status.UpdateGeneration — consumed by updateGenerationValuesIfNeeded before job creation - status.ObservedGeneration — consumed by the same call The fix saves the original values of all three fields before manageGitJob is called and restores them in the error path, so the next reconcile still sees the pending trigger and retries job creation. Tests are included that fail on the unfixed code and pass after the fix. Refers to: rancher#4948 Signed-off-by: Xavi Garcia <xavi.garcia@suse.com>
thardeck
pushed a commit
that referenced
this pull request
Apr 16, 2026
When manageGitJob fails, updateErrorStatus was persisting mutated in-memory status fields to Kubernetes even though no gitjob had been created. On the next reconcile all shouldCreateJob conditions evaluated to false, permanently losing the trigger. Three fields were affected: - status.Commit — promoted by getNextCommit before manageGitJob is called - status.UpdateGeneration — consumed by updateGenerationValuesIfNeeded before job creation - status.ObservedGeneration — consumed by the same call The fix saves the original values of all three fields before manageGitJob is called and restores them in the error path, so the next reconcile still sees the pending trigger and retries job creation. Tests are included that fail on the unfixed code and pass after the fix. Refers to: #4948 Signed-off-by: Xavi Garcia <xavi.garcia@suse.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
When manageGitJob fails, updateErrorStatus was persisting mutated in-memory status fields to Kubernetes even though no gitjob had been created. On the next reconcile all shouldCreateJob conditions evaluated to false, permanently losing the trigger.
Three fields were affected:
The fix saves the original values of all three fields before manageGitJob is called and restores them in the error path, so the next reconcile still sees the pending trigger and retries job creation.
Tests are included that fail on the unfixed code and pass after the fix.
Refers to: #4948
Additional Information
Checklist
- [ ] I have updated the documentation via a pull request in the fleet-product-docs repository.