-
Notifications
You must be signed in to change notification settings - Fork 7.7k
feat: make manifest hydration queue concurrency configurable (#27926) #27948
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
crenshaw-dev
merged 4 commits into
argoproj:master
from
GuruduGanesh:feat/hydration-queue-concurrency-27926
Jun 10, 2026
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
262ef01
feat: make manifest hydration queue concurrency configurable (#27926)
GuruduGanesh 9a01966
test(hydrator): mock GetHydratorReadmeMessageTemplate after upstream …
GuruduGanesh 8bc744a
test(controller): fix pre-existing data race in TestFinalizeAppDeleti…
GuruduGanesh 447b20a
test(controller): fix lint for fake client lock
GuruduGanesh File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
20 changes: 20 additions & 0 deletions
20
cmd/argocd-application-controller/commands/argocd_application_controller_test.go
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| package commands | ||
|
|
||
| import ( | ||
| "testing" | ||
|
|
||
| "github.com/stretchr/testify/assert" | ||
| "github.com/stretchr/testify/require" | ||
| ) | ||
|
|
||
| // TestNewCommand_HydrationProcessorsFlag pins down the contract for the manifest hydration concurrency | ||
| // knob added for https://github.com/argoproj/argo-cd/issues/27926: the flag exists and defaults to a value | ||
| // greater than 1 (so the default deployment exercises hydration concurrency and tests are more likely to | ||
| // catch races, per the maintainer's guidance on the issue). | ||
| func TestNewCommand_HydrationProcessorsFlag(t *testing.T) { | ||
| cmd := NewCommand() | ||
|
|
||
| f := cmd.Flags().Lookup("hydration-processors") | ||
| require.NotNil(t, f, "expected --hydration-processors flag to be registered") | ||
| assert.Equal(t, "5", f.DefValue, "default hydration processors should be greater than 1") | ||
| } |
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,178 @@ | ||
| package controller | ||
|
|
||
| import ( | ||
| "fmt" | ||
| "sync" | ||
| "testing" | ||
| "time" | ||
|
|
||
| "github.com/stretchr/testify/assert" | ||
| "k8s.io/client-go/util/workqueue" | ||
|
|
||
| hydratortypes "github.com/argoproj/argo-cd/v3/controller/hydrator/types" | ||
| "github.com/argoproj/argo-cd/v3/pkg/ratelimiter" | ||
| ) | ||
|
|
||
| // TestNormalizeHydrationProcessors verifies that the hydration worker count is clamped to a safe minimum. | ||
| // The --hydration-processors CLI flag can be set to 0 or a negative value (the env default is clamped, but | ||
| // an explicit flag value is not), which would otherwise start zero workers and silently stall hydration. | ||
| // See https://github.com/argoproj/argo-cd/issues/27926. | ||
| func TestNormalizeHydrationProcessors(t *testing.T) { | ||
| t.Parallel() | ||
| tests := []struct { | ||
| name string | ||
| configured int | ||
| want int | ||
| }{ | ||
| {"zero clamps to one", 0, 1}, | ||
| {"negative clamps to one", -3, 1}, | ||
| {"one stays one", 1, 1}, | ||
| {"default preserved", 5, 5}, | ||
| {"large value preserved", 50, 50}, | ||
| } | ||
| for _, tc := range tests { | ||
| t.Run(tc.name, func(t *testing.T) { | ||
| t.Parallel() | ||
| assert.Equal(t, tc.want, normalizeHydrationProcessors(tc.configured)) | ||
| }) | ||
| } | ||
| } | ||
|
|
||
| func newTestHydrationQueue() workqueue.TypedRateLimitingInterface[hydratortypes.HydrationQueueKey] { | ||
| return workqueue.NewTypedRateLimitingQueue( | ||
| ratelimiter.NewCustomAppControllerRateLimiter[hydratortypes.HydrationQueueKey](ratelimiter.GetDefaultAppRateLimiterConfig()), | ||
| ) | ||
| } | ||
|
|
||
| // TestHydrationQueue_DistinctKeysProcessConcurrently asserts the core feature claim of #27926: when the | ||
| // hydration queue is drained by multiple workers, distinct hydration keys are processed concurrently, while | ||
| // no single key is ever processed by two workers at the same time. The worker loop mirrors the one started | ||
| // in ApplicationController.Run. | ||
| func TestHydrationQueue_DistinctKeysProcessConcurrently(t *testing.T) { | ||
| t.Parallel() | ||
|
|
||
| queue := newTestHydrationQueue() | ||
| t.Cleanup(queue.ShutDown) | ||
|
|
||
| const numKeys = 12 | ||
| const numWorkers = 4 | ||
| for i := range numKeys { | ||
| queue.Add(hydratortypes.HydrationQueueKey{SourceRepoURL: fmt.Sprintf("https://example.com/repo-%d", i)}) | ||
| } | ||
|
|
||
| var ( | ||
| mu sync.Mutex | ||
| inFlight int | ||
| maxConcurrent int | ||
| processed int | ||
| perKeyActive = map[hydratortypes.HydrationQueueKey]bool{} | ||
| sameKeyOverlap bool | ||
| ) | ||
|
|
||
| processNext := func() bool { | ||
| key, shutdown := queue.Get() | ||
| if shutdown { | ||
| return false | ||
| } | ||
| defer queue.Done(key) | ||
|
|
||
| mu.Lock() | ||
| if perKeyActive[key] { | ||
| sameKeyOverlap = true | ||
| } | ||
| perKeyActive[key] = true | ||
| inFlight++ | ||
| if inFlight > maxConcurrent { | ||
| maxConcurrent = inFlight | ||
| } | ||
| mu.Unlock() | ||
|
|
||
| // Hold the key briefly so that concurrent processing of distinct keys is observable. | ||
| time.Sleep(20 * time.Millisecond) | ||
|
|
||
| mu.Lock() | ||
| inFlight-- | ||
| perKeyActive[key] = false | ||
| processed++ | ||
| allDone := processed == numKeys | ||
| mu.Unlock() | ||
|
|
||
| if allDone { | ||
| queue.ShutDown() | ||
| } | ||
| return true | ||
| } | ||
|
|
||
| var wg sync.WaitGroup | ||
| for range numWorkers { | ||
| wg.Go(func() { | ||
| for processNext() { | ||
| } | ||
| }) | ||
| } | ||
| wg.Wait() | ||
|
|
||
| mu.Lock() | ||
| defer mu.Unlock() | ||
| assert.Equal(t, numKeys, processed, "every distinct key should be processed exactly once") | ||
| assert.False(t, sameKeyOverlap, "the same hydration key must never be processed by two workers at once") | ||
| assert.GreaterOrEqual(t, maxConcurrent, 2, "distinct hydration keys should be processed concurrently with multiple workers") | ||
| } | ||
|
|
||
| // TestHydrationQueue_SameKeyNotProcessedConcurrently asserts the dedup guarantee the feature relies on: a | ||
| // hydration key that is re-enqueued while it is still in-flight is withheld until the in-flight processing | ||
| // calls Done, so the same key is never handed to two workers simultaneously. See #27926. | ||
| func TestHydrationQueue_SameKeyNotProcessedConcurrently(t *testing.T) { | ||
| t.Parallel() | ||
|
|
||
| queue := newTestHydrationQueue() | ||
| t.Cleanup(queue.ShutDown) | ||
|
|
||
| key := hydratortypes.HydrationQueueKey{SourceRepoURL: "https://example.com/repo", DestinationBranch: "env/dev"} | ||
| queue.Add(key) | ||
|
|
||
| started := make(chan struct{}) | ||
| release := make(chan struct{}) | ||
| secondPickup := make(chan hydratortypes.HydrationQueueKey, 1) | ||
|
|
||
| // Worker 1 takes the key and holds it (does not call Done) until released. | ||
| go func() { | ||
| k, shutdown := queue.Get() | ||
| if shutdown { | ||
| return | ||
| } | ||
| close(started) | ||
| <-release | ||
| queue.Done(k) | ||
| }() | ||
|
|
||
| <-started | ||
| // Re-enqueue the same key while it is still in-flight. The workqueue must not hand it to another | ||
| // worker until the first one calls Done. | ||
| queue.Add(key) | ||
|
|
||
| // Worker 2 attempts to take work; it must block while the key is in-flight. | ||
| go func() { | ||
| k, shutdown := queue.Get() | ||
| if !shutdown { | ||
| secondPickup <- k | ||
| } | ||
| }() | ||
|
|
||
| select { | ||
| case <-secondPickup: | ||
| t.Fatal("the same hydration key was delivered to a second worker while still in-flight") | ||
| case <-time.After(150 * time.Millisecond): | ||
| // Expected: the re-added key is withheld until the first worker calls Done. | ||
| } | ||
|
|
||
| // Release the first worker; the re-added key should now become available to worker 2. | ||
| close(release) | ||
| select { | ||
| case got := <-secondPickup: | ||
| assert.Equal(t, key, got) | ||
| queue.Done(got) | ||
| case <-time.After(2 * time.Second): | ||
| t.Fatal("re-added key was not delivered after the first worker finished") | ||
| } | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.