diff --git a/cloud/services/loadbalancers.go b/cloud/services/loadbalancers.go index 98d161c9d..4a5cdb012 100644 --- a/cloud/services/loadbalancers.go +++ b/cloud/services/loadbalancers.go @@ -177,6 +177,12 @@ func DeleteNodeFromNB( return errors.New("no InstanceID") } + if machineScope.LinodeCluster.Spec.ControlPlaneEndpoint.Host == "" { + logger.Info("NodeBalancer already deleted, no NodeBalancer backend Node to remove") + + return nil + } + err := machineScope.LinodeClient.DeleteNodeBalancerNode( ctx, machineScope.LinodeCluster.Spec.Network.NodeBalancerID, diff --git a/controller/linodecluster_controller.go b/controller/linodecluster_controller.go index eebfb2d36..897a4829d 100644 --- a/controller/linodecluster_controller.go +++ b/controller/linodecluster_controller.go @@ -84,7 +84,7 @@ func (r *LinodeClusterReconciler) Reconcile(ctx context.Context, req ctrl.Reques return ctrl.Result{}, client.IgnoreNotFound(err) } else if cluster == nil { - logger.Info("Machine Controller has not yet set OwnerRef, skipping reconciliation") + logger.Info("Cluster Controller has not yet set OwnerRef, skipping reconciliation") return ctrl.Result{}, nil } diff --git a/controller/linodemachine_controller.go b/controller/linodemachine_controller.go index a3a4003b2..15a787595 100644 --- a/controller/linodemachine_controller.go +++ b/controller/linodemachine_controller.go @@ -163,18 +163,6 @@ func (r *LinodeMachineReconciler) Reconcile(ctx context.Context, req ctrl.Reques } linodeCluster := &infrav1alpha1.LinodeCluster{} - linodeClusterKey := client.ObjectKey{ - Namespace: linodeMachine.Namespace, - Name: cluster.Spec.InfrastructureRef.Name, - } - - if err = r.Client.Get(ctx, linodeClusterKey, linodeCluster); err != nil { - if err = client.IgnoreNotFound(err); err != nil { - log.Error(err, "Failed to fetch Linode cluster") - } - - return ctrl.Result{}, err - } machineScope, err := scope.NewMachineScope( r.LinodeApiKey, @@ -258,6 +246,19 @@ func (r *LinodeMachineReconciler) reconcile( return } + linodeClusterKey := client.ObjectKey{ + Namespace: machineScope.LinodeMachine.Namespace, + Name: machineScope.Cluster.Spec.InfrastructureRef.Name, + } + + if err = r.Client.Get(ctx, linodeClusterKey, machineScope.LinodeCluster); err != nil { + if err = client.IgnoreNotFound(err); err != nil { + logger.Error(err, "Failed to fetch Linode cluster") + } + + return + } + var linodeInstance *linodego.Instance defer func() { machineScope.LinodeMachine.Status.InstanceState = util.Pointer(linodego.InstanceOffline) @@ -282,8 +283,9 @@ func (r *LinodeMachineReconciler) reconcile( // Make sure bootstrap data is available and populated. if machineScope.Machine.Spec.Bootstrap.DataSecretName == nil { logger.Info("Bootstrap data secret is not yet available") + res = ctrl.Result{RequeueAfter: reconciler.DefaultMachineControllerWaitForBootstrapDelay} - return ctrl.Result{RequeueAfter: reconciler.DefaultMachineControllerWaitForBootstrapDelay}, nil + return } linodeInstance, err = r.reconcileCreate(ctx, logger, machineScope, clusterScope) @@ -298,9 +300,9 @@ func (r *LinodeMachineReconciler) reconcileCreate( ) (*linodego.Instance, error) { logger.Info("creating machine") - tags := []string{string(machineScope.LinodeCluster.UID), string(machineScope.LinodeMachine.UID)} + tags := []string{machineScope.LinodeCluster.Name} - linodeInstances, err := machineScope.LinodeClient.ListInstances(ctx, linodego.NewListOptions(1, util.CreateLinodeAPIFilter("", tags))) + linodeInstances, err := machineScope.LinodeClient.ListInstances(ctx, linodego.NewListOptions(1, util.CreateLinodeAPIFilter(machineScope.LinodeMachine.Name, tags))) if err != nil { logger.Error(err, "Failed to list Linode machine instances")