mirror of
https://github.com/etcd-io/etcd.git
synced 2024-09-27 06:25:44 +00:00
chore(config): move Sanitize and Force check to boot process
Make Load function just load parameters. So etcd instance could use Config struct to start service.
This commit is contained in:
parent
b56aa62bcc
commit
b0ffb4fd10
@ -142,16 +142,6 @@ func (c *Config) Load(arguments []string) error {
|
||||
return err
|
||||
}
|
||||
|
||||
// Sanitize all the input fields.
|
||||
if err := c.Sanitize(); err != nil {
|
||||
return fmt.Errorf("sanitize: %v", err)
|
||||
}
|
||||
|
||||
// Force remove server configuration if specified.
|
||||
if c.Force {
|
||||
c.Reset()
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
|
@ -479,7 +479,7 @@ func TestConfigCustomConfigOverrideSystemConfig(t *testing.T) {
|
||||
c := New()
|
||||
c.SystemPath = p1
|
||||
assert.Nil(t, c.Load([]string{"-config", p2}), "")
|
||||
assert.Equal(t, c.Addr, "http://127.0.0.1:6000", "")
|
||||
assert.Equal(t, c.Addr, "127.0.0.1:6000", "")
|
||||
})
|
||||
})
|
||||
}
|
||||
@ -494,7 +494,7 @@ func TestConfigEnvVarOverrideCustomConfig(t *testing.T) {
|
||||
c := New()
|
||||
c.SystemPath = ""
|
||||
assert.Nil(t, c.Load([]string{"-config", path}), "")
|
||||
assert.Equal(t, c.Peer.Addr, "http://127.0.0.1:8000", "")
|
||||
assert.Equal(t, c.Peer.Addr, "127.0.0.1:8000", "")
|
||||
})
|
||||
}
|
||||
|
||||
@ -506,7 +506,7 @@ func TestConfigCLIArgsOverrideEnvVar(t *testing.T) {
|
||||
c := New()
|
||||
c.SystemPath = ""
|
||||
assert.Nil(t, c.Load([]string{"-addr", "127.0.0.1:2000"}), "")
|
||||
assert.Equal(t, c.Addr, "http://127.0.0.1:2000", "")
|
||||
assert.Equal(t, c.Addr, "127.0.0.1:2000", "")
|
||||
}
|
||||
|
||||
//--------------------------------------
|
||||
|
10
etcd/etcd.go
10
etcd/etcd.go
@ -61,6 +61,16 @@ func New(c *config.Config) *Etcd {
|
||||
|
||||
// Run the etcd instance.
|
||||
func (e *Etcd) Run() {
|
||||
// Sanitize all the input fields.
|
||||
if err := e.Config.Sanitize(); err != nil {
|
||||
log.Fatalf("failed sanitizing configuration: %v", err)
|
||||
}
|
||||
|
||||
// Force remove server configuration if specified.
|
||||
if e.Config.Force {
|
||||
e.Config.Reset()
|
||||
}
|
||||
|
||||
// Enable options.
|
||||
if e.Config.VeryVeryVerbose {
|
||||
log.Verbose = true
|
||||
|
@ -34,10 +34,6 @@ func TestRunStop(t *testing.T) {
|
||||
config.Addr = "localhost:0"
|
||||
config.Peer.Addr = "localhost:0"
|
||||
|
||||
if err := config.Sanitize(); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
etcd := New(config)
|
||||
go etcd.Run()
|
||||
<-etcd.ReadyNotify()
|
||||
|
Loading…
x
Reference in New Issue
Block a user