reset etcd name on cluster reset (#2284)

* reset etcd name on cluster reset

Signed-off-by: galal-hussein <hussein.galal.ahmed.11@gmail.com>

* gofmt

Signed-off-by: galal-hussein <hussein.galal.ahmed.11@gmail.com>
pull/2291/head
Hussein Galal 4 years ago committed by GitHub
parent 0aa73c4765
commit 46fe57d7e9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -148,8 +148,14 @@ func (e *ETCD) Reset(ctx context.Context, clientAccessInfo *clientaccess.Info) e
if info.IsDir() {
return fmt.Errorf("etcd: snapshot path is directory: %s", e.config.ClusterResetRestorePath)
}
return e.Restore(ctx)
if err := e.Restore(ctx); err != nil {
return err
}
}
if err := e.setName(true); err != nil {
return err
}
return e.newCluster(ctx, true)
}
@ -272,17 +278,17 @@ func (e *ETCD) Register(ctx context.Context, config *config.Control, l net.Liste
e.config.Datastore.Config.CertFile = e.runtime.ClientETCDCert
e.config.Datastore.Config.KeyFile = e.runtime.ClientETCDKey
if err := e.setName(); err != nil {
if err := e.setName(false); err != nil {
return nil, nil, err
}
return l, e.handler(handler), err
}
func (e *ETCD) setName() error {
func (e *ETCD) setName(force bool) error {
fileName := nameFile(e.config)
data, err := ioutil.ReadFile(fileName)
if os.IsNotExist(err) {
if os.IsNotExist(err) || force {
h, err := os.Hostname()
if err != nil {
return err
@ -615,11 +621,7 @@ func (e *ETCD) Restore(ctx context.Context) error {
} else {
return err
}
if err := e.setName(); err != nil {
return err
}
return e.newCluster(ctx, true)
return nil
}
// snapshotRetention iterates through the snapshots and removes the oldest

Loading…
Cancel
Save