Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions cloud/linode/cloud.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ var Options struct {
ClusterCIDRIPv4 string
NodeCIDRMaskSizeIPv4 int
NodeCIDRMaskSizeIPv6 int
LoadBalancerPrefix string
}

type linodeCloud struct {
Expand All @@ -71,6 +72,7 @@ type linodeCloud struct {
var (
instanceCache *instances
ipHolderCharLimit int = 23
LoadBalancerPrefixCharLimit int = 20
)

func init() {
Expand Down Expand Up @@ -193,6 +195,12 @@ func newCloud() (cloudprovider.Interface, error) {
return nil, fmt.Errorf("%s", msg)
}

if len(Options.LoadBalancerPrefix) > LoadBalancerPrefixCharLimit {
msg := fmt.Sprintf("load-balancer-prefix must be %d characters or less: %s is %d characters\n", LoadBalancerPrefixCharLimit, Options.LoadBalancerPrefix, len(Options.LoadBalancerPrefix))
Copy link

Copilot AI Jul 17, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove the trailing newline in the formatted error message and replace fmt.Errorf("%s", msg) with errors.New(msg) to avoid redundant wrapping and ensure error messages don't include unintended line breaks.

Copilot uses AI. Check for mistakes.
klog.Error(msg)
return nil, fmt.Errorf("%s", msg)
}

// create struct that satisfies cloudprovider.Interface
lcloud := &linodeCloud{
client: linodeClient,
Expand Down
10 changes: 10 additions & 0 deletions cloud/linode/cloud_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,16 @@ func TestNewCloud(t *testing.T) {
_, err := newCloud()
assert.Error(t, err, "expected error if ipholdersuffix is longer than 23 chars")
})

t.Run("should fail if load-balancer-prefix is longer than 20 chars", func(t *testing.T) {
prefix := Options.LoadBalancerPrefix
Options.LoadBalancerPrefix = strings.Repeat("a", 21)
defer func() {
Options.LoadBalancerPrefix = prefix
}()
_, err := newCloud()
assert.Error(t, err, "expected error if load-balancer-prefix is longer than 20 chars")
})
}

func Test_linodeCloud_LoadBalancer(t *testing.T) {
Expand Down
2 changes: 1 addition & 1 deletion cloud/linode/loadbalancers.go
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ func (l *loadbalancers) cleanupOldNodeBalancer(ctx context.Context, service *v1.
// GetLoadBalancer will not modify service.
func (l *loadbalancers) GetLoadBalancerName(_ context.Context, _ string, _ *v1.Service) string {
unixNano := strconv.FormatInt(time.Now().UnixNano(), 16)
return fmt.Sprintf("ccm-%s", unixNano[len(unixNano)-12:])
return fmt.Sprintf("%s%s", Options.LoadBalancerPrefix, unixNano[len(unixNano)-12:])
}

// GetLoadBalancer returns the *v1.LoadBalancerStatus of service.
Expand Down
1 change: 1 addition & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ func main() {
command.Flags().IntVar(&linode.Options.NodeBalancerBackendIPv4SubnetID, "nodebalancer-backend-ipv4-subnet-id", 0, "ipv4 subnet id to use for NodeBalancer backends")
command.Flags().StringVar(&linode.Options.NodeBalancerBackendIPv4SubnetName, "nodebalancer-backend-ipv4-subnet-name", "", "ipv4 subnet name to use for NodeBalancer backends")
command.Flags().BoolVar(&linode.Options.DisableNodeBalancerVPCBackends, "disable-nodebalancer-vpc-backends", false, "disables nodebalancer backends in VPCs (when enabled, nodebalancers will only have private IPs as backends for backward compatibility)")
command.Flags().StringVar(&linode.Options.LoadBalancerPrefix, "load-balancer-prefix", "ccm-", "Name prefix for LoadBalancers. (max. 20 char.)")
Comment thread
adamginna-akamai marked this conversation as resolved.
Outdated

// Set static flags
command.Flags().VisitAll(func(fl *pflag.Flag) {
Expand Down
Loading