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 9, 2024
1 parent 660e466 commit 7fa7b9f
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 16 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
32 changes: 17 additions & 15 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
}

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

Expand All @@ -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")

Expand Down

0 comments on commit 7fa7b9f

Please sign in to comment.