From 002c85b2180d74e6960cdb2b085f62fe4f87d44a Mon Sep 17 00:00:00 2001 From: Adrian Moisey Date: Wed, 15 Oct 2025 17:17:07 +0200 Subject: [PATCH] Tweak the informer for Services It no longer filters out Services with the v1.IsHeadlessService label as that is left for EndpointSlices --- cmd/kube-proxy/app/server.go | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/cmd/kube-proxy/app/server.go b/cmd/kube-proxy/app/server.go index 3f3cc6571e8..98ede40e319 100644 --- a/cmd/kube-proxy/app/server.go +++ b/cmd/kube-proxy/app/server.go @@ -572,13 +572,16 @@ func (s *ProxyServer) Run(ctx context.Context) error { return err } - labelSelector := labels.NewSelector() - labelSelector = labelSelector.Add(*noProxyName, *noHeadlessEndpoints) + labelSelectorNoProxyName := labels.NewSelector().Add(*noProxyName) + labelSelectorNoHeadlessEndpoints := labels.NewSelector().Add(*noHeadlessEndpoints) - // Make informers that filter out objects that want a non-default service proxy. - informerFactory := informers.NewSharedInformerFactoryWithOptions(s.Client, s.Config.ConfigSyncPeriod.Duration, + // Make informer that contains no filters + informerFactory := informers.NewSharedInformerFactoryWithOptions(s.Client, s.Config.ConfigSyncPeriod.Duration) + + // Make informers that filter out objects that do not contain a service.kubernetes.io/headless label + endpointSliceInformerFactory := informers.NewSharedInformerFactoryWithOptions(s.Client, s.Config.ConfigSyncPeriod.Duration, informers.WithTweakListOptions(func(options *metav1.ListOptions) { - options.LabelSelector = labelSelector.String() + options.LabelSelector = labelSelectorNoHeadlessEndpoints.String() })) // Create configs (i.e. Watches for Services, EndpointSlices and ServiceCIDRs) @@ -588,14 +591,14 @@ func (s *ProxyServer) Run(ctx context.Context) error { // don't watch headless services for kube-proxy, they are proxied by DNS. serviceInformerFactory := informers.NewSharedInformerFactoryWithOptions(s.Client, s.Config.ConfigSyncPeriod.Duration, informers.WithTweakListOptions(func(options *metav1.ListOptions) { - options.LabelSelector = labelSelector.String() + options.LabelSelector = labelSelectorNoProxyName.String() options.FieldSelector = fields.OneTermNotEqualSelector("spec.clusterIP", v1.ClusterIPNone).String() })) serviceConfig := config.NewServiceConfig(ctx, serviceInformerFactory.Core().V1().Services(), s.Config.ConfigSyncPeriod.Duration) serviceConfig.RegisterEventHandler(s.Proxier) go serviceConfig.Run(ctx.Done()) - endpointSliceConfig := config.NewEndpointSliceConfig(ctx, informerFactory.Discovery().V1().EndpointSlices(), s.Config.ConfigSyncPeriod.Duration) + endpointSliceConfig := config.NewEndpointSliceConfig(ctx, endpointSliceInformerFactory.Discovery().V1().EndpointSlices(), s.Config.ConfigSyncPeriod.Duration) endpointSliceConfig.RegisterEventHandler(s.Proxier) go endpointSliceConfig.Run(ctx.Done()) @@ -607,6 +610,7 @@ func (s *ProxyServer) Run(ctx context.Context) error { // This has to start after the calls to NewServiceConfig because that // function must configure its shared informer event handlers first. informerFactory.Start(wait.NeverStop) + endpointSliceInformerFactory.Start(wait.NeverStop) serviceInformerFactory.Start(wait.NeverStop) // hollow-proxy doesn't need node config, and we don't create nodeManager for hollow-proxy.