Skip to content

Commit abca5fb

Browse files
committed
Address the comments
1 parent b587ca5 commit abca5fb

File tree

3 files changed

+51
-31
lines changed

3 files changed

+51
-31
lines changed

internal/controller/linodecluster_controller.go

Lines changed: 47 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -229,34 +229,15 @@ func (r *LinodeClusterReconciler) performPreflightChecks(ctx context.Context, lo
229229
// The condition is already set in reconcilePreflightLinodeVPCCheck, so we don't need to set it again
230230
return res, err
231231
}
232-
233-
// Only set to true if there was no error
234-
conditions.Set(clusterScope.LinodeCluster, metav1.Condition{
235-
Type: ConditionPreflightLinodeVPCReady,
236-
Status: metav1.ConditionTrue,
237-
Reason: "LinodeVPCReady", // We have to set the reason to not fail object patching
238-
})
239232
}
240233
}
241234

242235
if clusterScope.LinodeCluster.Spec.NodeBalancerFirewallRef != nil {
243236
if !reconciler.ConditionTrue(clusterScope.LinodeCluster, ConditionPreflightLinodeNBFirewallReady) {
244237
res, err := r.reconcilePreflightLinodeFirewallCheck(ctx, logger, clusterScope)
245238
if err != nil || !res.IsZero() {
246-
conditions.Set(clusterScope.LinodeCluster, metav1.Condition{
247-
Type: ConditionPreflightLinodeNBFirewallReady,
248-
Status: metav1.ConditionFalse,
249-
Reason: "LinodeFirewallNotYetAvailable", // We have to set the reason to not fail object patching
250-
})
251239
return res, err
252240
}
253-
254-
// Only set to true if there was no error
255-
conditions.Set(clusterScope.LinodeCluster, metav1.Condition{
256-
Type: ConditionPreflightLinodeNBFirewallReady,
257-
Status: metav1.ConditionTrue,
258-
Reason: "LinodeFirewallReady", // We have to set the reason to not fail object patching
259-
})
260241
}
261242
}
262243

@@ -289,17 +270,37 @@ func (r *LinodeClusterReconciler) reconcilePreflightLinodeFirewallCheck(ctx cont
289270
Reason: util.CreateError,
290271
Message: err.Error(),
291272
})
273+
292274
return ctrl.Result{}, err
293275
}
276+
conditions.Set(clusterScope.LinodeCluster, metav1.Condition{
277+
Type: ConditionPreflightLinodeNBFirewallReady,
278+
Status: metav1.ConditionFalse,
279+
Reason: "LinodeFirewallNotYetAvailable", // We have to set the reason to not fail object patching
280+
})
281+
294282
return ctrl.Result{RequeueAfter: reconciler.DefaultClusterControllerReconcileDelay}, nil
295283
}
296284
if linodeFirewall.Spec.FirewallID == nil {
297285
logger.Info("Linode firewall not yet available")
286+
conditions.Set(clusterScope.LinodeCluster, metav1.Condition{
287+
Type: ConditionPreflightLinodeNBFirewallReady,
288+
Status: metav1.ConditionFalse,
289+
Reason: "LinodeFirewallNotYetAvailable", // We have to set the reason to not fail object patching
290+
})
291+
298292
return ctrl.Result{RequeueAfter: reconciler.DefaultClusterControllerReconcileDelay}, nil
299293
}
300294

301295
r.Recorder.Event(clusterScope.LinodeCluster, corev1.EventTypeNormal, string(clusterv1.ReadyCondition), "Linode firewall is now available")
302296

297+
// Only set to true if there was no error
298+
conditions.Set(clusterScope.LinodeCluster, metav1.Condition{
299+
Type: ConditionPreflightLinodeNBFirewallReady,
300+
Status: metav1.ConditionTrue,
301+
Reason: "LinodeFirewallReady", // We have to set the reason to not fail object patching
302+
})
303+
303304
return ctrl.Result{}, nil
304305
}
305306

@@ -316,7 +317,7 @@ func (r *LinodeClusterReconciler) reconcilePreflightLinodeVPCCheck(ctx context.C
316317
Reason: util.CreateError,
317318
Message: fmt.Sprintf("VPC with ID %d not found: %v", vpcID, err),
318319
})
319-
return ctrl.Result{RequeueAfter: reconciler.DefaultClusterControllerReconcileDelay}, err
320+
return ctrl.Result{RequeueAfter: reconciler.DefaultClusterControllerReconcileDelay}, nil
320321
}
321322
// VPC exists, verify it has at least one subnet
322323
if len(vpc.Subnets) == 0 {
@@ -328,9 +329,17 @@ func (r *LinodeClusterReconciler) reconcilePreflightLinodeVPCCheck(ctx context.C
328329
Reason: util.CreateError,
329330
Message: err.Error(),
330331
})
331-
return ctrl.Result{RequeueAfter: reconciler.DefaultClusterControllerReconcileDelay}, err
332+
return ctrl.Result{RequeueAfter: reconciler.DefaultClusterControllerReconcileDelay}, nil
332333
}
333334
r.Recorder.Event(clusterScope.LinodeCluster, corev1.EventTypeNormal, string(clusterv1.ReadyCondition), fmt.Sprintf("VPC with ID %d is available", vpcID))
335+
336+
// Only set to true if there was no error
337+
conditions.Set(clusterScope.LinodeCluster, metav1.Condition{
338+
Type: ConditionPreflightLinodeVPCReady,
339+
Status: metav1.ConditionTrue,
340+
Reason: "LinodeVPCReady", // We have to set the reason to not fail object patching
341+
})
342+
334343
return ctrl.Result{}, nil
335344
}
336345

