Skip to content

Commit

Permalink
update tests, remove unneeded scheme, conditionally retry machine delete
Browse files Browse the repository at this point in the history
  • Loading branch information
AshleyDumaine committed Jul 15, 2024
1 parent 2f35892 commit 576cb65
Show file tree
Hide file tree
Showing 3 changed files with 329 additions and 14 deletions.
1 change: 0 additions & 1 deletion cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,6 @@ func main() {
if err = reconciler.NewReconcilerWithTracing(
&controller.LinodeMachineReconciler{
Client: mgr.GetClient(),
Scheme: mgr.GetScheme(),
Recorder: mgr.GetEventRecorderFor("LinodeMachineReconciler"),
WatchFilterValue: machineWatchFilter,
LinodeApiKey: linodeToken,
Expand Down
14 changes: 9 additions & 5 deletions controller/linodemachine_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ import (
corev1 "k8s.io/api/core/v1"
apierrors "k8s.io/apimachinery/pkg/api/errors"
"k8s.io/apimachinery/pkg/api/resource"
"k8s.io/apimachinery/pkg/runtime"
utilerrors "k8s.io/apimachinery/pkg/util/errors"
"k8s.io/client-go/tools/record"
clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1"
Expand Down Expand Up @@ -95,7 +94,6 @@ type LinodeMachineReconciler struct {
LinodeApiKey string
LinodeDNSAPIKey string
WatchFilterValue string
Scheme *runtime.Scheme
ReconcileTimeout time.Duration
}

Expand Down Expand Up @@ -223,7 +221,7 @@ func (r *LinodeMachineReconciler) reconcile(
Name: machineScope.Cluster.Spec.InfrastructureRef.Name,
}

if err := r.Client.Get(ctx, linodeClusterKey, machineScope.LinodeCluster); err != nil {
if err := machineScope.Client.Get(ctx, linodeClusterKey, machineScope.LinodeCluster); err != nil {
if err = client.IgnoreNotFound(err); err != nil {
return ctrl.Result{}, fmt.Errorf("get linodecluster %q: %w", linodeClusterKey, err)
}
Expand Down Expand Up @@ -704,9 +702,15 @@ func (r *LinodeMachineReconciler) reconcileDelete(

if err := machineScope.LinodeClient.DeleteInstance(ctx, *machineScope.LinodeMachine.Spec.InstanceID); err != nil {
if util.IgnoreLinodeAPIError(err, http.StatusNotFound) != nil {
logger.Error(err, "Failed to delete Linode machine instance")
logger.Error(err, "Failed to fetch Linode instance")

return ctrl.Result{RequeueAfter: reconciler.DefaultClusterControllerReconcileDelay}, err
if machineScope.LinodeMachine.ObjectMeta.DeletionTimestamp.Add(reconciler.DefaultTimeout(r.ReconcileTimeout, reconciler.DefaultMachineControllerRetryDelay)).After(time.Now()) {
logger.Info("re-queuing Linode instance deletion")

return ctrl.Result{RequeueAfter: reconciler.DefaultMachineControllerRetryDelay}, nil
}

return ctrl.Result{}, err
}
}

Expand Down
Loading

0 comments on commit 576cb65

Please # to comment.