From d542401841fd32992deaecf0ccee4407ff98ff2f Mon Sep 17 00:00:00 2001 From: Evan Johnson Date: Thu, 8 Feb 2024 12:52:41 -0500 Subject: [PATCH] wait until after delete step to check that linodeCluster still exists. tag resources by cluster label instead of UUID --- cloud/services/loadbalancers.go | 6 ++++++ controller/linodecluster_controller.go | 2 +- controller/linodemachine_controller.go | 29 +++++++++++++------------- 3 files changed, 22 insertions(+), 15 deletions(-) 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..87ecdf504 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) @@ -298,9 +299,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")