2020-05-05 22:02:16 +00:00
|
|
|
// +build !no_embedded_executor
|
|
|
|
|
|
|
|
package executor
|
|
|
|
|
|
|
|
import (
|
2020-12-07 20:30:44 +00:00
|
|
|
"io/ioutil"
|
|
|
|
"path/filepath"
|
|
|
|
"strings"
|
|
|
|
|
|
|
|
"github.com/rancher/k3s/pkg/version"
|
2020-05-05 22:02:16 +00:00
|
|
|
"github.com/sirupsen/logrus"
|
|
|
|
"go.etcd.io/etcd/embed"
|
2020-12-07 20:30:44 +00:00
|
|
|
"go.etcd.io/etcd/etcdserver"
|
2020-05-05 22:02:16 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func (e Embedded) CurrentETCDOptions() (InitialOptions, error) {
|
|
|
|
return InitialOptions{}, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (e Embedded) ETCD(args ETCDConfig) error {
|
|
|
|
configFile, err := args.ToConfigFile()
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
cfg, err := embed.ConfigFromFile(configFile)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
etcd, err := embed.StartEtcd(cfg)
|
|
|
|
if err != nil {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
go func() {
|
2020-10-27 18:06:26 +00:00
|
|
|
select {
|
2020-12-07 20:30:44 +00:00
|
|
|
case err := <-etcd.Server.ErrNotify():
|
|
|
|
if strings.Contains(err.Error(), etcdserver.ErrMemberRemoved.Error()) {
|
|
|
|
tombstoneFile := filepath.Join(args.DataDir, "tombstone")
|
|
|
|
if err := ioutil.WriteFile(tombstoneFile, []byte{}, 0600); err != nil {
|
|
|
|
logrus.Fatalf("failed to write tombstone file to %s", tombstoneFile)
|
|
|
|
}
|
|
|
|
logrus.Infof("this node has been removed from the cluster please restart %s to rejoin the cluster", version.Program)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2020-10-27 18:06:26 +00:00
|
|
|
case <-etcd.Server.StopNotify():
|
2020-12-07 20:30:44 +00:00
|
|
|
logrus.Fatalf("etcd stopped")
|
2020-10-27 18:06:26 +00:00
|
|
|
case err := <-etcd.Err():
|
|
|
|
logrus.Fatalf("etcd exited: %v", err)
|
|
|
|
}
|
2020-05-05 22:02:16 +00:00
|
|
|
}()
|
|
|
|
return nil
|
|
|
|
}
|