github.com/banzaicloud/operator-tools@v0.28.10/pkg/reconciler/result.go (about)

     1  // Copyright © 2020 Banzai Cloud
     2  //
     3  // Licensed under the Apache License, Version 2.0 (the "License");
     4  // you may not use this file except in compliance with the License.
     5  // You may obtain a copy of the License at
     6  //
     7  //    http://www.apache.org/licenses/LICENSE-2.0
     8  //
     9  // Unless required by applicable law or agreed to in writing, software
    10  // distributed under the License is distributed on an "AS IS" BASIS,
    11  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    12  // See the License for the specific language governing permissions and
    13  // limitations under the License.
    14  
    15  package reconciler
    16  
    17  import (
    18  	"emperror.dev/errors"
    19  	"sigs.k8s.io/controller-runtime/pkg/reconcile"
    20  )
    21  
    22  // Collects results and errors of all subcomponents instead of failing and bailing out immediately
    23  type CombinedResult struct {
    24  	Result reconcile.Result
    25  	Err error
    26  }
    27  
    28  func (c *CombinedResult) Combine(sub *reconcile.Result, err error) {
    29  	c.CombineErr(err)
    30  	if sub != nil {
    31  		if sub.Requeue {
    32  			c.Result.Requeue = true
    33  		}
    34  		// combined should be requeued at the minimum of all subresults
    35  		if sub.RequeueAfter > 0 {
    36  			if c.Result.RequeueAfter == 0 || sub.RequeueAfter < c.Result.RequeueAfter {
    37  				c.Result.RequeueAfter = sub.RequeueAfter
    38  			}
    39  		}
    40  	}
    41  }
    42  
    43  func (c *CombinedResult) CombineErr(err error) {
    44  	c.Err = errors.Combine(c.Err, err)
    45  }