Skip to content

Commit

Permalink
chore(*): use waitgroup
Browse files Browse the repository at this point in the history
Signed-off-by: Jakub Dyszkiewicz <jakub.dyszkiewicz@gmail.com>
  • Loading branch information
jakubdyszkiewicz committed May 16, 2022
1 parent 161fdc1 commit f806edd
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 48 deletions.
9 changes: 5 additions & 4 deletions app/kuma-dp/pkg/dataplane/dnsserver/dnsserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"io"
"os/exec"
"regexp"
"sync"
"text/template"

"github.com/pkg/errors"
Expand All @@ -25,7 +26,7 @@ type DNSServer struct {
opts *Opts
path string

finalizer component.Finalizer
wg sync.WaitGroup
}

var _ component.GracefulComponent = &DNSServer{}
Expand Down Expand Up @@ -92,7 +93,7 @@ func (s *DNSServer) NeedLeaderElection() bool {
}

func (s *DNSServer) Start(stop <-chan struct{}) error {
s.finalizer.Running()
s.wg.Add(1)
ctx, cancel := context.WithCancel(context.Background())
defer cancel()

Expand Down Expand Up @@ -148,7 +149,7 @@ func (s *DNSServer) Start(stop <-chan struct{}) error {
done <- command.Wait()
// Component should only be considered done after CoreDNS exists.
// Otherwise, we may not propagate SIGTERM on time.
s.finalizer.Done()
s.wg.Done()
}()

select {
Expand All @@ -172,5 +173,5 @@ func (s *DNSServer) Start(stop <-chan struct{}) error {
}

func (s *DNSServer) WaitForDone() {
s.finalizer.WaitForDone()
s.wg.Wait()
}
9 changes: 5 additions & 4 deletions app/kuma-dp/pkg/dataplane/envoy/envoy.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"runtime"
"strconv"
"strings"
"sync"
"time"

envoy_bootstrap_v3 "github.com/envoyproxy/go-control-plane/envoy/config/bootstrap/v3"
Expand Down Expand Up @@ -62,7 +63,7 @@ var _ component.GracefulComponent = &Envoy{}
type Envoy struct {
opts Opts

finalizer component.Finalizer
wg sync.WaitGroup
}

type EnvoyVersion struct {
Expand All @@ -84,7 +85,7 @@ func lookupEnvoyPath(configuredPath string) (string, error) {
}

func (e *Envoy) Start(stop <-chan struct{}) error {
e.finalizer.Running()
e.wg.Add(1)

configFile, err := GenerateBootstrapFile(e.opts.Config.DataplaneRuntime, e.opts.BootstrapConfig)
if err != nil {
Expand Down Expand Up @@ -143,7 +144,7 @@ func (e *Envoy) Start(stop <-chan struct{}) error {
done <- command.Wait()
// Component should only be considered done after Envoy exists.
// Otherwise, we may not propagate SIGTERM on time.
e.finalizer.Done()
e.wg.Done()
}()

select {
Expand All @@ -166,7 +167,7 @@ func (e *Envoy) Start(stop <-chan struct{}) error {
}

func (e *Envoy) WaitForDone() {
e.finalizer.WaitForDone()
e.wg.Wait()
}

func (e *Envoy) DrainConnections() error {
Expand Down
40 changes: 0 additions & 40 deletions pkg/core/runtime/component/finalizer.go

This file was deleted.

0 comments on commit f806edd

Please sign in to comment.