@@ -113,7 +113,8 @@ func (m *DataManager) Reconcile(ctx context.Context) error {
113113 m .clearError (ctx )
114114
115115 if err := m .createSecrets (ctx ); err != nil {
116- if ok := errors .As (err , & hasRequeueAfterError ); ok {
116+ var reconcileError ReconcileError
117+ if errors .As (err , & reconcileError ) && reconcileError .IsTransient () {
117118 return err
118119 }
119120 m .setError (ctx , errors .Cause (err ).Error ())
@@ -220,8 +221,9 @@ func (m *DataManager) createSecrets(ctx context.Context) error {
220221 return errors .Wrapf (err , "Metal3Machine's owner Machine could not be retrieved" )
221222 }
222223 if capiMachine == nil {
223- m .Log .Info ("Waiting for Machine Controller to set OwnerRef on Metal3Machine" )
224- return & RequeueAfterError {RequeueAfter : requeueAfter }
224+ errMessage := "Waiting for Machine Controller to set OwnerRef on Metal3Machine"
225+ m .Log .Info (errMessage )
226+ return WithTransientError (errors .New (errMessage ), requeueAfter )
225227 }
226228 m .Log .Info ("Fetched Machine" )
227229
@@ -231,7 +233,9 @@ func (m *DataManager) createSecrets(ctx context.Context) error {
231233 return err
232234 }
233235 if bmh == nil {
234- return & RequeueAfterError {RequeueAfter : requeueAfter }
236+ errMessage := "Waiting for BareMetalHost to become available"
237+ m .Log .Info (errMessage )
238+ return WithTransientError (errors .New (errMessage ), requeueAfter )
235239 }
236240 m .Log .Info ("Fetched BMH" )
237241
@@ -328,7 +332,7 @@ type reconciledClaim struct {
328332// getAddressesFromPool allocates IP addresses from all IP pools referenced by a [Metal3DataTemplate].
329333// It does so by creating IP claims for each referenced pool. It will check whether the claim was fulfilled
330334// and return a map containing all pools and addresses. If some claims are not fulfilled yet, it will
331- // return a [RequeueAfterError] , indicating that some addresses were not fully allocated yet.
335+ // return a Transient type ReconcileError , indicating that some addresses were not fully allocated yet.
332336func (m * DataManager ) getAddressesFromPool (ctx context.Context ,
333337 m3dt infrav1.Metal3DataTemplate ,
334338) (map [string ]addressFromPool , error ) {
@@ -388,7 +392,7 @@ func (m *DataManager) getAddressesFromPool(ctx context.Context,
388392
389393 m .Log .Info ("done allocating addresses" , "addresses" , addresses , "requeue" , requeue )
390394 if requeue {
391- return addresses , & RequeueAfterError { RequeueAfter : requeueAfter }
395+ return addresses , WithTransientError ( nil , requeueAfter )
392396 }
393397 return addresses , nil
394398}
@@ -620,7 +624,8 @@ func (m *DataManager) ensureM3IPClaim(ctx context.Context, poolRef corev1.TypedL
620624 return reconciledClaim {m3Claim : ipClaim }, nil
621625 }
622626
623- if ok := errors .As (err , & hasRequeueAfterError ); ! ok {
627+ var reconcileError ReconcileError
628+ if ! errors .As (err , & reconcileError ) {
624629 return reconciledClaim {m3Claim : ipClaim }, err
625630 }
626631
@@ -651,15 +656,15 @@ func (m *DataManager) ensureM3IPClaim(ctx context.Context, poolRef corev1.TypedL
651656 return reconciledClaim {m3Claim : ipClaim }, err
652657 }
653658 if bmh == nil {
654- return reconciledClaim {m3Claim : ipClaim }, & RequeueAfterError { RequeueAfter : requeueAfter }
659+ return reconciledClaim {m3Claim : ipClaim }, WithTransientError ( nil , requeueAfter )
655660 }
656661 m .Log .Info ("Fetched BMH" )
657662
658663 ipClaim , err = fetchM3IPClaim (ctx , m .client , m .Log , bmh .Name + "-" + poolRef .Name , m .Data .Namespace )
659664 if err == nil {
660665 return reconciledClaim {m3Claim : ipClaim }, nil
661666 }
662- if ok := errors .As (err , & hasRequeueAfterError ); ! ok {
667+ if ! ( errors .As (err , & reconcileError ) && reconcileError . IsTransient ()) {
663668 return reconciledClaim {m3Claim : ipClaim }, err
664669 }
665670
@@ -683,7 +688,7 @@ func (m *DataManager) ensureM3IPClaim(ctx context.Context, poolRef corev1.TypedL
683688 }
684689 err = createObject (ctx , m .client , ipClaim )
685690 if err != nil {
686- if ok := errors .As (err , & hasRequeueAfterError ); ! ok {
691+ if ! ( errors .As (err , & reconcileError ) && reconcileError . IsTransient ()) {
687692 return reconciledClaim {m3Claim : ipClaim }, err
688693 }
689694 }
@@ -783,7 +788,8 @@ func (m *DataManager) releaseAddressFromM3Pool(ctx context.Context, poolRef core
783788 }
784789 ipClaim , err = fetchM3IPClaim (ctx , m .client , m .Log , m .Data .Name + "-" + poolRef .Name , m .Data .Namespace )
785790 if err != nil {
786- if ok := errors .As (err , & hasRequeueAfterError ); ! ok {
791+ var reconcileError ReconcileError
792+ if ! (errors .As (err , & reconcileError ) && reconcileError .IsTransient ()) {
787793 return err
788794 }
789795 return nil
@@ -1373,7 +1379,7 @@ func (m *DataManager) getM3Machine(ctx context.Context, m3dt *infrav1.Metal3Data
13731379
13741380 if err := m .client .Get (ctx , claimNamespacedName , capm3DataClaim ); err != nil {
13751381 if apierrors .IsNotFound (err ) {
1376- return nil , & RequeueAfterError { RequeueAfter : requeueAfter }
1382+ return nil , WithTransientError ( nil , requeueAfter )
13771383 }
13781384 return nil , err
13791385 }
@@ -1413,8 +1419,9 @@ func fetchM3IPClaim(ctx context.Context, cl client.Client, mLog logr.Logger,
14131419 }
14141420 if err := cl .Get (ctx , metal3ClaimName , metal3IPClaim ); err != nil {
14151421 if apierrors .IsNotFound (err ) {
1416- mLog .Info ("Address claim not found, requeuing" )
1417- return nil , & RequeueAfterError {RequeueAfter : requeueAfter }
1422+ errMessage := "Address claim not found, requeuing"
1423+ mLog .Info (errMessage )
1424+ return nil , WithTransientError (errors .New (errMessage ), requeueAfter )
14181425 }
14191426 err := errors .Wrap (err , "Failed to get address claim" )
14201427 return nil , err
0 commit comments