discovery/kubernetes: optimize more gets

Signed-off-by: Giedrius Statkevičius <giedrius.statkevicius@vinted.com>
This commit is contained in:
Giedrius Statkevičius 2024-10-28 17:16:37 +02:00
parent 716fd5b11f
commit 58fedb6b61

View file

@ -467,11 +467,8 @@ func (e *EndpointSlice) resolvePodRef(ref *apiv1.ObjectReference) *apiv1.Pod {
if ref == nil || ref.Kind != "Pod" { if ref == nil || ref.Kind != "Pod" {
return nil return nil
} }
p := &apiv1.Pod{}
p.Namespace = ref.Namespace
p.Name = ref.Name
obj, exists, err := e.podStore.Get(p) obj, exists, err := e.podStore.GetByKey(namespacedName(ref.Namespace, ref.Name))
if err != nil { if err != nil {
e.logger.Error("resolving pod ref failed", "err", err) e.logger.Error("resolving pod ref failed", "err", err)
return nil return nil
@ -484,19 +481,19 @@ func (e *EndpointSlice) resolvePodRef(ref *apiv1.ObjectReference) *apiv1.Pod {
func (e *EndpointSlice) addServiceLabels(esa endpointSliceAdaptor, tg *targetgroup.Group) { func (e *EndpointSlice) addServiceLabels(esa endpointSliceAdaptor, tg *targetgroup.Group) {
var ( var (
svc = &apiv1.Service{}
found bool found bool
name string
) )
svc.Namespace = esa.namespace() ns := esa.namespace()
// Every EndpointSlice object has the Service they belong to in the // Every EndpointSlice object has the Service they belong to in the
// kubernetes.io/service-name label. // kubernetes.io/service-name label.
svc.Name, found = esa.labels()[esa.labelServiceName()] name, found = esa.labels()[esa.labelServiceName()]
if !found { if !found {
return return
} }
obj, exists, err := e.serviceStore.Get(svc) obj, exists, err := e.serviceStore.GetByKey(namespacedName(ns, name))
if err != nil { if err != nil {
e.logger.Error("retrieving service failed", "err", err) e.logger.Error("retrieving service failed", "err", err)
return return
@ -504,7 +501,7 @@ func (e *EndpointSlice) addServiceLabels(esa endpointSliceAdaptor, tg *targetgro
if !exists { if !exists {
return return
} }
svc = obj.(*apiv1.Service) svc := obj.(*apiv1.Service)
tg.Labels = tg.Labels.Merge(serviceLabels(svc)) tg.Labels = tg.Labels.Merge(serviceLabels(svc))
} }