From 1b696b1843a87d85d35e51d1cfa318c5c27ee9bc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juan-Luis=20de=20Sousa-Valadas=20Casta=C3=B1o?= Date: Thu, 2 Jan 2025 12:01:00 +0100 Subject: [PATCH] Allow to disable CPLB load balancer MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This is one of the remaining tasks of #5279. The intended use case for this is to allow to use the VIPs functionality while using some user provided load balancer such as HAProxy, nginx, etc... Signed-off-by: Juan-Luis de Sousa-Valadas CastaƱo --- pkg/apis/k0s/v1beta1/cplb.go | 3 +++ pkg/component/controller/cplb/cplb_linux.go | 17 ++++++++++------- .../k0s/k0s.k0sproject.io_clusterconfigs.yaml | 3 +++ 3 files changed, 16 insertions(+), 7 deletions(-) diff --git a/pkg/apis/k0s/v1beta1/cplb.go b/pkg/apis/k0s/v1beta1/cplb.go index f38bdd504a3e..a942d3dda567 100644 --- a/pkg/apis/k0s/v1beta1/cplb.go +++ b/pkg/apis/k0s/v1beta1/cplb.go @@ -75,6 +75,9 @@ type KeepalivedSpec struct { // +kubebuilder:validation:Maximum=65535 // +optional UserSpaceProxyPort int `json:"userSpaceProxyBindPort,omitempty"` + // DisableLoadBalanmcer disables the load balancer. + // +optional + DisableLoadBalancer bool `json:"disableLoadBalancer,omitempty"` } // VRRPInstances is a list of VRRPInstance diff --git a/pkg/component/controller/cplb/cplb_linux.go b/pkg/component/controller/cplb/cplb_linux.go index 0496ffa08c48..24c54a4c58ad 100644 --- a/pkg/component/controller/cplb/cplb_linux.go +++ b/pkg/component/controller/cplb/cplb_linux.go @@ -100,13 +100,15 @@ func (k *Keepalived) Start(ctx context.Context) error { } } - if len(k.Config.VRRPInstances) > 0 || len(k.Config.VirtualServers) > 0 { - k.log.Info("Starting CPLB reconciler") - updateCh := make(chan struct{}, 1) - k.reconciler = NewCPLBReconciler(k.KubeConfigPath, updateCh) - k.updateCh = updateCh - if err := k.reconciler.Start(); err != nil { - return fmt.Errorf("failed to start CPLB reconciler: %w", err) + if !k.Config.DisableLoadBalancer { + if len(k.Config.VRRPInstances) > 0 || len(k.Config.VirtualServers) > 0 { + k.log.Info("Starting CPLB reconciler") + updateCh := make(chan struct{}, 1) + k.reconciler = NewCPLBReconciler(k.KubeConfigPath, updateCh) + k.updateCh = updateCh + if err := k.reconciler.Start(); err != nil { + return fmt.Errorf("failed to start CPLB reconciler: %w", err) + } } } @@ -160,6 +162,7 @@ func (k *Keepalived) Start(ctx context.Context) error { } }() } + return k.supervisor.Supervise() } diff --git a/static/_crds/k0s/k0s.k0sproject.io_clusterconfigs.yaml b/static/_crds/k0s/k0s.k0sproject.io_clusterconfigs.yaml index a9a3da692bb7..b1fc5d6f6cc7 100644 --- a/static/_crds/k0s/k0s.k0sproject.io_clusterconfigs.yaml +++ b/static/_crds/k0s/k0s.k0sproject.io_clusterconfigs.yaml @@ -508,6 +508,9 @@ spec: Keepalived contains configuration options related to the "Keepalived" type of load balancing. properties: + disableLoadBalancer: + description: DisableLoadBalanmcer disables the load balancer. + type: boolean userSpaceProxyBindPort: default: 6444 description: |-