From 0dcaedeb6c9f9c885a32d29eb335014a5e6ff559 Mon Sep 17 00:00:00 2001 From: joey Date: Sun, 8 Sep 2024 15:32:58 +0800 Subject: [PATCH] perf: optimize the `GetPodServiceMemberships` function. If the service is not the pod's membership, it seems unnecessary to get the `key` Signed-off-by: joey --- .../src/k8s.io/endpointslice/util/controller_utils.go | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/staging/src/k8s.io/endpointslice/util/controller_utils.go b/staging/src/k8s.io/endpointslice/util/controller_utils.go index 8b2bfb0bf38..99525fc5716 100644 --- a/staging/src/k8s.io/endpointslice/util/controller_utils.go +++ b/staging/src/k8s.io/endpointslice/util/controller_utils.go @@ -61,11 +61,12 @@ func GetPodServiceMemberships(serviceLister v1listers.ServiceLister, pod *v1.Pod // if the service has a nil selector this means selectors match nothing, not everything. continue } - key, err := cache.DeletionHandlingMetaNamespaceKeyFunc(service) - if err != nil { - return nil, err - } + if labels.ValidatedSetSelector(service.Spec.Selector).Matches(labels.Set(pod.Labels)) { + key, err := cache.DeletionHandlingMetaNamespaceKeyFunc(service) + if err != nil { + return nil, err + } set.Insert(key) } }