This repository has been archived by the owner on Jun 4, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
options.go
71 lines (60 loc) · 2.23 KB
/
options.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
package server
import (
"flag"
"time"
api "github.com/appscode/messenger/apis/messenger/v1alpha1"
cs "github.com/appscode/messenger/client/clientset/versioned"
"github.com/appscode/messenger/pkg/controller"
"github.com/spf13/pflag"
crd_cs "k8s.io/apiextensions-apiserver/pkg/client/clientset/clientset/typed/apiextensions/v1beta1"
"k8s.io/client-go/kubernetes"
)
type ExtraOptions struct {
MaxNumRequeues int
NumThreads int
QPS float64
Burst int
ResyncPeriod time.Duration
GarbageCollectTime time.Duration
}
func NewExtraOptions() *ExtraOptions {
return &ExtraOptions{
MaxNumRequeues: 5,
NumThreads: 2,
QPS: 100,
Burst: 100,
ResyncPeriod: 10 * time.Minute,
GarbageCollectTime: time.Hour,
}
}
func (s *ExtraOptions) AddGoFlags(fs *flag.FlagSet) {
fs.Float64Var(&s.QPS, "qps", s.QPS, "The maximum QPS to the master from this client")
fs.IntVar(&s.Burst, "burst", s.Burst, "The maximum burst for throttle")
fs.DurationVar(&s.ResyncPeriod, "resync-period", s.ResyncPeriod, "If non-zero, will re-list this often. Otherwise, re-list will be delayed aslong as possible (until the upstream source closes the watch or times out.")
fs.DurationVar(&s.GarbageCollectTime, "gc-time", s.GarbageCollectTime, "The time after when crds are garbage collected")
fs.BoolVar(&api.EnableStatusSubresource, "enable-status-subresource", api.EnableStatusSubresource, "If true, uses sub resource for Voyager crds.")
}
func (s *ExtraOptions) AddFlags(fs *pflag.FlagSet) {
pfs := flag.NewFlagSet("messenger", flag.ExitOnError)
s.AddGoFlags(pfs)
fs.AddGoFlagSet(pfs)
}
func (s *ExtraOptions) ApplyTo(cfg *controller.Config) error {
var err error
cfg.MaxNumRequeues = s.MaxNumRequeues
cfg.NumThreads = s.NumThreads
cfg.ResyncPeriod = s.ResyncPeriod
cfg.GarbageCollectTime = s.GarbageCollectTime
cfg.ClientConfig.QPS = float32(s.QPS)
cfg.ClientConfig.Burst = s.Burst
if cfg.KubeClient, err = kubernetes.NewForConfig(cfg.ClientConfig); err != nil {
return err
}
if cfg.MessengerClient, err = cs.NewForConfig(cfg.ClientConfig); err != nil {
return err
}
if cfg.CRDClient, err = crd_cs.NewForConfig(cfg.ClientConfig); err != nil {
return err
}
return nil
}