Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

wait until after delete step to check that linodeCluster still exists #95

Merged
merged 1 commit into from
Feb 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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