Skip to content

Commit

Permalink
Use unique controller name
Browse files Browse the repository at this point in the history
  • Loading branch information
sjberman committed Aug 15, 2024
1 parent 1632d7c commit c2b903b
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 1 deletion.
3 changes: 2 additions & 1 deletion internal/framework/controller/register.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ func defaultConfig() config {
func Register(
ctx context.Context,
objectType ngftypes.ObjectType,
name string,
mgr manager.Manager,
eventCh chan<- interface{},
options ...Option,
Expand Down Expand Up @@ -114,7 +115,7 @@ func Register(
forOpts = append(forOpts, ctlrBuilder.OnlyMetadata)
}

builder := ctlr.NewControllerManagedBy(mgr).For(objectType, forOpts...)
builder := ctlr.NewControllerManagedBy(mgr).Named(name).For(objectType, forOpts...)

if cfg.k8sPredicate != nil {
builder = builder.WithEventFilter(cfg.k8sPredicate)
Expand Down
1 change: 1 addition & 0 deletions internal/framework/controller/register_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@ func TestRegister(t *testing.T) {
return controller.Register(
context.Background(),
test.objectType,
test.msg, // unique controller name for each loop iteration
test.fakes.mgr,
eventCh,
controller.WithNamespacedNameFilter(nsNameFilter),
Expand Down
1 change: 1 addition & 0 deletions internal/mode/provisioner/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ func StartManager(cfg Config) error {
if err := controller.Register(
ctx,
regCfg.objectType,
regCfg.objectType.GetObjectKind().GroupVersionKind().Kind,

Check warning on line 97 in internal/mode/provisioner/manager.go

View check run for this annotation

Codecov / codecov/patch

internal/mode/provisioner/manager.go#L97

Added line #L97 was not covered by tests
mgr,
eventCh,
regCfg.options...,
Expand Down
9 changes: 9 additions & 0 deletions internal/mode/static/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -356,6 +356,7 @@ func registerControllers(
controlConfigNSName types.NamespacedName,
) error {
type ctlrCfg struct {
name string

Check warning on line 359 in internal/mode/static/manager.go

View check run for this annotation

Codecov / codecov/patch

internal/mode/static/manager.go#L359

Added line #L359 was not covered by tests
objectType ngftypes.ObjectType
options []controller.Option
}
Expand Down Expand Up @@ -402,12 +403,14 @@ func registerControllers(
},
{
objectType: &apiv1.Service{},
name: "user-service",
options: []controller.Option{
controller.WithK8sPredicate(predicate.ServicePortsChangedPredicate{}),
},
},
{
objectType: &apiv1.Service{},
name: "ngf-service",
options: func() []controller.Option {
svcNSName := types.NamespacedName{
Namespace: cfg.GatewayPodConfig.Namespace,
Expand Down Expand Up @@ -521,9 +524,15 @@ func registerControllers(
}

for _, regCfg := range controllerRegCfgs {
name := regCfg.objectType.GetObjectKind().GroupVersionKind().Kind
if regCfg.name != "" {
name = regCfg.name

Check warning on line 529 in internal/mode/static/manager.go

View check run for this annotation

Codecov / codecov/patch

internal/mode/static/manager.go#L527-L529

Added lines #L527 - L529 were not covered by tests
}

if err := controller.Register(
ctx,
regCfg.objectType,
name,

Check warning on line 535 in internal/mode/static/manager.go

View check run for this annotation

Codecov / codecov/patch

internal/mode/static/manager.go#L535

Added line #L535 was not covered by tests
mgr,
eventCh,
regCfg.options...,
Expand Down

0 comments on commit c2b903b

Please sign in to comment.