55 "fmt"
66 "time"
77
8+ "github.com/spf13/pflag"
89 "k8s.io/apimachinery/pkg/api/errors"
910 "k8s.io/apimachinery/pkg/apis/meta/v1"
1011 "k8s.io/apimachinery/pkg/runtime"
@@ -27,11 +28,27 @@ import (
2728 "github.com/ucloud/redis-operator/pkg/util"
2829)
2930
30- // ReconcileTime is the delay between reconciliations
3131const ReconcileTime = 60 * time .Second
32- const MaxConcurrentReconciles = 4
3332
34- var log = logf .Log .WithName ("controller_rediscluster" )
33+ var (
34+ controllerFlagSet * pflag.FlagSet
35+ // maxConcurrentReconciles is the maximum number of concurrent Reconciles which can be run. Defaults to 4.
36+ maxConcurrentReconciles int
37+ // reconcileTime is the delay between reconciliations. Defaults to 60s.
38+ reconcileTime int
39+
40+ log = logf .Log .WithName ("controller_rediscluster" )
41+ )
42+
43+ func init () {
44+ controllerFlagSet = pflag .NewFlagSet ("controller" , pflag .ExitOnError )
45+ controllerFlagSet .IntVar (& maxConcurrentReconciles , "ctr-maxconcurrent" , 4 , "the maximum number of concurrent Reconciles which can be run. Defaults to 4." )
46+ controllerFlagSet .IntVar (& reconcileTime , "ctr-reconciletime" , 60 , "" )
47+ }
48+
49+ func FlagSet () * pflag.FlagSet {
50+ return controllerFlagSet
51+ }
3552
3653/**
3754* USER ACTION REQUIRED: This is a scaffold file intended for the user to modify with their own Controller
@@ -74,7 +91,7 @@ func newReconciler(mgr manager.Manager) reconcile.Reconciler {
7491func add (mgr manager.Manager , r reconcile.Reconciler ) error {
7592 // Create a new controller
7693 c , err := controller .New ("rediscluster-controller" , mgr , controller.Options {Reconciler : r ,
77- MaxConcurrentReconciles : MaxConcurrentReconciles })
94+ MaxConcurrentReconciles : maxConcurrentReconciles })
7895 if err != nil {
7996 return err
8097 }
@@ -209,7 +226,7 @@ func (r *ReconcileRedisCluster) Reconcile(request reconcile.Request) (reconcile.
209226 return reconcile.Result {RequeueAfter : 20 * time .Second }, nil
210227 }
211228
212- return reconcile.Result {RequeueAfter : ReconcileTime }, nil
229+ return reconcile.Result {RequeueAfter : time . Duration ( reconcileTime ) * time . Second }, nil
213230}
214231
215232func shoudManage (meta v1.Object ) bool {
0 commit comments