Skip to content

Commit

Permalink
add more checks for retrying on transient error during machine creation
Browse files Browse the repository at this point in the history
  • Loading branch information
AshleyDumaine committed Jul 29, 2024
1 parent 3119045 commit 061a407
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 10 deletions.
23 changes: 14 additions & 9 deletions controller/linodemachine_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ import (

const (
linodeBusyCode = 400
linodeTooManyRequests = 429
defaultDiskFilesystem = string(linodego.FilesystemExt4)

// conditions for preflight instance creation
Expand Down Expand Up @@ -262,6 +261,14 @@ func (r *LinodeMachineReconciler) reconcile(
return
}

func retryIfTransient(err error) (ctrl.Result, error) {
if util.IsTransientError(err) {
return ctrl.Result{RequeueAfter: reconciler.DefaultMachineControllerRetryDelay}, nil
}

return ctrl.Result{}, err
}

func (r *LinodeMachineReconciler) reconcileCreate(
ctx context.Context,
logger logr.Logger,
Expand Down Expand Up @@ -302,15 +309,11 @@ func (r *LinodeMachineReconciler) reconcileCreate(
createOpts, err := r.newCreateConfig(ctx, machineScope, tags, logger)
if err != nil {
logger.Error(err, "Failed to create Linode machine InstanceCreateOptions")
if util.IsTransientError(err) {
return ctrl.Result{RequeueAfter: reconciler.DefaultMachineControllerRetryDelay}, nil
}

return ctrl.Result{}, err
return retryIfTransient(err)
}
linodeInstance, err = machineScope.LinodeClient.CreateInstance(ctx, *createOpts)
if err != nil {
if linodego.ErrHasStatus(err, linodeTooManyRequests) || linodego.ErrHasStatus(err, linodego.ErrorFromError) {
if linodego.ErrHasStatus(err, http.StatusTooManyRequests) || linodego.ErrHasStatus(err, linodego.ErrorFromError) {
logger.Error(err, "Failed to create Linode instance due to API error, requeing")
return ctrl.Result{RequeueAfter: reconciler.DefaultMachineControllerRetryDelay}, nil
}
Expand Down Expand Up @@ -362,11 +365,13 @@ func (r *LinodeMachineReconciler) reconcileInstanceCreate(
instanceConfig, err := r.getDefaultInstanceConfig(ctx, machineScope, linodeInstance.ID)
if err != nil {
logger.Error(err, "Failed to get default instance configuration")
return ctrl.Result{}, err
return retryIfTransient(err)

}

Check failure on line 370 in controller/linodemachine_controller.go

View workflow job for this annotation

GitHub Actions / go-analyze

unnecessary trailing newline (whitespace)

if _, err := machineScope.LinodeClient.UpdateInstanceConfig(ctx, linodeInstance.ID, instanceConfig.ID, linodego.InstanceConfigUpdateOptions{Kernel: machineScope.LinodeMachine.Spec.Configuration.Kernel}); err != nil {
return ctrl.Result{}, err
logger.Error(err, "Failed to get update instance configuration")
return retryIfTransient(err)
}
}

Expand Down
2 changes: 1 addition & 1 deletion util/reconciler/defaults.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ const (
// DefaultMachineControllerWaitForRunningTimeout is the default timeout if instance is not running.
DefaultMachineControllerWaitForRunningTimeout = 20 * time.Minute
// DefaultMachineControllerRetryDelay is the default requeue delay if there is an error.
DefaultMachineControllerRetryDelay = 10 * time.Second
DefaultMachineControllerRetryDelay = 30 * time.Second

// DefaultVPCControllerReconcileDelay is the default requeue delay when a reconcile operation fails.
DefaultVPCControllerReconcileDelay = 5 * time.Second
Expand Down

0 comments on commit 061a407

Please sign in to comment.