From a82ac4fdc73ad0cdd2710c6d7815f6aed1130c82 Mon Sep 17 00:00:00 2001 From: robertlestak Date: Mon, 28 Feb 2022 19:37:53 -0800 Subject: [PATCH] servicelb pool selector adds a new optional node label "svccontroller.k3s.cattle.io/lbpool=" that can be set on nodes. ServiceType: LoadBalancer services can then specify a matching label, which will schedule the DaemonSet only on specified nodes. This allows operators to specify different pools of nodes that can serve different LoadBalancer services on the same ports. Signed-off-by: robertlestak --- pkg/servicelb/controller.go | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/pkg/servicelb/controller.go b/pkg/servicelb/controller.go index 7f89052fb1..18585f7b96 100644 --- a/pkg/servicelb/controller.go +++ b/pkg/servicelb/controller.go @@ -32,10 +32,11 @@ import ( ) var ( - svcNameLabel = "svccontroller." + version.Program + ".cattle.io/svcname" - daemonsetNodeLabel = "svccontroller." + version.Program + ".cattle.io/enablelb" - nodeSelectorLabel = "svccontroller." + version.Program + ".cattle.io/nodeselector" - DefaultLBImage = "rancher/klipper-lb:v0.3.4" + svcNameLabel = "svccontroller." + version.Program + ".cattle.io/svcname" + daemonsetNodeLabel = "svccontroller." + version.Program + ".cattle.io/enablelb" + daemonsetNodePoolLabel = "svccontroller." + version.Program + ".cattle.io/lbpool" + nodeSelectorLabel = "svccontroller." + version.Program + ".cattle.io/nodeselector" + DefaultLBImage = "rancher/klipper-lb:v0.3.4" ) const ( @@ -499,6 +500,10 @@ func (h *handler) newDaemonSet(svc *core.Service) (*apps.DaemonSet, error) { ds.Spec.Template.Spec.NodeSelector = map[string]string{ daemonsetNodeLabel: "true", } + // Add node selector for "svccontroller.k3s.cattle.io/lbpool=" if service has lbpool label + if svc.Labels[daemonsetNodePoolLabel] != "" { + ds.Spec.Template.Spec.NodeSelector[daemonsetNodePoolLabel] = svc.Labels[daemonsetNodePoolLabel] + } ds.Labels[nodeSelectorLabel] = "true" } return ds, nil