From 54ae8d2126872f7dff9e586530eaffa21a52ad49 Mon Sep 17 00:00:00 2001 From: Enrico Candino Date: Tue, 24 Jun 2025 23:56:14 +0200 Subject: [PATCH] add named controller (#394) --- k3k-kubelet/controller/configmap.go | 6 ++++++ k3k-kubelet/controller/handler.go | 2 ++ k3k-kubelet/controller/secret.go | 6 ++++++ 3 files changed, 14 insertions(+) diff --git a/k3k-kubelet/controller/configmap.go b/k3k-kubelet/controller/configmap.go index 0c9d23f2..b3167e09 100644 --- a/k3k-kubelet/controller/configmap.go +++ b/k3k-kubelet/controller/configmap.go @@ -16,6 +16,8 @@ import ( "sigs.k8s.io/controller-runtime/pkg/reconcile" ) +const ConfigMapSyncerName = "configmap-syncer" + type ConfigMapSyncer struct { mutex sync.RWMutex // VirtualClient is the client for the virtual cluster @@ -32,6 +34,10 @@ type ConfigMapSyncer struct { objs sets.Set[types.NamespacedName] } +func (c *ConfigMapSyncer) Name() string { + return ConfigMapSyncerName +} + // Reconcile implements reconcile.Reconciler and synchronizes the objects in objs to the host cluster func (c *ConfigMapSyncer) Reconcile(ctx context.Context, req reconcile.Request) (reconcile.Result, error) { if !c.isWatching(req.NamespacedName) { diff --git a/k3k-kubelet/controller/handler.go b/k3k-kubelet/controller/handler.go index b4a9fb61..7f4bedbb 100644 --- a/k3k-kubelet/controller/handler.go +++ b/k3k-kubelet/controller/handler.go @@ -39,6 +39,7 @@ type ControllerHandler struct { // be altered through the Add and Remove methods type updateableReconciler interface { reconcile.Reconciler + Name() string AddResource(ctx context.Context, namespace string, name string) error RemoveResource(ctx context.Context, namespace string, name string) error } @@ -97,6 +98,7 @@ func (c *ControllerHandler) AddResource(ctx context.Context, obj client.Object) } err := ctrl.NewControllerManagedBy(c.Mgr). + Named(r.Name()). For(&v1.ConfigMap{}). Complete(r) diff --git a/k3k-kubelet/controller/secret.go b/k3k-kubelet/controller/secret.go index 85b1156d..e3a4c9ff 100644 --- a/k3k-kubelet/controller/secret.go +++ b/k3k-kubelet/controller/secret.go @@ -16,6 +16,8 @@ import ( "sigs.k8s.io/controller-runtime/pkg/reconcile" ) +const SecretSyncerName = "secret-syncer" + type SecretSyncer struct { mutex sync.RWMutex // VirtualClient is the client for the virtual cluster @@ -32,6 +34,10 @@ type SecretSyncer struct { objs sets.Set[types.NamespacedName] } +func (s *SecretSyncer) Name() string { + return SecretSyncerName +} + // Reconcile implements reconcile.Reconciler and synchronizes the objects in objs to the host cluster func (s *SecretSyncer) Reconcile(ctx context.Context, req reconcile.Request) (reconcile.Result, error) { if !s.isWatching(req.NamespacedName) {