Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[fix] respect vlan interface if defined in linodemachine #562

Merged
merged 1 commit into from
Nov 5, 2024
Merged
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
13 changes: 11 additions & 2 deletions controller/linodemachine_controller_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,8 +129,9 @@

// if vlan is enabled, attach additional interface as eth0 to linode
if machineScope.LinodeCluster.Spec.Network.UseVlan {
iface, err := getVlanInterfaceConfig(ctx, machineScope, logger)
iface, err := getVlanInterfaceConfig(ctx, machineScope, createConfig.Interfaces, logger)
if err != nil {
logger.Error(err, "Failed to get VLAN interface config")

Check warning on line 134 in controller/linodemachine_controller_helpers.go

View check run for this annotation

Codecov / codecov/patch

controller/linodemachine_controller_helpers.go#L134

Added line #L134 was not covered by tests
return nil, err
}
if iface != nil {
Expand Down Expand Up @@ -363,7 +364,7 @@
return *linodeFirewall.Spec.FirewallID, nil
}

func getVlanInterfaceConfig(ctx context.Context, machineScope *scope.MachineScope, logger logr.Logger) (*linodego.InstanceConfigInterfaceCreateOptions, error) {
func getVlanInterfaceConfig(ctx context.Context, machineScope *scope.MachineScope, interfaces []linodego.InstanceConfigInterfaceCreateOptions, logger logr.Logger) (*linodego.InstanceConfigInterfaceCreateOptions, error) {
logger = logger.WithValues("vlanName", machineScope.Cluster.Name)

// Try to obtain a IP for the machine using its name
Expand All @@ -373,6 +374,14 @@
}

logger.Info("obtained IP for machine", "name", machineScope.LinodeMachine.Name, "ip", ip)

for i, netInterface := range interfaces {
if netInterface.Purpose == linodego.InterfacePurposeVLAN {
interfaces[i].IPAMAddress = fmt.Sprintf(vlanIPFormat, ip)
return nil, nil //nolint:nilnil // it is important we don't return an interface if a VLAN interface already exists
}
}

return &linodego.InstanceConfigInterfaceCreateOptions{
Purpose: linodego.InterfacePurposeVLAN,
Label: machineScope.Cluster.Name,
Expand Down
11 changes: 11 additions & 0 deletions controller/linodemachine_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2152,6 +2152,14 @@ var _ = Describe("machine in vlan", Label("machine", "vlan"), Ordered, func() {
Type: "g6-nanode-1",
Image: rutil.DefaultMachineControllerLinodeImage,
DiskEncryption: string(linodego.InstanceDiskEncryptionEnabled),
Interfaces: []infrav1alpha2.InstanceConfigInterfaceCreateOptions{
{
Purpose: linodego.InterfacePurposePublic,
},
{
Purpose: linodego.InterfacePurposeVLAN,
},
},
},
}

Expand Down Expand Up @@ -2221,6 +2229,9 @@ var _ = Describe("machine in vlan", Label("machine", "vlan"), Ordered, func() {
After(getAddrs).
Return([]linodego.InstanceConfig{{
Interfaces: []linodego.InstanceConfigInterface{
{
Purpose: linodego.InterfacePurposePublic,
},
{
Purpose: linodego.InterfacePurposeVLAN,
IPAMAddress: "10.0.0.2/11",
Expand Down
Loading