@@ -29,6 +29,7 @@ import (
29
29
"github.com/linode/linodego"
30
30
corev1 "k8s.io/api/core/v1"
31
31
apierrors "k8s.io/apimachinery/pkg/api/errors"
32
+ metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
32
33
utilerrors "k8s.io/apimachinery/pkg/util/errors"
33
34
"k8s.io/client-go/tools/record"
34
35
clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1"
@@ -59,6 +60,8 @@ const (
59
60
defaultDiskFilesystem = string (linodego .FilesystemExt4 )
60
61
61
62
// conditions for preflight instance creation
63
+ ConditionPreflightBootstrapDataSecretReady clusterv1.ConditionType = "PreflightBootstrapDataSecretReady"
64
+ ConditionPreflightLinodeFirewallReady clusterv1.ConditionType = "PreflightLinodeFirewallReady"
62
65
ConditionPreflightMetadataSupportConfigured clusterv1.ConditionType = "PreflightMetadataSupportConfigured"
63
66
ConditionPreflightCreated clusterv1.ConditionType = "PreflightCreated"
64
67
ConditionPreflightRootDiskResizing clusterv1.ConditionType = "PreflightRootDiskResizing"
@@ -212,10 +215,12 @@ func (r *LinodeMachineReconciler) reconcile(ctx context.Context, logger logr.Log
212
215
}
213
216
214
217
// Make sure bootstrap data is available and populated.
215
- if machineScope .Machine .Spec .Bootstrap .DataSecretName == nil {
218
+ if ! reconciler . ConditionTrue ( machineScope . LinodeMachine , ConditionPreflightBootstrapDataSecretReady ) && machineScope .Machine .Spec .Bootstrap .DataSecretName == nil {
216
219
logger .Info ("Bootstrap data secret is not yet available" )
217
- conditions .MarkFalse (machineScope .LinodeMachine , ConditionPreflightMetadataSupportConfigured , WaitingForBootstrapDataReason , clusterv1 .ConditionSeverityInfo , "" )
220
+ conditions .MarkFalse (machineScope .LinodeMachine , ConditionPreflightBootstrapDataSecretReady , WaitingForBootstrapDataReason , clusterv1 .ConditionSeverityInfo , "" )
218
221
return ctrl.Result {}, nil
222
+ } else {
223
+ conditions .MarkTrue (machineScope .LinodeMachine , ConditionPreflightBootstrapDataSecretReady )
219
224
}
220
225
221
226
// Update
@@ -229,7 +234,7 @@ func (r *LinodeMachineReconciler) reconcile(ctx context.Context, logger logr.Log
229
234
return r .reconcileCreate (ctx , logger , machineScope )
230
235
}
231
236
232
- //nolint:cyclop // can't make it simpler with existing API
237
+ //nolint:cyclop,gocognit // can't make it simpler with existing API
233
238
func (r * LinodeMachineReconciler ) reconcileCreate (
234
239
ctx context.Context ,
235
240
logger logr.Logger ,
@@ -242,6 +247,16 @@ func (r *LinodeMachineReconciler) reconcileCreate(
242
247
return ctrl.Result {}, err
243
248
}
244
249
250
+ if machineScope .LinodeMachine .Spec .FirewallRef != nil {
251
+ if ! reconciler .ConditionTrue (machineScope .LinodeMachine , ConditionPreflightLinodeFirewallReady ) && machineScope .LinodeMachine .Spec .ProviderID == nil {
252
+ res , err := r .reconcilePreflightLinodeFirewallCheck (ctx , logger , machineScope )
253
+ if err != nil || ! res .IsZero () {
254
+ conditions .MarkFalse (machineScope .LinodeMachine , ConditionPreflightLinodeFirewallReady , string ("linode firewall not yet available" ), clusterv1 .ConditionSeverityError , "" )
255
+ return res , err
256
+ }
257
+ }
258
+ }
259
+
245
260
if ! reconciler .ConditionTrue (machineScope .LinodeMachine , ConditionPreflightMetadataSupportConfigured ) && machineScope .LinodeMachine .Spec .ProviderID == nil {
246
261
res , err := r .reconcilePreflightMetadataSupportConfigure (ctx , logger , machineScope )
247
262
if err != nil || ! res .IsZero () {
@@ -287,6 +302,34 @@ func (r *LinodeMachineReconciler) reconcileCreate(
287
302
return ctrl.Result {}, nil
288
303
}
289
304
305
+ func (r * LinodeMachineReconciler ) reconcilePreflightLinodeFirewallCheck (ctx context.Context , logger logr.Logger , machineScope * scope.MachineScope ) (ctrl.Result , error ) {
306
+ name := machineScope .LinodeMachine .Spec .FirewallRef .Name
307
+ namespace := machineScope .LinodeMachine .Spec .FirewallRef .Namespace
308
+ if namespace == "" {
309
+ namespace = machineScope .LinodeMachine .Namespace
310
+ }
311
+ linodeFirewall := infrav1alpha2.LinodeFirewall {
312
+ ObjectMeta : metav1.ObjectMeta {
313
+ Namespace : namespace ,
314
+ Name : name ,
315
+ },
316
+ }
317
+ if err := machineScope .Client .Get (ctx , client .ObjectKeyFromObject (& linodeFirewall ), & linodeFirewall ); err != nil {
318
+ logger .Error (err , "Failed to find linode Firewall" )
319
+ if reconciler .RecordDecayingCondition (machineScope .LinodeMachine ,
320
+ ConditionPreflightLinodeFirewallReady , string (cerrs .CreateMachineError ), err .Error (),
321
+ reconciler .DefaultTimeout (r .ReconcileTimeout , reconciler .DefaultMachineControllerWaitForPreflightTimeout )) {
322
+ return ctrl.Result {}, err
323
+ }
324
+ return ctrl.Result {RequeueAfter : reconciler .DefaultMachineControllerRetryDelay }, nil
325
+ } else if ! linodeFirewall .Status .Ready {
326
+ logger .Info ("Linode firewall not yet ready" )
327
+ return ctrl.Result {RequeueAfter : reconciler .DefaultMachineControllerRetryDelay }, nil
328
+ }
329
+ conditions .MarkTrue (machineScope .LinodeMachine , ConditionPreflightLinodeFirewallReady )
330
+ return ctrl.Result {}, nil
331
+ }
332
+
290
333
func (r * LinodeMachineReconciler ) reconcilePreflightMetadataSupportConfigure (ctx context.Context , logger logr.Logger , machineScope * scope.MachineScope ) (ctrl.Result , error ) {
291
334
region , err := machineScope .LinodeClient .GetRegion (ctx , machineScope .LinodeMachine .Spec .Region )
292
335
if err != nil {
0 commit comments