8
8
package options
9
9
10
10
import (
11
+ "math"
12
+
11
13
"github.com/spf13/viper"
12
14
utilerrors "k8s.io/apimachinery/pkg/util/errors"
13
15
"k8s.io/client-go/tools/clientcmd"
@@ -31,10 +33,12 @@ var _ app.CliOptions = (*Options)(nil)
31
33
32
34
// Options contains everything necessary to create and run a nightwatch server.
33
35
type Options struct {
34
- HealthOptions * genericoptions.HealthOptions `json:"health" mapstructure:"health"`
35
- MySQLOptions * genericoptions.MySQLOptions `json:"mysql" mapstructure:"mysql"`
36
- RedisOptions * genericoptions.RedisOptions `json:"redis" mapstructure:"redis"`
37
- Metrics * genericoptions.MetricsOptions `json:"metrics" mapstructure:"metrics"`
36
+ HealthOptions * genericoptions.HealthOptions `json:"health" mapstructure:"health"`
37
+ MySQLOptions * genericoptions.MySQLOptions `json:"db" mapstructure:"db"`
38
+ RedisOptions * genericoptions.RedisOptions `json:"redis" mapstructure:"redis"`
39
+ UserWatcherMaxWorkers int64 `json:"user-watcher-max-workers" mapstructure:"user-watcher-max-workers"`
40
+ DisableWatchers []string `json:"disable-watchers" mapstructure:"disable-watchers"`
41
+ Metrics * genericoptions.MetricsOptions `json:"metrics" mapstructure:"metrics"`
38
42
// Path to kubeconfig file with authorization and master location information.
39
43
Kubeconfig string `json:"kubeconfig" mapstructure:"kubeconfig"`
40
44
FeatureGates map [string ]bool `json:"feature-gates"`
@@ -44,11 +48,13 @@ type Options struct {
44
48
// NewOptions returns initialized Options.
45
49
func NewOptions () * Options {
46
50
o := & Options {
47
- HealthOptions : genericoptions .NewHealthOptions (),
48
- MySQLOptions : genericoptions .NewMySQLOptions (),
49
- RedisOptions : genericoptions .NewRedisOptions (),
50
- Metrics : genericoptions .NewMetricsOptions (),
51
- Log : log .NewOptions (),
51
+ HealthOptions : genericoptions .NewHealthOptions (),
52
+ MySQLOptions : genericoptions .NewMySQLOptions (),
53
+ RedisOptions : genericoptions .NewRedisOptions (),
54
+ UserWatcherMaxWorkers : math .MaxInt64 ,
55
+ DisableWatchers : []string {},
56
+ Metrics : genericoptions .NewMetricsOptions (),
57
+ Log : log .NewOptions (),
52
58
}
53
59
54
60
return o
@@ -57,7 +63,7 @@ func NewOptions() *Options {
57
63
// Flags returns flags for a specific server by section name.
58
64
func (o * Options ) Flags () (fss cliflag.NamedFlagSets ) {
59
65
o .HealthOptions .AddFlags (fss .FlagSet ("health" ))
60
- o .MySQLOptions .AddFlags (fss .FlagSet ("mysql " ))
66
+ o .MySQLOptions .AddFlags (fss .FlagSet ("db " ))
61
67
o .RedisOptions .AddFlags (fss .FlagSet ("redis" ))
62
68
o .Metrics .AddFlags (fss .FlagSet ("metrics" ))
63
69
o .Log .AddFlags (fss .FlagSet ("log" ))
@@ -66,6 +72,8 @@ func (o *Options) Flags() (fss cliflag.NamedFlagSets) {
66
72
// arrange these text blocks sensibly. Grrr.
67
73
fs := fss .FlagSet ("misc" )
68
74
fs .StringVar (& o .Kubeconfig , "kubeconfig" , o .Kubeconfig , "Path to kubeconfig file with authorization and master location information." )
75
+ fs .Int64Var (& o .UserWatcherMaxWorkers , "user-watcher-max-workers" , o .UserWatcherMaxWorkers , "Specify the maximum concurrency event of user watcher." )
76
+ fs .StringSliceVar (& o .DisableWatchers , "disable-watchers" , o .DisableWatchers , "The list of watchers that should be disabled." )
69
77
feature .DefaultMutableFeatureGate .AddFlag (fs )
70
78
71
79
return fss
@@ -77,6 +85,10 @@ func (o *Options) Complete() error {
77
85
return err
78
86
}
79
87
88
+ if o .UserWatcherMaxWorkers < 1 {
89
+ o .UserWatcherMaxWorkers = math .MaxInt64
90
+ }
91
+
80
92
_ = feature .DefaultMutableFeatureGate .SetFromMap (o .FeatureGates )
81
93
return nil
82
94
}
@@ -98,6 +110,8 @@ func (o *Options) Validate() error {
98
110
func (o * Options ) ApplyTo (c * nightwatch.Config ) error {
99
111
c .MySQLOptions = o .MySQLOptions
100
112
c .RedisOptions = o .RedisOptions
113
+ c .UserWatcherMaxWorkers = o .UserWatcherMaxWorkers
114
+ c .DisableWatchers = o .DisableWatchers
101
115
return nil
102
116
}
103
117
0 commit comments