k3s/pkg/daemons/executor/etcd.go
Chris Kim 334eae119a
[release-1.21] Add etcd extra args support for K3s (#4471)
* 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>
2021-11-11 20:36:17 -08:00

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
}