Skip to content

Commit 6f47ec7

Browse files
committed
allow skipping of setting interfaces and linodeInterfaces via InterfaceGeneration on LinodeMachines, only update instanceConfig if configuring kernel or network helpers
1 parent 24abc79 commit 6f47ec7

File tree

8 files changed

+60
-145
lines changed

8 files changed

+60
-145
lines changed

api/v1alpha2/linodemachine_types.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,13 @@ type LinodeMachineSpec struct {
128128
// For more information, see https://techdocs.akamai.com/cloud-computing/docs/automatically-configure-networking
129129
// Defaults to true.
130130
NetworkHelper *bool `json:"networkHelper,omitempty"`
131+
132+
// InterfaceGeneration is the generation of the interface to use for the cluster's
133+
// nodes in interface / linodeInterface are not specified for a LinodeMachine.
134+
// If not set, defaults to "legacy_config".
135+
// +kubebuilder:validation:Enum=legacy_config;linode
136+
// +kubebuilder:default=legacy_config
137+
InterfaceGeneration linodego.InterfaceGeneration `json:"interfaceGeneration,omitempty"`
131138
}
132139

133140
// IPv6CreateOptions defines the IPv6 options for the instance.

config/crd/bases/infrastructure.cluster.x-k8s.io_linodemachines.yaml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,16 @@ spec:
228228
instanceID:
229229
description: InstanceID is the Linode instance ID for this machine.
230230
type: integer
231+
interfaceGeneration:
232+
default: legacy_config
233+
description: |-
234+
InterfaceGeneration is the generation of the interface to use for the cluster's
235+
nodes in interface / linodeInterface are not specified for a LinodeMachine.
236+
If not set, defaults to "legacy_config".
237+
enum:
238+
- legacy_config
239+
- linode
240+
type: string
231241
interfaces:
232242
items:
233243
description: InstanceConfigInterfaceCreateOptions defines network

config/crd/bases/infrastructure.cluster.x-k8s.io_linodemachinetemplates.yaml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,16 @@ spec:
219219
description: InstanceID is the Linode instance ID for this
220220
machine.
221221
type: integer
222+
interfaceGeneration:
223+
default: legacy_config
224+
description: |-
225+
InterfaceGeneration is the generation of the interface to use for the cluster's
226+
nodes in interface / linodeInterface are not specified for a LinodeMachine.
227+
If not set, defaults to "legacy_config".
228+
enum:
229+
- legacy_config
230+
- linode
231+
type: string
222232
interfaces:
223233
items:
224234
description: InstanceConfigInterfaceCreateOptions defines

