remove etcd data dir when etcd is disabled (#3059)

* remove etcd data dir when etcd is disabled

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

* fix comment

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

* more fixes

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

* use debug instead of info logs

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

@ -3,6 +3,7 @@ package cluster
import ( import (
"bytes" "bytes"
"context" "context"
"strings"
"github.com/k3s-io/kine/pkg/client" "github.com/k3s-io/kine/pkg/client"
"github.com/rancher/k3s/pkg/bootstrap" "github.com/rancher/k3s/pkg/bootstrap"
@ -23,6 +24,7 @@ func (c *Cluster) save(ctx context.Context) error {
if err != nil { if err != nil {
return err return err
} }
storageClient, err := client.New(c.etcdConfig) storageClient, err := client.New(c.etcdConfig)
if err != nil { if err != nil {
return err return err
@ -32,6 +34,9 @@ func (c *Cluster) save(ctx context.Context) error {
if err.Error() == "key exists" { if err.Error() == "key exists" {
logrus.Warnln("Bootstrap key exists. Please follow documentation updating a node after restore.") logrus.Warnln("Bootstrap key exists. Please follow documentation updating a node after restore.")
return nil return nil
} else if strings.Contains(err.Error(), "not supported for learner") {
logrus.Debug("Skipping bootstrap data save on learner.")
return nil
} }
return err return err
} }

@ -1011,5 +1011,13 @@ func (e *ETCD) GetMembersClientURLs(ctx context.Context) ([]string, error) {
// RemoveSelf will remove the member if it exists in the cluster // RemoveSelf will remove the member if it exists in the cluster
func (e *ETCD) RemoveSelf(ctx context.Context) error { func (e *ETCD) RemoveSelf(ctx context.Context) error {
return e.removePeer(ctx, e.name, e.address, true) if err := e.removePeer(ctx, e.name, e.address, true); err != nil {
return err
}
// backup the data dir to avoid issues when re-enabling etcd
oldDataDir := etcdDBDir(e.config) + "-old-" + strconv.Itoa(int(time.Now().Unix()))
// move the data directory to a temp path
return os.Rename(etcdDBDir(e.config), oldDataDir)
} }

Loading…
Cancel
Save