Merge pull request #348 from pjbgf/rate-limit
Add flags to configure exponential back-off retry
This commit is contained in:
		
						commit
						13dc750792
					
				| 
						 | 
				
			
			@ -48,6 +48,7 @@ import (
 | 
			
		|||
	"sigs.k8s.io/controller-runtime/pkg/controller"
 | 
			
		||||
	"sigs.k8s.io/controller-runtime/pkg/handler"
 | 
			
		||||
	"sigs.k8s.io/controller-runtime/pkg/predicate"
 | 
			
		||||
	"sigs.k8s.io/controller-runtime/pkg/ratelimiter"
 | 
			
		||||
	"sigs.k8s.io/controller-runtime/pkg/reconcile"
 | 
			
		||||
	"sigs.k8s.io/controller-runtime/pkg/source"
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -95,6 +96,7 @@ type ImageUpdateAutomationReconciler struct {
 | 
			
		|||
 | 
			
		||||
type ImageUpdateAutomationReconcilerOptions struct {
 | 
			
		||||
	MaxConcurrentReconciles int
 | 
			
		||||
	RateLimiter             ratelimiter.RateLimiter
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// +kubebuilder:rbac:groups=image.toolkit.fluxcd.io,resources=imageupdateautomations,verbs=get;list;watch;create;update;patch;delete
 | 
			
		||||
| 
						 | 
				
			
			@ -423,6 +425,7 @@ func (r *ImageUpdateAutomationReconciler) SetupWithManager(mgr ctrl.Manager, opt
 | 
			
		|||
		Watches(&source.Kind{Type: &imagev1_reflect.ImagePolicy{}}, handler.EnqueueRequestsFromMapFunc(r.automationsForImagePolicy)).
 | 
			
		||||
		WithOptions(controller.Options{
 | 
			
		||||
			MaxConcurrentReconciles: opts.MaxConcurrentReconciles,
 | 
			
		||||
			RateLimiter:             opts.RateLimiter,
 | 
			
		||||
		}).
 | 
			
		||||
		Complete(r)
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
							
								
								
									
										4
									
								
								main.go
								
								
								
								
							
							
						
						
									
										4
									
								
								main.go
								
								
								
								
							| 
						 | 
				
			
			@ -31,6 +31,7 @@ import (
 | 
			
		|||
	imagev1_reflect "github.com/fluxcd/image-reflector-controller/api/v1beta1"
 | 
			
		||||
	"github.com/fluxcd/pkg/runtime/acl"
 | 
			
		||||
	"github.com/fluxcd/pkg/runtime/client"
 | 
			
		||||
	helper "github.com/fluxcd/pkg/runtime/controller"
 | 
			
		||||
	"github.com/fluxcd/pkg/runtime/events"
 | 
			
		||||
	"github.com/fluxcd/pkg/runtime/leaderelection"
 | 
			
		||||
	"github.com/fluxcd/pkg/runtime/logger"
 | 
			
		||||
| 
						 | 
				
			
			@ -70,6 +71,7 @@ func main() {
 | 
			
		|||
		aclOptions            acl.Options
 | 
			
		||||
		logOptions            logger.Options
 | 
			
		||||
		leaderElectionOptions leaderelection.Options
 | 
			
		||||
		rateLimiterOptions    helper.RateLimiterOptions
 | 
			
		||||
		watchAllNamespaces    bool
 | 
			
		||||
		concurrent            int
 | 
			
		||||
	)
 | 
			
		||||
| 
						 | 
				
			
			@ -84,6 +86,7 @@ func main() {
 | 
			
		|||
	logOptions.BindFlags(flag.CommandLine)
 | 
			
		||||
	leaderElectionOptions.BindFlags(flag.CommandLine)
 | 
			
		||||
	aclOptions.BindFlags(flag.CommandLine)
 | 
			
		||||
	rateLimiterOptions.BindFlags(flag.CommandLine)
 | 
			
		||||
	flag.Parse()
 | 
			
		||||
 | 
			
		||||
	log := logger.NewLogger(logOptions)
 | 
			
		||||
| 
						 | 
				
			
			@ -133,6 +136,7 @@ func main() {
 | 
			
		|||
		NoCrossNamespaceRef: aclOptions.NoCrossNamespaceRefs,
 | 
			
		||||
	}).SetupWithManager(mgr, controllers.ImageUpdateAutomationReconcilerOptions{
 | 
			
		||||
		MaxConcurrentReconciles: concurrent,
 | 
			
		||||
		RateLimiter:             helper.GetRateLimiter(rateLimiterOptions),
 | 
			
		||||
	}); err != nil {
 | 
			
		||||
		setupLog.Error(err, "unable to create controller", "controller", "ImageUpdateAutomation")
 | 
			
		||||
		os.Exit(1)
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
		Reference in New Issue