fix(cronworkflow): prevent metadata overwrite due to stale controller state#15880
Open
GeunSam2 wants to merge 3 commits intoargoproj:mainfrom
Open
fix(cronworkflow): prevent metadata overwrite due to stale controller state#15880GeunSam2 wants to merge 3 commits intoargoproj:mainfrom
GeunSam2 wants to merge 3 commits intoargoproj:mainfrom
Conversation
…odified labels persistUpdate() was patching the full metadata.labels and metadata.annotations maps from a stale in-memory snapshot, silently reverting any external changes made between the informer cache read and the patch call. This changes persistUpdate() to only include metadata keys that the controller explicitly modified during the current operation (e.g. completed label, schedule annotation). Signed-off-by: gray_karrot <gray@daangn.com>
53e89ce to
7908684
Compare
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.
Summary
Fix a race condition in the CronWorkflow controller where
metadata.labelsandmetadata.annotationscan be overwritten with stale values.Previously, the controller used in-memory objects when performing updates after workflow execution, which could revert newer metadata changes made by external actors.
This PR ensures that:
Fixes #15877
Motivation
In certain scenarios, the controller may overwrite newer metadata changes due to stale in-memory state:
persistUpdate()using stale metadataThis leads to unexpected behavior for systems relying on labels/annotations for:
Changes
metadata.labelsandmetadata.annotationsHow to test
kubectl patch cronworkflow metadata-race-test \ -p '{"metadata":{"labels":{"test-label":"updated"}}}' \ --type=mergeExpected behavior
test-label=updatedis preservedBefore this PR
test-labelis reverted to"initial"Checklist
:latestimage tagAdditional context
This issue is related to controller-side ownership of metadata fields.
The fix aligns with Kubernetes best practices: