From ced4d37eda825959758bb4933b808ef65a79898f Mon Sep 17 00:00:00 2001 From: Reed Schalo Date: Mon, 30 Sep 2024 14:05:24 -0700 Subject: [PATCH] fix: conditionally enable migration controllers based on webhook enablement (#1723) --- kwok/main.go | 1 + pkg/controllers/controllers.go | 17 +++++++++++++---- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/kwok/main.go b/kwok/main.go index e44d7ce1d9..eb6e7ec281 100644 --- a/kwok/main.go +++ b/kwok/main.go @@ -36,6 +36,7 @@ func main() { op. WithWebhooks(ctx, webhooks.NewWebhooks()...). WithControllers(ctx, controllers.NewControllers( + ctx, op.Manager, op.Clock, op.GetClient(), diff --git a/pkg/controllers/controllers.go b/pkg/controllers/controllers.go index e3f3ac3a5c..ad18dd18a0 100644 --- a/pkg/controllers/controllers.go +++ b/pkg/controllers/controllers.go @@ -17,6 +17,8 @@ limitations under the License. package controllers import ( + "context" + "github.com/awslabs/operatorpkg/controller" "github.com/awslabs/operatorpkg/status" "k8s.io/utils/clock" @@ -24,6 +26,7 @@ import ( "sigs.k8s.io/controller-runtime/pkg/manager" v1 "sigs.k8s.io/karpenter/pkg/apis/v1" + "sigs.k8s.io/karpenter/pkg/operator/options" migrationcrd "sigs.k8s.io/karpenter/pkg/controllers/migration/crd" migration "sigs.k8s.io/karpenter/pkg/controllers/migration/resource" @@ -55,6 +58,7 @@ import ( ) func NewControllers( + ctx context.Context, mgr manager.Manager, clock clock.Clock, kubeClient client.Client, @@ -67,7 +71,7 @@ func NewControllers( evictionQueue := terminator.NewQueue(kubeClient, recorder) disruptionQueue := orchestration.NewQueue(kubeClient, recorder, cluster, clock, p) - return []controller.Controller{ + controllers := []controller.Controller{ p, evictionQueue, disruptionQueue, disruption.NewController(clock, kubeClient, p, cloudProvider, recorder, cluster, disruptionQueue), provisioning.NewPodController(kubeClient, p), @@ -95,8 +99,13 @@ func NewControllers( leasegarbagecollection.NewController(kubeClient), status.NewController[*v1.NodeClaim](kubeClient, mgr.GetEventRecorderFor("karpenter")), status.NewController[*v1.NodePool](kubeClient, mgr.GetEventRecorderFor("karpenter")), - migration.NewController[*v1.NodeClaim](kubeClient), - migration.NewController[*v1.NodePool](kubeClient), - migrationcrd.NewController(kubeClient, cloudProvider), } + + if !options.FromContext(ctx).DisableWebhook { + controllers = append(controllers, migration.NewController[*v1.NodeClaim](kubeClient)) + controllers = append(controllers, migration.NewController[*v1.NodePool](kubeClient)) + controllers = append(controllers, migrationcrd.NewController(kubeClient, cloudProvider)) + } + + return controllers }