Commit ce413e56 authored by Geoff Simmons's avatar Geoff Simmons

Clear out obsolete code for general shutdown.

The error channel for the Varnish controller was never used.
The Varnish controller uses a WaitGroup to wait for any running
admin interactions with Varnish instances to complete before
shutting down.

Closes #6
parent 68798224
...@@ -202,9 +202,8 @@ func main() { ...@@ -202,9 +202,8 @@ func main() {
os.Exit(-1) os.Exit(-1)
} }
vController.EvtGenerator(ingController) vController.EvtGenerator(ingController)
varnishDone := make(chan error, 1) go handleTermination(log, ingController, vController)
go handleTermination(log, ingController, vController, varnishDone) vController.Start()
vController.Start(varnishDone)
informerFactory.Start(informerStop) informerFactory.Start(informerStop)
ingController.Run(*readyfileF, uint16(*metricsPortF)) ingController.Run(*readyfileF, uint16(*metricsPortF))
} }
...@@ -212,28 +211,13 @@ func main() { ...@@ -212,28 +211,13 @@ func main() {
func handleTermination( func handleTermination(
log *logrus.Logger, log *logrus.Logger,
ingc *controller.IngressController, ingc *controller.IngressController,
vc *varnish.VarnishController, vc *varnish.VarnishController) {
varnishDone chan error) {
signalChan := make(chan os.Signal, 1) signalChan := make(chan os.Signal, 1)
signal.Notify(signalChan, syscall.SIGTERM, syscall.SIGINT) signal.Notify(signalChan, syscall.SIGTERM, syscall.SIGINT)
exitStatus := 0 sig := <-signalChan
exited := false
select {
case err := <-varnishDone:
if err != nil {
log.Error("varnish controller exited with an error:",
err)
exitStatus = 1
} else {
log.Info("varnish controller exited successfully")
}
exited = true
case sig := <-signalChan:
log.Infof("Received signal (%s), shutting down", sig.String()) log.Infof("Received signal (%s), shutting down", sig.String())
}
log.Info("Shutting down the ingress controller") log.Info("Shutting down the ingress controller")
ingc.Stop() ingc.Stop()
...@@ -241,11 +225,9 @@ func handleTermination( ...@@ -241,11 +225,9 @@ func handleTermination(
log.Info("Shutting down informers") log.Info("Shutting down informers")
informerStop <- struct{}{} informerStop <- struct{}{}
if !exited {
log.Info("Shutting down the Varnish controller") log.Info("Shutting down the Varnish controller")
vc.Quit() vc.Quit()
}
log.Info("Exiting with a status:", exitStatus) log.Info("Exiting")
os.Exit(exitStatus) os.Exit(0)
} }
...@@ -88,6 +88,8 @@ func (vc *VarnishController) checkInst(svc string, inst *varnishInst) bool { ...@@ -88,6 +88,8 @@ func (vc *VarnishController) checkInst(svc string, inst *varnishInst) bool {
} }
inst.admMtx.Lock() inst.admMtx.Lock()
defer inst.admMtx.Unlock() defer inst.admMtx.Unlock()
vc.wg.Add(1)
defer vc.wg.Done()
timer := prometheus.NewTimer(metrics.connectLatency) timer := prometheus.NewTimer(metrics.connectLatency)
adm, err := admin.Dial(inst.addr, *inst.admSecret, admTimeout) adm, err := admin.Dial(inst.addr, *inst.admSecret, admTimeout)
......
...@@ -151,7 +151,7 @@ type VarnishController struct { ...@@ -151,7 +151,7 @@ type VarnishController struct {
svcEvt interfaces.SvcEventGenerator svcEvt interfaces.SvcEventGenerator
svcs map[string]*varnishSvc svcs map[string]*varnishSvc
secrets map[string]*[]byte secrets map[string]*[]byte
errChan chan error wg *sync.WaitGroup
monIntvl time.Duration monIntvl time.Duration
} }
...@@ -183,6 +183,7 @@ func NewVarnishController( ...@@ -183,6 +183,7 @@ func NewVarnishController(
secrets: make(map[string]*[]byte), secrets: make(map[string]*[]byte),
log: log, log: log,
monIntvl: monIntvl, monIntvl: monIntvl,
wg: new(sync.WaitGroup),
}, nil }, nil
} }
...@@ -195,9 +196,7 @@ func (vc *VarnishController) EvtGenerator(svcEvt interfaces.SvcEventGenerator) { ...@@ -195,9 +196,7 @@ func (vc *VarnishController) EvtGenerator(svcEvt interfaces.SvcEventGenerator) {
// Start initiates the Varnish controller and starts the monitor // Start initiates the Varnish controller and starts the monitor
// goroutine. // goroutine.
func (vc *VarnishController) Start(errChan chan error) { func (vc *VarnishController) Start() {
vc.errChan = errChan
vc.log.Info("Starting Varnish controller")
fmt.Printf("Varnish controller logging at level: %s\n", vc.log.Level) fmt.Printf("Varnish controller logging at level: %s\n", vc.log.Level)
go vc.monitor(vc.monIntvl) go vc.monitor(vc.monIntvl)
} }
...@@ -212,6 +211,8 @@ func (vc *VarnishController) updateVarnishInstance(inst *varnishInst, ...@@ -212,6 +211,8 @@ func (vc *VarnishController) updateVarnishInstance(inst *varnishInst,
} }
inst.admMtx.Lock() inst.admMtx.Lock()
defer inst.admMtx.Unlock() defer inst.admMtx.Unlock()
vc.wg.Add(1)
defer vc.wg.Done()
vc.log.Tracef("Connect to %s, timeout=%v", inst.addr, admTimeout) vc.log.Tracef("Connect to %s, timeout=%v", inst.addr, admTimeout)
timer := prometheus.NewTimer(metrics.connectLatency) timer := prometheus.NewTimer(metrics.connectLatency)
...@@ -359,6 +360,8 @@ func (vc *VarnishController) setCfgLabel(inst *varnishInst, ...@@ -359,6 +360,8 @@ func (vc *VarnishController) setCfgLabel(inst *varnishInst,
metrics := getInstanceMetrics(inst.addr) metrics := getInstanceMetrics(inst.addr)
inst.admMtx.Lock() inst.admMtx.Lock()
defer inst.admMtx.Unlock() defer inst.admMtx.Unlock()
vc.wg.Add(1)
defer vc.wg.Done()
vc.log.Tracef("Connect to %s, timeout=%v", inst.addr, admTimeout) vc.log.Tracef("Connect to %s, timeout=%v", inst.addr, admTimeout)
timer := prometheus.NewTimer(metrics.connectLatency) timer := prometheus.NewTimer(metrics.connectLatency)
...@@ -753,5 +756,7 @@ func (vc *VarnishController) DeleteAdmSecret(name string) { ...@@ -753,5 +756,7 @@ func (vc *VarnishController) DeleteAdmSecret(name string) {
// Quit stops the Varnish controller. // Quit stops the Varnish controller.
func (vc *VarnishController) Quit() { func (vc *VarnishController) Quit() {
vc.errChan <- nil vc.log.Info("Wait for admin interactions with Varnish instances to " +
"finish")
vc.wg.Wait()
} }
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