From 56e66f685b382ec93fdd7096f97913d2c7bd0875 Mon Sep 17 00:00:00 2001 From: Will Hegedus Date: Wed, 8 Mar 2023 14:50:35 -0500 Subject: [PATCH] feat: truncate long labels in nodebalancers Nodebalancer backends can have a max label length of 32 chars. If a k8s node's name is longer than 32 chars, creating a nodebalancer fails. Example error: E0307 22:31:47.275176 1 controller.go:307] error processing service traefik/traefik (will retry): failed to ensure load balancer: [400] [configs[0].nodes[0].label] Length must be 3-32 characters; [configs[0].nodes[1].label] Length must be 3-32 characters; [configs[0].nodes[2].label] Length must be 3-32 characters; --- cloud/linode/loadbalancers.go | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/cloud/linode/loadbalancers.go b/cloud/linode/loadbalancers.go index 92c04b6f..c0b0917e 100644 --- a/cloud/linode/loadbalancers.go +++ b/cloud/linode/loadbalancers.go @@ -601,12 +601,20 @@ func (l *loadbalancers) buildLoadBalancerRequest(ctx context.Context, clusterNam return l.createNodeBalancer(ctx, clusterName, service, configs) } +func trimString(s string, maxLen int) string { + if len(s) > maxLen { + return s[:maxLen] + } + return s +} + func (l *loadbalancers) buildNodeBalancerNodeCreateOptions(node *v1.Node, nodePort int32) linodego.NodeBalancerNodeCreateOptions { return linodego.NodeBalancerNodeCreateOptions{ Address: fmt.Sprintf("%v:%v", getNodeInternalIP(node), nodePort), - Label: node.Name, - Mode: "accept", - Weight: 100, + // NodeBalancer backends must be 3-32 chars in length + Label: trimString(node.Name, 32), + Mode: "accept", + Weight: 100, } }