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