Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(*) quit kuma-dp when envoy exits #1480

Merged
merged 1 commit into from
Jan 27, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 18 additions & 1 deletion app/kuma-dp/cmd/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,12 +112,15 @@ func newRunCmd() *cobra.Command {
cfg.ControlPlane.CaCert = string(cert)
}

shouldQuit := setupQuitChannel()

dataplane, err := envoy.New(envoy.Opts{
Config: cfg,
Generator: bootstrapGenerator,
Dataplane: dp,
Stdout: cmd.OutOrStdout(),
Stderr: cmd.OutOrStderr(),
Quit: shouldQuit,
})
if err != nil {
return err
Expand All @@ -130,7 +133,7 @@ func newRunCmd() *cobra.Command {
}

runLog.Info("starting Kuma DP", "version", kuma_version.Build.Version)
if err := componentMgr.Start(core.SetupSignalHandler()); err != nil {
if err := componentMgr.Start(shouldQuit); err != nil {
runLog.Error(err, "error while running Kuma DP")
return err
}
Expand Down Expand Up @@ -161,3 +164,17 @@ func writeFile(filename string, data []byte, perm os.FileMode) error {
}
return ioutil.WriteFile(filename, data, perm)
}

func setupQuitChannel() chan struct{} {
quit := make(chan struct{})
quitOnSignal := core.SetupSignalHandler()
go func() {
<-quitOnSignal
runLog.Info("Kuma DP caught an exit signal")
if quit != nil {
close(quit)
}
}()

return quit
}
5 changes: 5 additions & 0 deletions app/kuma-dp/pkg/dataplane/envoy/envoy.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ type Opts struct {
Dataplane *rest.Resource
Stdout io.Writer
Stderr io.Writer
Quit chan struct{}
}

func New(opts Opts) (*Envoy, error) {
Expand Down Expand Up @@ -168,6 +169,10 @@ func (e *Envoy) Start(stop <-chan struct{}) error {
} else {
runLog.Info("Envoy terminated successfully")
}
if e.opts.Quit != nil {
close(e.opts.Quit)
}

return err
}
}
Expand Down
2 changes: 0 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -337,7 +337,6 @@ github.com/elazarl/goproxy/ext v0.0.0-20190711103511-473e67f1d7d2/go.mod h1:gNh8
github.com/emicklei/go-restful v0.0.0-20170410110728-ff4f55a20633/go.mod h1:otzb+WCGbkyDHkqmQmT5YD2WR4BBwUdeQoFo8l/7tVs=
github.com/emicklei/go-restful v2.9.5+incompatible/go.mod h1:otzb+WCGbkyDHkqmQmT5YD2WR4BBwUdeQoFo8l/7tVs=
github.com/emicklei/go-restful v2.9.6+incompatible/go.mod h1:otzb+WCGbkyDHkqmQmT5YD2WR4BBwUdeQoFo8l/7tVs=
github.com/emicklei/go-restful v2.14.2+incompatible h1:uyx8VgUCryEkh7qbr8rEtrA0rGDEJ73F5lOJdB5m3V8=
github.com/emicklei/go-restful v2.14.2+incompatible/go.mod h1:otzb+WCGbkyDHkqmQmT5YD2WR4BBwUdeQoFo8l/7tVs=
github.com/emicklei/go-restful v2.15.0+incompatible h1:8KpYO/Xl/ZudZs5RNOEhWMBY4hmzlZhhRd9cu+jrZP4=
github.com/emicklei/go-restful v2.15.0+incompatible/go.mod h1:otzb+WCGbkyDHkqmQmT5YD2WR4BBwUdeQoFo8l/7tVs=
Expand Down Expand Up @@ -763,7 +762,6 @@ github.com/lib/pq v1.1.1/go.mod h1:5WUZQaWbwv1U+lTReE5YruASi9Al49XbQIvNi/34Woo=
github.com/lib/pq v1.2.0/go.mod h1:5WUZQaWbwv1U+lTReE5YruASi9Al49XbQIvNi/34Woo=
github.com/lib/pq v1.3.0/go.mod h1:5WUZQaWbwv1U+lTReE5YruASi9Al49XbQIvNi/34Woo=
github.com/lib/pq v1.7.0/go.mod h1:AlVN5x4E4T544tWzH6hKfbfQvm3HdbOxrmggDNAPY9o=
github.com/lib/pq v1.8.0 h1:9xohqzkUwzR4Ga4ivdTcawVS89YSDVxXMa3xJX3cGzg=
github.com/lib/pq v1.8.0/go.mod h1:AlVN5x4E4T544tWzH6hKfbfQvm3HdbOxrmggDNAPY9o=
github.com/lib/pq v1.9.0 h1:L8nSXQQzAYByakOFMTwpjRoHsMJklur4Gi59b6VivR8=
github.com/lib/pq v1.9.0/go.mod h1:AlVN5x4E4T544tWzH6hKfbfQvm3HdbOxrmggDNAPY9o=
Expand Down