Commit 100f4d19 authored by Brad Davidson's avatar Brad Davidson Committed by Brad Davidson

Pass context in to embedded etcd so that it can be stopped

Partial cherry-pick from 29c8b238Signed-off-by: 's avatarBrad Davidson <brad.davidson@rancher.com>
parent 4fa89524
...@@ -4,6 +4,7 @@ ...@@ -4,6 +4,7 @@
package executor package executor
import ( import (
"context"
"io/ioutil" "io/ioutil"
"path/filepath" "path/filepath"
"strings" "strings"
...@@ -18,7 +19,7 @@ func (e Embedded) CurrentETCDOptions() (InitialOptions, error) { ...@@ -18,7 +19,7 @@ func (e Embedded) CurrentETCDOptions() (InitialOptions, error) {
return InitialOptions{}, nil return InitialOptions{}, nil
} }
func (e Embedded) ETCD(args ETCDConfig, extraArgs []string) error { func (e Embedded) ETCD(ctx context.Context, args ETCDConfig, extraArgs []string) error {
configFile, err := args.ToConfigFile(extraArgs) configFile, err := args.ToConfigFile(extraArgs)
if err != nil { if err != nil {
return err return err
...@@ -45,6 +46,9 @@ func (e Embedded) ETCD(args ETCDConfig, extraArgs []string) error { ...@@ -45,6 +46,9 @@ func (e Embedded) ETCD(args ETCDConfig, extraArgs []string) error {
return return
} }
case <-ctx.Done():
logrus.Infof("stopping etcd")
etcd.Close()
case <-etcd.Server.StopNotify(): case <-etcd.Server.StopNotify():
logrus.Fatalf("etcd stopped") logrus.Fatalf("etcd stopped")
case err := <-etcd.Err(): case err := <-etcd.Err():
......
...@@ -30,7 +30,7 @@ type Executor interface { ...@@ -30,7 +30,7 @@ type Executor interface {
Scheduler(apiReady <-chan struct{}, args []string) error Scheduler(apiReady <-chan struct{}, args []string) error
ControllerManager(apiReady <-chan struct{}, args []string) error ControllerManager(apiReady <-chan struct{}, args []string) error
CurrentETCDOptions() (InitialOptions, error) CurrentETCDOptions() (InitialOptions, error)
ETCD(args ETCDConfig, extraArgs []string) error ETCD(ctx context.Context, args ETCDConfig, extraArgs []string) error
CloudControllerManager(ccmRBACReady <-chan struct{}, args []string) error CloudControllerManager(ccmRBACReady <-chan struct{}, args []string) error
} }
...@@ -161,8 +161,8 @@ func CurrentETCDOptions() (InitialOptions, error) { ...@@ -161,8 +161,8 @@ func CurrentETCDOptions() (InitialOptions, error) {
return executor.CurrentETCDOptions() return executor.CurrentETCDOptions()
} }
func ETCD(args ETCDConfig, extraArgs []string) error { func ETCD(ctx context.Context, args ETCDConfig, extraArgs []string) error {
return executor.ETCD(args, extraArgs) return executor.ETCD(ctx, args, extraArgs)
} }
func CloudControllerManager(ccmRBACReady <-chan struct{}, args []string) error { func CloudControllerManager(ccmRBACReady <-chan struct{}, args []string) error {
......
...@@ -616,7 +616,7 @@ func (e *ETCD) metricsURL(expose bool) string { ...@@ -616,7 +616,7 @@ func (e *ETCD) metricsURL(expose bool) string {
// cluster returns ETCDConfig for a cluster // cluster returns ETCDConfig for a cluster
func (e *ETCD) cluster(ctx context.Context, forceNew bool, options executor.InitialOptions) error { func (e *ETCD) cluster(ctx context.Context, forceNew bool, options executor.InitialOptions) error {
return executor.ETCD(executor.ETCDConfig{ return executor.ETCD(ctx, executor.ETCDConfig{
Name: e.name, Name: e.name,
InitialOptions: options, InitialOptions: options,
ForceNewCluster: forceNew, ForceNewCluster: forceNew,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment