Skip to content

Commit

Permalink
actually get the NB config for the ID on delete
Browse files Browse the repository at this point in the history
  • Loading branch information
AshleyDumaine committed Feb 6, 2024
1 parent 0c20300 commit d7e1e12
Showing 1 changed file with 15 additions and 10 deletions.
25 changes: 15 additions & 10 deletions controller/linodemachine_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import (
b64 "encoding/base64"
"errors"
"fmt"
"github.com/linode/cluster-api-provider-linode/cloud/services"
"net/http"
"time"

Expand All @@ -45,7 +44,8 @@ import (
"sigs.k8s.io/controller-runtime/pkg/reconcile"
"sigs.k8s.io/controller-runtime/pkg/source"

infrav1 "github.com/linode/cluster-api-provider-linode/api/v1alpha1"
infrav1alpha1 "github.com/linode/cluster-api-provider-linode/api/v1alpha1"
"github.com/linode/cluster-api-provider-linode/cloud/services"
)

var skippedMachinePhases = map[string]bool{
Expand Down Expand Up @@ -101,7 +101,7 @@ func (r *LinodeMachineReconciler) Reconcile(ctx context.Context, req ctrl.Reques

log := ctrl.LoggerFrom(ctx).WithName("LinodeMachineReconciler").WithValues("name", req.NamespacedName.String())

linodeMachine := &infrav1.LinodeMachine{}
linodeMachine := &infrav1alpha1.LinodeMachine{}
if err := r.Client.Get(ctx, req.NamespacedName, linodeMachine); err != nil {
log.Error(err, "Failed to fetch Linode machine")

Expand Down Expand Up @@ -149,7 +149,7 @@ func (r *LinodeMachineReconciler) Reconcile(ctx context.Context, req ctrl.Reques
return ctrl.Result{}, client.IgnoreNotFound(err)
}

linodeCluster := &infrav1.LinodeCluster{}
linodeCluster := &infrav1alpha1.LinodeCluster{}
linodeClusterKey := client.ObjectKey{
Namespace: linodeMachine.Namespace,
Name: cluster.Spec.InfrastructureRef.Name,
Expand Down Expand Up @@ -471,15 +471,20 @@ func (r *LinodeMachineReconciler) reconcileDelete(
clusterScope *scope.ClusterScope,
) error {
logger.Info("deleting machine")
var err error

if machineScope.LinodeMachine.Spec.InstanceID != nil {

Check failure on line 475 in controller/linodemachine_controller.go

View workflow job for this annotation

GitHub Actions / go-analyse

`if machineScope.LinodeMachine.Spec.InstanceID != nil` has complex nested blocks (complexity: 8) (nestif)
// Update the NB to remove the node if it's a control plane node
linodeNBConfig, err := services.GetNodeBalancerConfig(ctx, clusterScope, logger)
if err != nil {
logger.Error(err, "Failed to get Node Balancer config")

return err
}
if kutil.IsControlPlaneMachine(machineScope.Machine) {
err = machineScope.LinodeClient.DeleteNodeBalancerNode(
ctx,
machineScope.LinodeCluster.Spec.Network.NodeBalancerID,
0,
linodeNBConfig.ID,
*machineScope.LinodeMachine.Spec.InstanceID,
)
if err != nil {
Expand All @@ -505,21 +510,21 @@ func (r *LinodeMachineReconciler) reconcileDelete(

machineScope.LinodeMachine.Spec.ProviderID = nil
machineScope.LinodeMachine.Spec.InstanceID = nil
controllerutil.RemoveFinalizer(machineScope.LinodeMachine, infrav1.GroupVersion.String())
controllerutil.RemoveFinalizer(machineScope.LinodeMachine, infrav1alpha1.GroupVersion.String())

return nil
}

// SetupWithManager sets up the controller with the Manager.
func (r *LinodeMachineReconciler) SetupWithManager(mgr ctrl.Manager) error {
controller, err := ctrl.NewControllerManagedBy(mgr).
For(&infrav1.LinodeMachine{}).
For(&infrav1alpha1.LinodeMachine{}).
Watches(
&clusterv1.Machine{},
handler.EnqueueRequestsFromMapFunc(kutil.MachineToInfrastructureMapFunc(infrav1.GroupVersion.WithKind("LinodeMachine"))),
handler.EnqueueRequestsFromMapFunc(kutil.MachineToInfrastructureMapFunc(infrav1alpha1.GroupVersion.WithKind("LinodeMachine"))),
).
Watches(
&infrav1.LinodeCluster{},
&infrav1alpha1.LinodeCluster{},
handler.EnqueueRequestsFromMapFunc(r.linodeClusterToLinodeMachines(mgr.GetLogger())),
).
WithEventFilter(predicates.ResourceNotPausedAndHasFilterLabel(mgr.GetLogger(), r.WatchFilterValue)).
Expand Down

0 comments on commit d7e1e12

Please sign in to comment.