From 6807dfd7ea7a4221cb3b8612f4ca0ee490026389 Mon Sep 17 00:00:00 2001 From: Tom Wieczorek Date: Thu, 5 Dec 2024 10:30:14 +0100 Subject: [PATCH] Reuse boolean for toggling the k0s endpoint reconciler In the controller start function, the condition to determine whether to use the k0s endpoint reconciler was written twice in very distant parts of that function. Reuse the boolean value instead. Also, rename it to a more appropriate name: There are actually two different reconcilers at play: The default one built into the API server, and k0's own implementation of it. Make it clear which implementation the boolean refers to. Signed-off-by: Tom Wieczorek --- cmd/controller/controller.go | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/cmd/controller/controller.go b/cmd/controller/controller.go index ade3efee648c..15226f20a9bf 100644 --- a/cmd/controller/controller.go +++ b/cmd/controller/controller.go @@ -254,8 +254,8 @@ func (c *command) start(ctx context.Context) error { } enableKonnectivity := !c.SingleNode && !slices.Contains(c.DisableComponents, constant.KonnectivityServerComponentName) - disableEndpointReconciler := !slices.Contains(c.DisableComponents, constant.APIEndpointReconcilerComponentName) && - nodeConfig.Spec.API.ExternalAddress != "" + enableK0sEndpointReconciler := nodeConfig.Spec.API.ExternalAddress != "" && + !slices.Contains(c.DisableComponents, constant.APIEndpointReconcilerComponentName) if enableKonnectivity { nodeComponents.Add(ctx, &controller.Konnectivity{ @@ -267,12 +267,14 @@ func (c *command) start(ctx context.Context) error { } nodeComponents.Add(ctx, &controller.APIServer{ - ClusterConfig: nodeConfig, - K0sVars: c.K0sVars, - LogLevel: c.LogLevels.KubeAPIServer, - Storage: storageBackend, - EnableKonnectivity: enableKonnectivity, - DisableEndpointReconciler: disableEndpointReconciler, + ClusterConfig: nodeConfig, + K0sVars: c.K0sVars, + LogLevel: c.LogLevels.KubeAPIServer, + Storage: storageBackend, + EnableKonnectivity: enableKonnectivity, + + // If k0s reconciles the kubernetes endpoint, the API server shouldn't do it. + DisableEndpointReconciler: enableK0sEndpointReconciler, }) if !c.SingleNode { @@ -442,7 +444,7 @@ func (c *command) start(ctx context.Context) error { clusterComponents.Add(ctx, controller.NewCRD(manifestsSaver, "autopilot")) } - if !slices.Contains(c.DisableComponents, constant.APIEndpointReconcilerComponentName) && nodeConfig.Spec.API.ExternalAddress != "" { + if enableK0sEndpointReconciler { clusterComponents.Add(ctx, controller.NewEndpointReconciler( nodeConfig, leaderElector,