Skip to content

Commit f6ed3ee

Browse files
committed
update firewall listing for new linode interfaces
1 parent 3f9319b commit f6ed3ee

File tree

4 files changed

+84
-5
lines changed

4 files changed

+84
-5
lines changed

clients/clients.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,7 @@ type LinodeFirewallClient interface {
129129
// LinodeInterfacesClient defines the methods that interact with Linode's Interfaces service.
130130
type LinodeInterfacesClient interface {
131131
ListInterfaces(ctx context.Context, linodeID int, opts *linodego.ListOptions) ([]linodego.LinodeInterface, error)
132+
ListInterfaceFirewalls(ctx context.Context, linodeID int, interfaceID int, opts *linodego.ListOptions) ([]linodego.Firewall, error)
132133
}
133134

134135
type K8sClient interface {

internal/controller/linodemachine_controller.go

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -785,11 +785,32 @@ func (r *LinodeMachineReconciler) reconcileUpdate(ctx context.Context, logger lo
785785
}
786786

787787
func (r *LinodeMachineReconciler) reconcileFirewallID(ctx context.Context, logger logr.Logger, machineScope *scope.MachineScope, instanceID int) (ctrl.Result, error) {
788-
// get the instance's firewalls
789-
firewalls, err := machineScope.LinodeClient.ListInstanceFirewalls(ctx, instanceID, nil)
790-
if err != nil {
791-
logger.Error(err, "Failed to list firewalls for Linode instance")
792-
return ctrl.Result{RequeueAfter: reconciler.DefaultMachineControllerWaitForRunningDelay}, nil
788+
var (
789+
firewalls []linodego.Firewall
790+
err error
791+
)
792+
// Get the instance's firewalls normally if this is not using the new linode interfaces,
793+
// otherwise we have to get firewalls per linode interface
794+
if machineScope.LinodeMachine.Spec.InterfaceGeneration == linodego.GenerationLegacyConfig {
795+
firewalls, err = machineScope.LinodeClient.ListInstanceFirewalls(ctx, instanceID, nil)
796+
if err != nil {
797+
logger.Error(err, "Failed to list firewalls for Linode instance")
798+
return ctrl.Result{RequeueAfter: reconciler.DefaultMachineControllerWaitForRunningDelay}, nil
799+
}
800+
} else {
801+
interfaces, err := machineScope.LinodeClient.ListInterfaces(ctx, instanceID, nil)
802+
if err != nil {
803+
logger.Error(err, "Failed to list interfaces for Linode instance")
804+
return ctrl.Result{RequeueAfter: reconciler.DefaultMachineControllerWaitForRunningDelay}, nil
805+
}
806+
for _, iface := range interfaces {
807+
ifaceFWs, err := machineScope.LinodeClient.ListInterfaceFirewalls(ctx, instanceID, iface.ID, nil)
808+
if err != nil {
809+
logger.Error(err, "Failed to list firewalls for Linode instance interface", "interfaceID", iface.ID)
810+
return ctrl.Result{RequeueAfter: reconciler.DefaultMachineControllerWaitForRunningDelay}, nil
811+
}
812+
firewalls = append(firewalls, ifaceFWs...)
813+
}
793814
}
794815

795816
attachedFWIDs := make([]int, 0, len(firewalls))

mock/client.go

Lines changed: 30 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

observability/wrappers/linodeclient/linodeclient.gen.go

Lines changed: 27 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)