Skip to content
This repository was archived by the owner on Jan 21, 2020. It is now read-only.

Commit 3b6cc3a

Browse files
kaufersDavid Chung
authored andcommitted
Honor default Options in the run/v0 package (#690)
Signed-off-by: Steven Kaufer <[email protected]>
1 parent 7bd619d commit 3b6cc3a

File tree

8 files changed

+31
-37
lines changed

8 files changed

+31
-37
lines changed

pkg/run/v0/enrollment/enrollment.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ func Run(plugins func() discovery.Plugins, name plugin.Name,
5858
panic("no plugins()")
5959
}
6060

61-
options := enrollment.Options{}
61+
options := DefaultOptions
6262
err = config.Decode(&options)
6363
if err != nil {
6464
return

pkg/run/v0/manager/etcd.go

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -23,17 +23,15 @@ type BackendEtcdOptions struct {
2323
}
2424

2525
// DefaultBackendEtcdOptions contains the defaults for running etcd as backend
26-
var DefaultBackendEtcdOptions = types.AnyValueMust(
27-
BackendEtcdOptions{
28-
PollInterval: types.FromDuration(5 * time.Second),
29-
Options: etcd.Options{
30-
RequestTimeout: 1 * time.Second,
31-
Config: clientv3.Config{
32-
Endpoints: []string{etcd.LocalIP() + ":2379"},
33-
},
26+
var DefaultBackendEtcdOptions = BackendEtcdOptions{
27+
PollInterval: types.FromDuration(5 * time.Second),
28+
Options: etcd.Options{
29+
RequestTimeout: 1 * time.Second,
30+
Config: clientv3.Config{
31+
Endpoints: []string{etcd.LocalIP() + ":2379"},
3432
},
3533
},
36-
)
34+
}
3735

3836
func configEtcdBackends(options BackendEtcdOptions, managerConfig *Options) error {
3937
if options.TLS != nil {

pkg/run/v0/manager/file.go

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -37,14 +37,12 @@ type BackendFileOptions struct {
3737
}
3838

3939
// DefaultBackendFileOptions is the default for the file backend
40-
var DefaultBackendFileOptions = types.AnyValueMust(
41-
BackendFileOptions{
42-
ID: local.Getenv(EnvID, "manager1"),
43-
PollInterval: types.FromDuration(5 * time.Second),
44-
LeaderFile: local.Getenv(EnvLeaderFile, filepath.Join(local.InfrakitHome(), "leader")),
45-
StoreDir: local.Getenv(EnvStoreDir, filepath.Join(local.InfrakitHome(), "configs")),
46-
},
47-
)
40+
var DefaultBackendFileOptions = BackendFileOptions{
41+
ID: local.Getenv(EnvID, "manager1"),
42+
PollInterval: types.FromDuration(5 * time.Second),
43+
LeaderFile: local.Getenv(EnvLeaderFile, filepath.Join(local.InfrakitHome(), "leader")),
44+
StoreDir: local.Getenv(EnvStoreDir, filepath.Join(local.InfrakitHome(), "configs")),
45+
}
4846

4947
func configFileBackends(options BackendFileOptions, managerConfig *Options) error {
5048

pkg/run/v0/manager/manager.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -94,16 +94,16 @@ func defaultOptions() (options Options) {
9494
switch options.Backend {
9595
case "swarm":
9696
options.Backend = "swarm"
97-
options.Settings = DefaultBackendSwarmOptions
97+
options.Settings = types.AnyValueMust(DefaultBackendSwarmOptions)
9898
case "etcd":
9999
options.Backend = "etcd"
100-
options.Settings = DefaultBackendEtcdOptions
100+
options.Settings = types.AnyValueMust(DefaultBackendEtcdOptions)
101101
case "file":
102102
options.Backend = "file"
103-
options.Settings = DefaultBackendFileOptions
103+
options.Settings = types.AnyValueMust(DefaultBackendFileOptions)
104104
default:
105105
options.Backend = "file"
106-
options.Settings = DefaultBackendFileOptions
106+
options.Settings = types.AnyValueMust(DefaultBackendFileOptions)
107107
}
108108

109109
return
@@ -118,7 +118,7 @@ func Run(plugins func() discovery.Plugins, name plugin.Name,
118118
panic("no plugins()")
119119
}
120120

121-
options := Options{}
121+
options := defaultOptions()
122122
err = config.Decode(&options)
123123
if err != nil {
124124
return
@@ -131,7 +131,7 @@ func Run(plugins func() discovery.Plugins, name plugin.Name,
131131

132132
switch strings.ToLower(options.Backend) {
133133
case "etcd":
134-
backendOptions := BackendEtcdOptions{}
134+
backendOptions := DefaultBackendEtcdOptions
135135
err = options.Settings.Decode(&backendOptions)
136136
if err != nil {
137137
return
@@ -143,7 +143,7 @@ func Run(plugins func() discovery.Plugins, name plugin.Name,
143143
}
144144
log.Info("etcd backend", "leader", options.leader, "store", options.store, "cleanup", options.cleanUpFunc)
145145
case "file":
146-
backendOptions := BackendFileOptions{}
146+
backendOptions := DefaultBackendFileOptions
147147
err = options.Settings.Decode(&backendOptions)
148148
if err != nil {
149149
return
@@ -155,7 +155,7 @@ func Run(plugins func() discovery.Plugins, name plugin.Name,
155155
}
156156
log.Info("file backend", "leader", options.leader, "store", options.store, "cleanup", options.cleanUpFunc)
157157
case "swarm":
158-
backendOptions := BackendSwarmOptions{}
158+
backendOptions := DefaultBackendSwarmOptions
159159
err = options.Settings.Decode(&backendOptions)
160160
if err != nil {
161161
return

pkg/run/v0/manager/swarm.go

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,13 @@ type BackendSwarmOptions struct {
2020
}
2121

2222
// DefaultBackendSwarmOptions is the Options for using the swarm backend.
23-
var DefaultBackendSwarmOptions = types.AnyValueMust(
24-
BackendSwarmOptions{
25-
PollInterval: types.FromDuration(5 * time.Second),
26-
Docker: docker.ConnectInfo{
27-
Host: "unix:///var/run/docker.sock",
28-
TLS: &tlsconfig.Options{},
29-
},
23+
var DefaultBackendSwarmOptions = BackendSwarmOptions{
24+
PollInterval: types.FromDuration(5 * time.Second),
25+
Docker: docker.ConnectInfo{
26+
Host: "unix:///var/run/docker.sock",
27+
TLS: &tlsconfig.Options{},
3028
},
31-
)
29+
}
3230

3331
func configSwarmBackends(options BackendSwarmOptions, managerConfig *Options) error {
3432
dockerClient, err := docker.NewClient(options.Docker.Host, options.Docker.TLS)

pkg/run/v0/simulator/simulator.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ var DefaultOptions = Options{
6767
func Run(plugins func() discovery.Plugins, name plugin.Name,
6868
config *types.Any) (transport plugin.Transport, impls map[run.PluginCode]interface{}, onStop func(), err error) {
6969

70-
options := Options{}
70+
options := DefaultOptions
7171
err = config.Decode(&options)
7272
if err != nil {
7373
return

pkg/run/v0/tailer/tailer.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ var DefaultOptions = tailer.Options{
4343
func Run(plugins func() discovery.Plugins, name plugin.Name,
4444
config *types.Any) (transport plugin.Transport, impls map[run.PluginCode]interface{}, onStop func(), err error) {
4545

46-
options := tailer.Options{}
46+
options := DefaultOptions
4747
err = config.Decode(&options)
4848
if err != nil {
4949
return

pkg/run/v0/terraform/terraform.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ var DefaultOptions = Options{
7474
func Run(plugins func() discovery.Plugins, name plugin.Name,
7575
config *types.Any) (transport plugin.Transport, impls map[run.PluginCode]interface{}, onStop func(), err error) {
7676

77-
options := Options{}
77+
options := DefaultOptions
7878
err = config.Decode(&options)
7979
if err != nil {
8080
return

0 commit comments

Comments
 (0)