diff --git a/cmd/kube-proxy/app/server.go b/cmd/kube-proxy/app/server.go index 3f3cc6571e8..60ee6b86504 100644 --- a/cmd/kube-proxy/app/server.go +++ b/cmd/kube-proxy/app/server.go @@ -440,7 +440,7 @@ func serveHealthz(ctx context.Context, hz *healthcheck.ProxyHealthServer, errCh return } - fn := func() { + fn := func(ctx context.Context) { err := hz.Run(ctx) if err != nil { logger.Error(err, "Healthz server failed") @@ -454,7 +454,7 @@ func serveHealthz(ctx context.Context, hz *healthcheck.ProxyHealthServer, errCh logger.Error(nil, "Healthz server returned without error") } } - go wait.Until(fn, 5*time.Second, ctx.Done()) + go wait.UntilWithContext(ctx, fn, 5*time.Second) } func serveMetrics(ctx context.Context, bindAddress string, proxyMode kubeproxyconfig.ProxyMode, enableProfiling bool, flagzReader flagz.Reader, errCh chan error) { @@ -493,12 +493,11 @@ func serveMetrics(ctx context.Context, bindAddress string, proxyMode kubeproxyco statusz.Install(proxyMux, kubeProxy, reg) } - fn := func() { + fn := func(ctx context.Context) { var err error defer func() { if err != nil { - err = fmt.Errorf("starting metrics server failed: %w", err) - utilruntime.HandleError(err) + utilruntime.HandleErrorWithContext(ctx, err, "starting metrics server failed") if errCh != nil { errCh <- err // if in hardfail mode, never retry again @@ -520,7 +519,7 @@ func serveMetrics(ctx context.Context, bindAddress string, proxyMode kubeproxyco } } - go wait.Until(fn, 5*time.Second, wait.NeverStop) + go wait.UntilWithContext(ctx, fn, 5*time.Second) } // Run runs the specified ProxyServer. This should never exit (unless CleanupAndExit is set).