docs/src/reference/out.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -679,6 +679,7 @@ _Appears in:_
679679
| `vpcID` _integer_ | VPCID is the ID of an existing VPC in Linode. This allows using a VPC that is not managed by CAPL. | | |
680680
| `ipv6Options` _[IPv6CreateOptions](#ipv6createoptions)_ | IPv6Options defines the IPv6 options for the instance.<br />If not specified, IPv6 ranges won't be allocated to instance. | | |
681681
| `networkHelper` _boolean_ | NetworkHelper is an option usually enabled on account level. It helps configure networking automatically for instances.<br />You can use this to enable/disable the network helper for a specific instance.<br />For more information, see https://techdocs.akamai.com/cloud-computing/docs/automatically-configure-networking<br />Defaults to true. | | |
682+
| `interfaceGeneration` _[InterfaceGeneration](#interfacegeneration)_ | InterfaceGeneration is the generation of the interface to use for the cluster's<br />nodes in interface / linodeInterface are not specified for a LinodeMachine.<br />If not set, defaults to "legacy_config". | legacy_config | Enum: [legacy_config linode] <br /> |
682683

683684

684685
#### LinodeMachineStatus

internal/controller/linodemachine_controller.go

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -274,7 +274,7 @@ func (r *LinodeMachineReconciler) reconcileCreate(
274274
}
275275

276276
if machineScope.LinodeMachine.Spec.FirewallRef != nil {
277-
if !reconciler.ConditionTrue(machineScope.LinodeMachine, string(ConditionPreflightLinodeFirewallReady)) && machineScope.LinodeMachine.Spec.ProviderID == nil {
277+
if !reconciler.ConditionTrue(machineScope.LinodeMachine, ConditionPreflightLinodeFirewallReady) && machineScope.LinodeMachine.Spec.ProviderID == nil {
278278
res, err := r.reconcilePreflightLinodeFirewallCheck(ctx, logger, machineScope)
279279
if err != nil || !res.IsZero() {
280280
conditions.Set(machineScope.LinodeMachine, metav1.Condition{
@@ -553,6 +553,10 @@ func (r *LinodeMachineReconciler) reconcilePreflightMetadataSupportConfigure(ctx
553553
}
554554

555555
func (r *LinodeMachineReconciler) reconcilePreflightCreate(ctx context.Context, logger logr.Logger, machineScope *scope.MachineScope) (ctrl.Result, error) {
556+
// default to legacy interface generation if not set for now
557+
if machineScope.LinodeMachine.Spec.InterfaceGeneration == "" {
558+
machineScope.LinodeMachine.Spec.InterfaceGeneration = linodego.GenerationLegacyConfig
559+
}
556560
// get the bootstrap data for the Linode instance and set it for create config
557561
createOpts, err := newCreateConfig(ctx, machineScope, r.GzipCompressionEnabled, logger)
558562
if err != nil {
@@ -619,7 +623,7 @@ func (r *LinodeMachineReconciler) reconcilePreflightConfigure(ctx context.Contex
619623
return ctrl.Result{RequeueAfter: reconciler.DefaultMachineControllerWaitForRunningDelay}, nil
620624
}
621625

622-
configData := &linodego.InstanceConfigUpdateOptions{}
626+
configData := linodego.InstanceConfigUpdateOptions{}
623627
if machineScope.LinodeMachine.Spec.Configuration != nil && machineScope.LinodeMachine.Spec.Configuration.Kernel != "" {
624628
configData.Kernel = machineScope.LinodeMachine.Spec.Configuration.Kernel
625629
}
@@ -632,14 +636,14 @@ func (r *LinodeMachineReconciler) reconcilePreflightConfigure(ctx context.Contex
632636
}
633637

634638
// only update the instance configuration if there are changes
635-
if configData != nil {
639+
if configData.Kernel != "" || configData.Helpers != nil {
636640
instanceConfig, err := getDefaultInstanceConfig(ctx, machineScope, instanceID)
637641
if err != nil {
638642
logger.Error(err, "Failed to get default instance configuration")
639643
return retryIfTransient(err, logger)
640644
}
641-
if _, err := machineScope.LinodeClient.UpdateInstanceConfig(ctx, instanceID, instanceConfig.ID, *configData); err != nil {
642-
logger.Error(err, "Failed to update default instance configuration", "configuration", *configData)
645+
if _, err := machineScope.LinodeClient.UpdateInstanceConfig(ctx, instanceID, instanceConfig.ID, configData); err != nil {
646+
logger.Error(err, "Failed to update default instance configuration", "configuration", configData)
643647
return retryIfTransient(err, logger)
644648
}
645649
}

internal/controller/linodemachine_controller_helpers.go

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ func fillCreateConfig(createConfig *linodego.InstanceCreateOptions, machineScope
8484
if machineScope.LinodeMachine.Spec.PrivateIP != nil {
8585
createConfig.PrivateIP = *machineScope.LinodeMachine.Spec.PrivateIP
8686
} else {
87-
if machineScope.LinodeMachine.Spec.LinodeInterfaces == nil {
87+
if machineScope.LinodeMachine.Spec.LinodeInterfaces == nil && machineScope.LinodeMachine.Spec.InterfaceGeneration == linodego.GenerationLegacyConfig {
8888
// Supported only for legacy network interfaces.
8989
createConfig.PrivateIP = true
9090
} else {
@@ -177,7 +177,7 @@ func configureVPCInterface(ctx context.Context, machineScope *scope.MachineScope
177177
// addVPCInterfaceFromDirectID handles adding a VPC interface from a direct ID
178178
func addVPCInterfaceFromDirectID(ctx context.Context, machineScope *scope.MachineScope, createConfig *linodego.InstanceCreateOptions, logger logr.Logger, vpcID int) error {
179179
switch {
180-
case createConfig.LinodeInterfaces != nil:
180+
case createConfig.LinodeInterfaces != nil || (createConfig.LinodeInterfaces == nil && machineScope.LinodeMachine.Spec.InterfaceGeneration == linodego.GenerationLinode):
181181
iface, err := getVPCLinodeInterfaceConfigFromDirectID(ctx, machineScope, createConfig.LinodeInterfaces, logger, vpcID)
182182
if err != nil {
183183
logger.Error(err, "Failed to get VPC linode interface config from direct ID")
@@ -207,7 +207,7 @@ func addVPCInterfaceFromDirectID(ctx context.Context, machineScope *scope.Machin
207207
// addVPCInterfaceFromReference handles adding a VPC interface from a reference
208208
func addVPCInterfaceFromReference(ctx context.Context, machineScope *scope.MachineScope, createConfig *linodego.InstanceCreateOptions, logger logr.Logger, vpcRef *corev1.ObjectReference) error {
209209
switch {
210-
case createConfig.LinodeInterfaces != nil:
210+
case createConfig.LinodeInterfaces != nil || (createConfig.LinodeInterfaces == nil && machineScope.LinodeMachine.Spec.InterfaceGeneration == linodego.GenerationLinode):
211211
iface, err := getVPCLinodeInterfaceConfig(ctx, machineScope, createConfig.LinodeInterfaces, logger, vpcRef)
212212
if err != nil {
213213
logger.Error(err, "Failed to get VPC interface config")
@@ -296,7 +296,7 @@ func buildInstanceAddrs(ctx context.Context, machineScope *scope.MachineScope, i
296296
func handleVlanIps(ctx context.Context, machineScope *scope.MachineScope, instanceID int) ([]clusterv1.MachineAddress, error) {
297297
ips := []clusterv1.MachineAddress{}
298298
switch {
299-
case machineScope.LinodeMachine.Spec.LinodeInterfaces != nil:
299+
case machineScope.LinodeMachine.Spec.LinodeInterfaces != nil || (machineScope.LinodeMachine.Spec.LinodeInterfaces == nil && machineScope.LinodeMachine.Spec.InterfaceGeneration == linodego.GenerationLinode):
300300
ifaces, err := machineScope.LinodeClient.ListInterfaces(ctx, instanceID, &linodego.ListOptions{})
301301
if err != nil || len(ifaces) == 0 {
302302
return ips, fmt.Errorf("list interfaces: %w", err)
@@ -1060,7 +1060,7 @@ func linodeMachineSpecToInstanceCreateConfig(machineSpec infrav1alpha2.LinodeMac
10601060

10611061
if len(machineSpec.LinodeInterfaces) > 0 {
10621062
instCreateOpts.LinodeInterfaces = constructLinodeInterfaceCreateOpts(machineSpec.LinodeInterfaces)
1063-
} else {
1063+
} else if len(machineSpec.Interfaces) > 0 {
10641064
interfaces := make([]linodego.InstanceConfigInterfaceCreateOptions, len(machineSpec.Interfaces))
10651065
for idx, iface := range machineSpec.Interfaces {
10661066
interfaces[idx] = linodego.InstanceConfigInterfaceCreateOptions{
@@ -1439,7 +1439,7 @@ func getVPCRefFromScope(machineScope *scope.MachineScope) *corev1.ObjectReferenc
14391439
// configureVlanInterface adds a VLAN interface to the configuration
14401440
func configureVlanInterface(ctx context.Context, machineScope *scope.MachineScope, createConfig *linodego.InstanceCreateOptions, logger logr.Logger) error {
14411441
switch {
1442-
case createConfig.LinodeInterfaces != nil:
1442+
case createConfig.LinodeInterfaces != nil || (createConfig.LinodeInterfaces == nil && machineScope.LinodeMachine.Spec.InterfaceGeneration == linodego.GenerationLinode):
14431443
iface, err := getVlanLinodeInterfaceConfig(ctx, machineScope, createConfig.LinodeInterfaces, logger)
14441444
if err != nil {
14451445
logger.Error(err, "Failed to get VLAN interface config")
@@ -1501,10 +1501,8 @@ func configureFirewall(ctx context.Context, machineScope *scope.MachineScope, cr
15011501
createConfig.FirewallID = fwID
15021502

15031503
// If using LinodeInterfaces that needs to know about the firewall ID
1504-
if machineScope.LinodeMachine.Spec.LinodeInterfaces != nil {
1505-
for i := range createConfig.LinodeInterfaces {
1506-
createConfig.LinodeInterfaces[i].FirewallID = ptr.To(fwID)
1507-
}
1504+
for i := range createConfig.LinodeInterfaces {
1505+
createConfig.LinodeInterfaces[i].FirewallID = ptr.To(fwID)
15081506
}
15091507

15101508
return nil

0 commit comments

Comments
 (0)