Skip to content
Open
Show file tree
Hide file tree
Changes from all 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
3 changes: 3 additions & 0 deletions cloud/linode/services/vpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,9 @@ func GetVPCIPv6Addresses(ctx context.Context, linodeClient client.Client, vpcNam
// It uses the first VPC name from Options.VPCNames to find the VPC ID and then retrieves the subnet ID
// for the NodeBalancer backend IPv4 subnet name specified in Options.NodeBalancerBackendIPv4SubnetName.
func GetNodeBalancerBackendIPv4SubnetID(linodeClient client.Client) (int, error) {
if len(options.Options.VPCNames) == 0 {
return 0, fmt.Errorf("--nodebalancer-backend-ipv4-subnet-name %q requires --vpc-names or --vpc-ids to be set", options.Options.NodeBalancerBackendIPv4SubnetName)
}
// Get the VPC ID from the name
vpcID, err := GetVPCID(context.TODO(), linodeClient, options.Options.VPCNames[0])
if err != nil {
Expand Down
19 changes: 19 additions & 0 deletions cloud/linode/services/vpc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,25 @@ func TestGetSubnetID(t *testing.T) {
}

func TestGetNodeBalancerBackendIPv4SubnetID(t *testing.T) {
t.Run("No VPC configured", func(t *testing.T) {
ctrl := gomock.NewController(t)
defer ctrl.Finish()
client := mocks.NewMockClient(ctrl)
currVPCNames := options.Options.VPCNames
currNodeBalancerBackendIPv4SubnetName := options.Options.NodeBalancerBackendIPv4SubnetName
defer func() {
options.Options.VPCNames = currVPCNames
options.Options.NodeBalancerBackendIPv4SubnetName = currNodeBalancerBackendIPv4SubnetName
}()
options.Options.VPCNames = nil
options.Options.NodeBalancerBackendIPv4SubnetName = "nb-backends"
subnetID, err := GetNodeBalancerBackendIPv4SubnetID(client)
require.ErrorContains(t, err, "requires --vpc-names or --vpc-ids")
if subnetID != 0 {
t.Errorf("getNodeBalancerBackendIPv4SubnetID() = %v, want %v", subnetID, 0)
}
})

t.Run("VPC not found", func(t *testing.T) {
ctrl := gomock.NewController(t)
defer ctrl.Finish()
Expand Down
Loading