Skip to content

Commit 8332d17

Browse files
committed
add commandline flag for controler
1 parent fb858e2 commit 8332d17

File tree

2 files changed

+25
-5
lines changed

2 files changed

+25
-5
lines changed

cmd/manager/main.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import (
1313

1414
"github.com/ucloud/redis-operator/pkg/apis"
1515
"github.com/ucloud/redis-operator/pkg/controller"
16+
"github.com/ucloud/redis-operator/pkg/controller/rediscluster"
1617
clusterMetrics "github.com/ucloud/redis-operator/pkg/metrics"
1718
"github.com/ucloud/redis-operator/pkg/util"
1819

@@ -53,6 +54,8 @@ func main() {
5354
// be added before calling pflag.Parse().
5455
pflag.CommandLine.AddFlagSet(zap.FlagSet())
5556

57+
pflag.CommandLine.AddFlagSet(rediscluster.FlagSet())
58+
5659
// Add flags registered by imported packages (e.g. glog and
5760
// controller-runtime)
5861
pflag.CommandLine.AddGoFlagSet(flag.CommandLine)

pkg/controller/rediscluster/controller.go

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
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
3131
const 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 {
7491
func 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

215232
func shoudManage(meta v1.Object) bool {

0 commit comments

Comments
 (0)