Skip to content

Commit

Permalink
fix: ensure unique controller names to satisfy controller-runtime
Browse files Browse the repository at this point in the history
controller-runtime complains at runtime if two registered controllers
have the same name

Signed-off-by: Rohan CJ <rohantmp@gmail.com>
  • Loading branch information
rohantmp committed Oct 7, 2024
1 parent 6006c69 commit d3c3d40
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
13 changes: 8 additions & 5 deletions pkg/controllers/register.go
Original file line number Diff line number Diff line change
Expand Up @@ -156,14 +156,16 @@ func registerServiceSyncControllers(ctx *synccontext.ControllerContext) error {
globalLocalManager.GetCache().WaitForCacheSync(ctx)

// register controller
name := "map-host-service-syncer"
controller := &servicesync.ServiceSyncer{
SyncContext: ctx.ToRegisterContext().ToSyncContext("map-host-service-syncer"),
Name: name,
SyncContext: ctx.ToRegisterContext().ToSyncContext(name),
SyncServices: mapping,
CreateNamespace: true,
CreateEndpoints: true,
From: globalLocalManager,
To: ctx.VirtualManager,
Log: loghelper.New("map-host-service-syncer"),
Log: loghelper.New(name),
}
err = controller.Register()
if err != nil {
Expand All @@ -176,14 +178,15 @@ func registerServiceSyncControllers(ctx *synccontext.ControllerContext) error {
if err != nil {
return errors.Wrap(err, "parse physical service mapping")
}

name := "map-virtual-service-syncer"
controller := &servicesync.ServiceSyncer{
SyncContext: ctx.ToRegisterContext().ToSyncContext("map-virtual-service-syncer"),
Name: name,
SyncContext: ctx.ToRegisterContext().ToSyncContext(name),
SyncServices: mapping,
IsVirtualToHostSyncer: true,
From: ctx.VirtualManager,
To: ctx.LocalManager,
Log: loghelper.New("map-virtual-service-syncer"),
Log: loghelper.New(name),
}

if ctx.Config.Experimental.MultiNamespaceMode.Enabled {
Expand Down
4 changes: 3 additions & 1 deletion pkg/controllers/servicesync/servicesync.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package servicesync

import (
"context"
"fmt"
"strings"

"github.com/loft-sh/vcluster/pkg/constants"
Expand All @@ -22,6 +23,7 @@ import (
)

type ServiceSyncer struct {
Name string
SyncContext *synccontext.SyncContext

SyncServices map[string]types.NamespacedName
Expand Down Expand Up @@ -50,7 +52,7 @@ func (e *ServiceSyncer) Register() error {
WithOptions(controller.Options{
CacheSyncTimeout: constants.DefaultCacheSyncTimeout,
}).
Named("servicesync").
Named(fmt.Sprintf("servicesyncer-%s", e.Name)).
For(&corev1.Service{}).
WatchesRawSource(source.Kind(e.To.GetCache(), &corev1.Service{}, handler.TypedEnqueueRequestsFromMapFunc(func(_ context.Context, object *corev1.Service) []reconcile.Request {
if object == nil {
Expand Down

0 comments on commit d3c3d40

Please sign in to comment.