Skip to content

Commit 4ccb684

Browse files
committed
Add preflight check for firewall if firewall ID is provided for LinodeCluster and LinodeMachine
1 parent abca5fb commit 4ccb684

File tree

2 files changed

+44
-0
lines changed

2 files changed

+44
-0
lines changed

internal/controller/linodecluster_controller.go

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,28 @@ func (r *LinodeClusterReconciler) performPreflightChecks(ctx context.Context, lo
245245
}
246246

247247
func (r *LinodeClusterReconciler) reconcilePreflightLinodeFirewallCheck(ctx context.Context, logger logr.Logger, clusterScope *scope.ClusterScope) (ctrl.Result, error) {
248+
// If NodeBalancerFirewallID is directly specified, check if it exists
249+
if clusterScope.LinodeCluster.Spec.Network.NodeBalancerFirewallID != nil {
250+
firewallID := *clusterScope.LinodeCluster.Spec.Network.NodeBalancerFirewallID
251+
_, err := clusterScope.LinodeClient.GetFirewall(ctx, firewallID)
252+
if err != nil {
253+
logger.Error(err, "Failed to get NodeBalancer firewall with provided ID", "firewallID", firewallID)
254+
conditions.Set(clusterScope.LinodeCluster, metav1.Condition{
255+
Type: ConditionPreflightLinodeNBFirewallReady,
256+
Status: metav1.ConditionFalse,
257+
Reason: util.CreateError,
258+
Message: err.Error(),
259+
})
260+
return ctrl.Result{RequeueAfter: reconciler.DefaultClusterControllerReconcileDelay}, nil
261+
}
262+
conditions.Set(clusterScope.LinodeCluster, metav1.Condition{
263+
Type: ConditionPreflightLinodeNBFirewallReady,
264+
Status: metav1.ConditionTrue,
265+
Reason: "LinodeFirewallReady", // We have to set the reason to not fail object patching
266+
})
267+
return ctrl.Result{}, nil
268+
}
269+
248270
name := clusterScope.LinodeCluster.Spec.NodeBalancerFirewallRef.Name
249271
namespace := clusterScope.LinodeCluster.Spec.NodeBalancerFirewallRef.Namespace
250272
if namespace == "" {

internal/controller/linodemachine_controller.go

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -442,6 +442,28 @@ func (r *LinodeMachineReconciler) reconcilePreflightVPC(ctx context.Context, log
442442
}
443443

444444
func (r *LinodeMachineReconciler) reconcilePreflightLinodeFirewallCheck(ctx context.Context, logger logr.Logger, machineScope *scope.MachineScope) (ctrl.Result, error) {
445+
// If NodeBalancerFirewallID is directly specified, check if it exists
446+
if machineScope.LinodeCluster.Spec.Network.NodeBalancerFirewallID != nil {
447+
firewallID := *machineScope.LinodeCluster.Spec.Network.NodeBalancerFirewallID
448+
_, err := machineScope.LinodeClient.GetFirewall(ctx, firewallID)
449+
if err != nil {
450+
logger.Error(err, "Failed to get NodeBalancer firewall with provided ID", "firewallID", firewallID)
451+
conditions.Set(machineScope.LinodeMachine, metav1.Condition{
452+
Type: ConditionPreflightLinodeFirewallReady,
453+
Status: metav1.ConditionFalse,
454+
Reason: util.CreateError,
455+
Message: err.Error(),
456+
})
457+
return ctrl.Result{RequeueAfter: reconciler.DefaultClusterControllerReconcileDelay}, nil
458+
}
459+
conditions.Set(machineScope.LinodeMachine, metav1.Condition{
460+
Type: ConditionPreflightLinodeFirewallReady,
461+
Status: metav1.ConditionTrue,
462+
Reason: "LinodeFirewallReady", // We have to set the reason to not fail object patching
463+
})
464+
return ctrl.Result{}, nil
465+
}
466+
445467
name := machineScope.LinodeMachine.Spec.FirewallRef.Name
446468
namespace := machineScope.LinodeMachine.Spec.FirewallRef.Namespace
447469
if namespace == "" {

0 commit comments

Comments
 (0)