Skip to content

Commit

Permalink
fix: sharded Warehouse cross-controller access (#2819)
Browse files Browse the repository at this point in the history
Signed-off-by: Hidde Beydals <hidde@hhh.computer>
(cherry picked from commit 7490ff2)
  • Loading branch information
hiddeco authored and github-actions[bot] committed Oct 23, 2024
1 parent 63ce8a5 commit 638c52a
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
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 @@ func (o *controllerOptions) setupKargoManager(
},
},
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 @@ func (o *controllerOptions) setupReconcilers(
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 @@ type reconciler struct {
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 @@ func SetupReconcilerWithManager(
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

0 comments on commit 638c52a

Please sign in to comment.