Switch kube-proxy/server.go to context-aware logging APIs (HandleErrorWithContext, UntilWithContext)

This commit is contained in:
MoonYoung02
2025-11-01 00:11:46 +09:00
parent 5c7325dbda
commit f86a456ea3

View File

@@ -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).