Skip to content

Commit

Permalink
chore(*) quit kuma-dp when envoy quits (#1480) (#1483)
Browse files Browse the repository at this point in the history
Signed-off-by: Nikolay Nikolaev <nikolay.nikolaev@konghq.com>
(cherry picked from commit 0b5a300)

Co-authored-by: Nikolay Nikolaev <nikolay.nikolaev@konghq.com>
  • Loading branch information
mergify[bot] and Nikolay Nikolaev authored Jan 27, 2021
1 parent 320c416 commit acd7af1
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 3 deletions.
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/envoyproxy/go-control-plane v0.6.9/go.mod h1:SBwIajubJHhxtWwsL9s8ss4safvEdbitLhGGK48rN6g=
github.com/envoyproxy/go-control-plane v0.9.0/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4=
Expand Down Expand Up @@ -760,7 +759,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

0 comments on commit acd7af1

Please sign in to comment.