Skip to content

Commit

Permalink
wait until after delete step to check that linodeCluster still exists…
Browse files Browse the repository at this point in the history
…. tag resources by cluster label instead of UUID
  • Loading branch information
eljohnson92 committed Feb 8, 2024
1 parent 660e466 commit 10f0008
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 15 deletions.
6 changes: 6 additions & 0 deletions cloud/services/loadbalancers.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion controller/linodecluster_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
29 changes: 15 additions & 14 deletions controller/linodemachine_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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 ctrl.Result{}, err
}

var linodeInstance *linodego.Instance
defer func() {
machineScope.LinodeMachine.Status.InstanceState = util.Pointer(linodego.InstanceOffline)
Expand Down Expand Up @@ -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")

Expand Down

0 comments on commit 10f0008

Please sign in to comment.