forked from ligato/vpp-agent
-
Notifications
You must be signed in to change notification settings - Fork 0
/
options.go
50 lines (40 loc) · 1.18 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
package ifplugin
import (
"go.ligato.io/cn-infra/v2/config"
"go.ligato.io/cn-infra/v2/logging"
"go.ligato.io/cn-infra/v2/servicelabel"
"go.ligato.io/vpp-agent/v3/plugins/kvscheduler"
"go.ligato.io/vpp-agent/v3/plugins/linux/nsplugin"
"go.ligato.io/vpp-agent/v3/plugins/netalloc"
)
// DefaultPlugin is a default instance of IfPlugin.
var DefaultPlugin = *NewPlugin()
// NewPlugin creates a new Plugin with the provides Options
func NewPlugin(opts ...Option) *IfPlugin {
p := &IfPlugin{}
p.PluginName = "linux-ifplugin"
p.KVScheduler = &kvscheduler.DefaultPlugin
p.NsPlugin = &nsplugin.DefaultPlugin
p.AddrAlloc = &netalloc.DefaultPlugin
p.ServiceLabel = &servicelabel.DefaultPlugin
for _, o := range opts {
o(p)
}
if p.Log == nil {
p.Log = logging.ForPlugin(p.String())
}
if p.Cfg == nil {
p.Cfg = config.ForPlugin(p.String(),
config.WithCustomizedFlag(config.FlagName(p.String()), "linux-ifplugin.conf"),
)
}
return p
}
// Option is a function that can be used in NewPlugin to customize Plugin.
type Option func(*IfPlugin)
// UseDeps returns Option that can inject custom dependencies.
func UseDeps(f func(*Deps)) Option {
return func(p *IfPlugin) {
f(&p.Deps)
}
}