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 <zchengjoey@gmail.com>
This commit is contained in:
joey 2024-09-08 15:32:58 +08:00
parent f5c5384181
commit 0dcaedeb6c
No known key found for this signature in database
GPG Key ID: B5AE69C27B241A78

View File

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