Skip to content

Commit

Permalink
feat: truncate long labels in nodebalancers
Browse files Browse the repository at this point in the history
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;
  • Loading branch information
wbh1 committed Mar 8, 2023
1 parent 0e0250e commit 56e66f6
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions cloud/linode/loadbalancers.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
}

Expand Down

0 comments on commit 56e66f6

Please sign in to comment.