@@ -359,12 +368,29 @@ func (r *LinodeClusterReconciler) reconcilePreflightLinodeVPCCheck(ctx context.C
359368
})
360369
return ctrl.Result{}, err
361370
}
371+
conditions.Set(clusterScope.LinodeCluster, metav1.Condition{
372+
Type: ConditionPreflightLinodeVPCReady,
373+
Status: metav1.ConditionFalse,
374+
Reason: "LinodeVPCNotYetAvailable", // We have to set the reason to not fail object patching
375+
})
362376
return ctrl.Result{RequeueAfter: reconciler.DefaultClusterControllerReconcileDelay}, nil
363377
} else if !linodeVPC.Status.Ready {
364378
logger.Info("LinodeVPC is not yet available")
379+
conditions.Set(clusterScope.LinodeCluster, metav1.Condition{
380+
Type: ConditionPreflightLinodeVPCReady,
381+
Status: metav1.ConditionFalse,
382+
Reason: "LinodeVPCNotYetAvailable", // We have to set the reason to not fail object patching
383+
})
365384
return ctrl.Result{RequeueAfter: reconciler.DefaultClusterControllerReconcileDelay}, nil
366385
}
367386
r.Recorder.Event(clusterScope.LinodeCluster, corev1.EventTypeNormal, string(clusterv1.ReadyCondition), "LinodeVPC is now available")
387+
388+
// Only set to true if there was no error
389+
conditions.Set(clusterScope.LinodeCluster, metav1.Condition{
390+
Type: ConditionPreflightLinodeVPCReady,
391+
Status: metav1.ConditionTrue,
392+
Reason: "LinodeVPCReady", // We have to set the reason to not fail object patching
393+
})
368394
return ctrl.Result{}, nil
369395
}
370396

internal/controller/linodemachine_controller.go

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -383,16 +383,13 @@ func (r *LinodeMachineReconciler) validateVPC(ctx context.Context, vpcID int, ma
383383
}
384384

385385
func (r *LinodeMachineReconciler) reconcilePreflightVPC(ctx context.Context, logger logr.Logger, machineScope *scope.MachineScope, vpcRef *corev1.ObjectReference) (ctrl.Result, error) {
386-
// Check if machine has direct VPCID
386+
// LinodeMachine VPCID takes precedence over LinodeCluster VPCID
387387
if machineScope.LinodeMachine.Spec.VPCID != nil {
388388
if err := r.validateVPC(ctx, *machineScope.LinodeMachine.Spec.VPCID, machineScope, logger, "Machine"); err != nil {
389389
return ctrl.Result{}, err
390390
}
391391
return ctrl.Result{}, nil
392-
}
393-
394-
// Check if cluster has direct VPCID
395-
if machineScope.LinodeCluster.Spec.VPCID != nil {
392+
} else if machineScope.LinodeCluster.Spec.VPCID != nil {
396393
if err := r.validateVPC(ctx, *machineScope.LinodeCluster.Spec.VPCID, machineScope, logger, "Cluster"); err != nil {
397394
return ctrl.Result{}, err
398395
}

internal/controller/linodemachine_controller_helpers.go

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -152,13 +152,10 @@ func newCreateConfig(ctx context.Context, machineScope *scope.MachineScope, gzip
152152

153153
// configureVPCInterface handles all VPC configuration scenarios and adds the appropriate interface
154154
func configureVPCInterface(ctx context.Context, machineScope *scope.MachineScope, createConfig *linodego.InstanceCreateOptions, logger logr.Logger) error {
155-
// First check if a direct VPCID is specified on the machine
155+
// First check if a direct VPCID is specified on the machine then the cluster
156156
if machineScope.LinodeMachine.Spec.VPCID != nil {
157157
return addVPCInterfaceFromDirectID(ctx, machineScope, createConfig, logger, *machineScope.LinodeMachine.Spec.VPCID)
158-
}
159-
160-
// Next check if a direct VPCID is specified on the cluster
161-
if machineScope.LinodeCluster.Spec.VPCID != nil {
158+
} else if machineScope.LinodeCluster.Spec.VPCID != nil {
162159
return addVPCInterfaceFromDirectID(ctx, machineScope, createConfig, logger, *machineScope.LinodeCluster.Spec.VPCID)
163160
}
164161

0 commit comments

Comments
 (0)