@@ -178,8 +178,13 @@ func (r *LinodeMachineReconciler) reconcile(ctx context.Context, logger logr.Log
178178 //nolint:dupl // Code duplication is simplicity in this case.
179179 defer func () {
180180 if err != nil {
181- // Only set failure reason if the error is not retryable.
182- if linodego .ErrHasStatus (err , http .StatusBadRequest ) {
181+ // Set specific failure reason for authentication errors
182+ if util .IsAuthenticationError (err ) {
183+ failureReason = util .CredentialError
184+ }
185+
186+ // Set failure status for terminal errors (400, 401, 403, 404)
187+ if util .IsTerminalError (err ) {
183188 machineScope .LinodeMachine .Status .FailureReason = util .Pointer (failureReason )
184189 machineScope .LinodeMachine .Status .FailureMessage = util .Pointer (err .Error ())
185190 machineScope .LinodeMachine .SetCondition (metav1.Condition {
@@ -535,7 +540,7 @@ func (r *LinodeMachineReconciler) reconcilePreflightMetadataSupportConfigure(ctx
535540 _ , err := machineScope .LinodeClient .GetRegion (ctx , machineScope .LinodeMachine .Spec .Region )
536541 if err != nil {
537542 logger .Error (err , fmt .Sprintf ("Failed to fetch region %s" , machineScope .LinodeMachine .Spec .Region ))
538- return retryIfTransient (err , logger )
543+ return retryIfTransient (err )
539544 }
540545 imageName := reconciler .DefaultMachineControllerLinodeImage
541546 if machineScope .LinodeMachine .Spec .Image != "" {
@@ -544,7 +549,7 @@ func (r *LinodeMachineReconciler) reconcilePreflightMetadataSupportConfigure(ctx
544549 _ , err = machineScope .LinodeClient .GetImage (ctx , imageName )
545550 if err != nil {
546551 logger .Error (err , fmt .Sprintf ("Failed to fetch image %s" , imageName ))
547- return retryIfTransient (err , logger )
552+ return retryIfTransient (err )
548553 }
549554 machineScope .LinodeMachine .SetCondition (metav1.Condition {
550555 Type : ConditionPreflightMetadataSupportConfigured ,
@@ -559,7 +564,7 @@ func (r *LinodeMachineReconciler) reconcilePreflightCreate(ctx context.Context,
559564 createOpts , err := newCreateConfig (ctx , machineScope , r .GzipCompressionEnabled , logger )
560565 if err != nil {
561566 logger .Error (err , "Failed to create Linode machine InstanceCreateOptions" )
562- return retryIfTransient (err , logger )
567+ return retryIfTransient (err )
563568 }
564569
565570 linodeInstance , retryAfter , err := createInstance (ctx , logger , machineScope , createOpts )
@@ -585,7 +590,7 @@ func (r *LinodeMachineReconciler) reconcilePreflightCreate(ctx context.Context,
585590 Reason : util .CreateError ,
586591 Message : err .Error (),
587592 })
588- return retryIfTransient (err , logger )
593+ return retryIfTransient (err )
589594 }
590595
591596 machineScope .LinodeMachine .SetCondition (metav1.Condition {
@@ -643,11 +648,11 @@ func (r *LinodeMachineReconciler) reconcilePreflightConfigure(ctx context.Contex
643648 instanceConfig , err := getDefaultInstanceConfig (ctx , machineScope , instanceID )
644649 if err != nil {
645650 logger .Error (err , "Failed to get default instance configuration" )
646- return retryIfTransient (err , logger )
651+ return retryIfTransient (err )
647652 }
648653 if _ , err := machineScope .LinodeClient .UpdateInstanceConfig (ctx , instanceID , instanceConfig .ID , configData ); err != nil {
649654 logger .Error (err , "Failed to update default instance configuration" , "configuration" , configData )
650- return retryIfTransient (err , logger )
655+ return retryIfTransient (err )
651656 }
652657 }
653658
@@ -729,7 +734,7 @@ func (r *LinodeMachineReconciler) reconcileUpdate(ctx context.Context, logger lo
729734
730735 var linodeInstance * linodego.Instance
731736 if linodeInstance , err = machineScope .LinodeClient .GetInstance (ctx , instanceID ); err != nil {
732- return retryIfTransient (err , logger )
737+ return retryIfTransient (err )
733738 }
734739 // update the status
735740 machineScope .LinodeMachine .Status .InstanceState = & linodeInstance .Status
0 commit comments