Skip to content

Commit 2c9e60a

Browse files
committed
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;
1 parent 4ced791 commit 2c9e60a

1 file changed

Lines changed: 11 additions & 3 deletions

File tree

cloud/linode/loadbalancers.go

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -644,12 +644,20 @@ func (l *loadbalancers) buildLoadBalancerRequest(ctx context.Context, clusterNam
644644
return l.createNodeBalancer(ctx, clusterName, service, configs)
645645
}
646646

647+
func trimString(s string, maxLen int) string {
648+
if len(s) > maxLen {
649+
return s[:maxLen]
650+
}
651+
return s
652+
}
653+
647654
func (l *loadbalancers) buildNodeBalancerNodeCreateOptions(node *v1.Node, nodePort int32) linodego.NodeBalancerNodeCreateOptions {
648655
return linodego.NodeBalancerNodeCreateOptions{
649656
Address: fmt.Sprintf("%v:%v", getNodePrivateIP(node), nodePort),
650-
Label: node.Name,
651-
Mode: "accept",
652-
Weight: 100,
657+
// NodeBalancer backends must be 3-32 chars in length
658+
Label: trimString(node.Name, 32),
659+
Mode: "accept",
660+
Weight: 100,
653661
}
654662
}
655663

0 commit comments

Comments
 (0)