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

Commit b731b3c

Browse files
committed
Merge pull request #1302 from mischief/fleet-etcd-endpoints
fleetd: use a sane default set of etcd endpoints
2 parents 57cf528 + 7dcf609 commit b731b3c

3 files changed

Lines changed: 89 additions & 27 deletions

File tree

fleetd/fleetd.go

Lines changed: 3 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,14 @@ import (
2020
"fmt"
2121
"os"
2222
"os/signal"
23-
"strings"
2423
"syscall"
2524

2625
"github.com/coreos/fleet/Godeps/_workspace/src/github.com/rakyll/globalconf"
2726

2827
"github.com/coreos/fleet/agent"
2928
"github.com/coreos/fleet/config"
3029
"github.com/coreos/fleet/log"
30+
"github.com/coreos/fleet/pkg"
3131
"github.com/coreos/fleet/registry"
3232
"github.com/coreos/fleet/server"
3333
"github.com/coreos/fleet/version"
@@ -65,7 +65,7 @@ func main() {
6565

6666
cfgset := flag.NewFlagSet("fleet", flag.ExitOnError)
6767
cfgset.Int("verbosity", 0, "Logging level")
68-
cfgset.Var(&stringSlice{}, "etcd_servers", "List of etcd endpoints")
68+
cfgset.Var(&pkg.StringSlice{"http://127.0.0.1:2379", "http://127.0.0.1:4001"}, "etcd_servers", "List of etcd endpoints")
6969
cfgset.String("etcd_keyfile", "", "SSL key file used to secure etcd communication")
7070
cfgset.String("etcd_certfile", "", "SSL certification file used to secure etcd communication")
7171
cfgset.String("etcd_cafile", "", "SSL Certificate Authority file used to secure etcd communication")
@@ -177,7 +177,7 @@ func getConfig(flagset *flag.FlagSet, userCfgFile string) (*config.Config, error
177177

178178
cfg := config.Config{
179179
Verbosity: (*flagset.Lookup("verbosity")).Value.(flag.Getter).Get().(int),
180-
EtcdServers: (*flagset.Lookup("etcd_servers")).Value.(flag.Getter).Get().(stringSlice),
180+
EtcdServers: (*flagset.Lookup("etcd_servers")).Value.(flag.Getter).Get().(pkg.StringSlice),
181181
EtcdKeyPrefix: (*flagset.Lookup("etcd_key_prefix")).Value.(flag.Getter).Get().(string),
182182
EtcdKeyFile: (*flagset.Lookup("etcd_keyfile")).Value.(flag.Getter).Get().(string),
183183
EtcdCertFile: (*flagset.Lookup("etcd_certfile")).Value.(flag.Getter).Get().(string),
@@ -220,27 +220,3 @@ func listenForSignals(sigmap map[os.Signal]func()) {
220220
}
221221
}
222222
}
223-
224-
type stringSlice []string
225-
226-
func (f *stringSlice) Set(value string) error {
227-
for _, item := range strings.Split(value, ",") {
228-
item = strings.TrimLeft(item, " [\"")
229-
item = strings.TrimRight(item, " \"]")
230-
*f = append(*f, item)
231-
}
232-
233-
return nil
234-
}
235-
236-
func (f *stringSlice) String() string {
237-
return fmt.Sprintf("%v", *f)
238-
}
239-
240-
func (f *stringSlice) Value() []string {
241-
return *f
242-
}
243-
244-
func (f *stringSlice) Get() interface{} {
245-
return *f
246-
}

pkg/flag.go

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
// Copyright 2015 CoreOS, Inc.
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
package pkg
16+
17+
import (
18+
"fmt"
19+
"strings"
20+
)
21+
22+
type StringSlice []string
23+
24+
func (f *StringSlice) Set(value string) error {
25+
var s StringSlice
26+
for _, item := range strings.Split(value, ",") {
27+
item = strings.TrimLeft(item, " [\"")
28+
item = strings.TrimRight(item, " \"]")
29+
s = append(s, item)
30+
}
31+
32+
*f = s
33+
34+
return nil
35+
}
36+
37+
func (f *StringSlice) String() string {
38+
return fmt.Sprintf("%v", *f)
39+
}
40+
41+
func (f *StringSlice) Value() []string {
42+
return *f
43+
}
44+
45+
func (f *StringSlice) Get() interface{} {
46+
return *f
47+
}

pkg/flag_test.go

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
// Copyright 2015 CoreOS, Inc.
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
package pkg
16+
17+
import (
18+
"reflect"
19+
"testing"
20+
)
21+
22+
func TestStringSlice(t *testing.T) {
23+
tests := []struct {
24+
input string
25+
output []string
26+
}{
27+
{`["a"]`, []string{"a"}},
28+
{`["a","b"]`, []string{"a", "b"}},
29+
}
30+
31+
for _, tt := range tests {
32+
var ss StringSlice
33+
ss.Set(tt.input)
34+
r := ss.Value()
35+
if !reflect.DeepEqual(r, tt.output) {
36+
t.Errorf("error setting StringSlice: expected %+v, got %+v", tt.output, r)
37+
}
38+
}
39+
}

0 commit comments

Comments
 (0)