From ff937d6a4d7f6c3353702ab1ac5082e586ae75c3 Mon Sep 17 00:00:00 2001 From: Miguel Angel Ajo Date: Thu, 27 Jan 2022 12:05:18 +0100 Subject: [PATCH] Make kube-proxy Service stoppable The kube-proxy k8s code does not support an stop channel, but at least we can accept cancel on the context and move on, so MicroShift can be stopped properly when necessary. Related-Issue: #556 Signed-off-by: Miguel Angel Ajo --- pkg/node/kube-proxy.go | 24 +++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/pkg/node/kube-proxy.go b/pkg/node/kube-proxy.go index b97014ecb6..15c4f4431d 100644 --- a/pkg/node/kube-proxy.go +++ b/pkg/node/kube-proxy.go @@ -95,20 +95,34 @@ featureGates: } func (s *ProxyOptions) Run(ctx context.Context, ready chan<- struct{}, stopped chan<- struct{}) error { + proxyStopErr := make(chan error, 1) defer close(stopped) + // run readiness check go func() { healthcheckStatus := util.RetryInsecureHttpsGet("http://127.0.0.1:10256/healthz") if healthcheckStatus != 200 { - klog.Fatalf("%s failed to start", s.Name(), fmt.Errorf("Healthcheck failed. ")) + err := fmt.Errorf("%s failed to start, healthcheck failed", s.Name()) + klog.Error(err) + proxyStopErr <- err } klog.Infof("%s is ready", s.Name()) close(ready) }() - if err := s.options.Run(); err != nil { - klog.Fatalf("%s failed to start", s.Name(), err) - } - return ctx.Err() + go func() { + if err := s.options.Run(); err != nil { + klog.Errorf("%s failed to start %v", s.Name(), err) + proxyStopErr <- err + } + }() + + select { + case <-ctx.Done(): + return ctx.Err() + + case err := <-proxyStopErr: + return err + } }