Skip to content
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

chore(backport release-1.0): fix: sharded Warehouse cross-controller access #2820

Merged
merged 1 commit into from
Oct 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions cmd/controlplane/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -194,10 +194,12 @@
},
},
Cache: cache.Options{
// Ensure that the controller only watches resources in the shard
// it is responsible for.
// When Kargo is sharded, we expect the controller to only handle
// resources in the shard it is responsible for. This is enforced
// by the following label selectors on the informers, EXCEPT for
// Warehouses — which should be accessible by all controllers in
// a sharded setup, but handled by only one controller at a time.

Check warning on line 201 in cmd/controlplane/controller.go

View check run for this annotation

Codecov / codecov/patch

cmd/controlplane/controller.go#L197-L201

Added lines #L197 - L201 were not covered by tests
ByObject: map[client.Object]cache.ByObject{
&kargoapi.Warehouse{}: {Label: shardSelector},
&kargoapi.Stage{}: {Label: shardSelector},
&kargoapi.Promotion{}: {Label: shardSelector},
},
Expand Down Expand Up @@ -311,6 +313,7 @@
if err := warehouses.SetupReconcilerWithManager(
kargoMgr,
credentialsDB,
o.ShardName,

Check warning on line 316 in cmd/controlplane/controller.go

View check run for this annotation

Codecov / codecov/patch

cmd/controlplane/controller.go#L316

Added line #L316 was not covered by tests
); err != nil {
return fmt.Errorf("error setting up Warehouses reconciler: %w", err)
}
Expand Down
7 changes: 7 additions & 0 deletions internal/controller/warehouses/warehouses.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,13 @@
func SetupReconcilerWithManager(
mgr manager.Manager,
credentialsDB credentials.Database,
shardName string,
) error {
shardPredicate, err := controller.GetShardPredicate(shardName)
if err != nil {
return fmt.Errorf("error creating shard selector predicate: %w", err)
}

Check warning on line 77 in internal/controller/warehouses/warehouses.go

View check run for this annotation

Codecov / codecov/patch

internal/controller/warehouses/warehouses.go#L74-L77

Added lines #L74 - L77 were not covered by tests

if err := ctrl.NewControllerManagedBy(mgr).
For(&kargoapi.Warehouse{}).
WithEventFilter(
Expand All @@ -86,6 +92,7 @@
kargo.RefreshRequested{},
),
).
WithEventFilter(shardPredicate).
WithOptions(controller.CommonOptions()).
Complete(newReconciler(mgr.GetClient(), credentialsDB)); err != nil {
return fmt.Errorf("error building Warehouse reconciler: %w", err)
Expand Down