mirror of
https://github.com/k3s-io/k3s.git
synced 2024-06-07 19:41:36 +00:00
334eae119a
* Export cli server flags and etcd restoration functions (#3527) * Export cli server flags and etfd restoration functions Signed-off-by: galal-hussein <hussein.galal.ahmed.11@gmail.com> * export S3 Signed-off-by: galal-hussein <hussein.galal.ahmed.11@gmail.com> Signed-off-by: Chris Kim <oats87g@gmail.com> * Add etcd extra args support for K3s Signed-off-by: Chris Kim <oats87g@gmail.com> * Remove integration test Signed-off-by: Chris Kim <oats87g@gmail.com> Co-authored-by: Hussein Galal <galal-hussein@users.noreply.github.com>
56 lines
1.3 KiB
Go
56 lines
1.3 KiB
Go
//go:build !no_embedded_executor
|
|
// +build !no_embedded_executor
|
|
|
|
package executor
|
|
|
|
import (
|
|
"io/ioutil"
|
|
"path/filepath"
|
|
"strings"
|
|
|
|
"github.com/rancher/k3s/pkg/version"
|
|
"github.com/sirupsen/logrus"
|
|
"go.etcd.io/etcd/embed"
|
|
"go.etcd.io/etcd/etcdserver"
|
|
)
|
|
|
|
func (e Embedded) CurrentETCDOptions() (InitialOptions, error) {
|
|
return InitialOptions{}, nil
|
|
}
|
|
|
|
func (e Embedded) ETCD(args ETCDConfig, extraArgs []string) error {
|
|
configFile, err := args.ToConfigFile(extraArgs)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
cfg, err := embed.ConfigFromFile(configFile)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
etcd, err := embed.StartEtcd(cfg)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
go func() {
|
|
select {
|
|
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
|
|
}
|
|
|
|
case <-etcd.Server.StopNotify():
|
|
logrus.Fatalf("etcd stopped")
|
|
case err := <-etcd.Err():
|
|
logrus.Fatalf("etcd exited: %v", err)
|
|
}
|
|
}()
|
|
return nil
|
|
}
|