From 4745ddbb0eca0fc9d1571bb77c7aec148d662c99 Mon Sep 17 00:00:00 2001 From: John Gardiner Myers Date: Tue, 9 May 2023 19:42:56 -0700 Subject: [PATCH] Address review comment --- source/node.go | 9 ++------- source/pod.go | 9 ++------- source/source.go | 6 ++++++ 3 files changed, 10 insertions(+), 14 deletions(-) diff --git a/source/node.go b/source/node.go index 39135ceaf..5e287e9a0 100644 --- a/source/node.go +++ b/source/node.go @@ -76,11 +76,6 @@ func NewNodeSource(ctx context.Context, kubeClient kubernetes.Interface, annotat }, nil } -type endpointsKey struct { - dnsName string - recordType string -} - // Endpoints returns endpoint objects for each service that should be processed. func (ns *nodeSource) Endpoints(ctx context.Context) ([]*endpoint.Endpoint, error) { nodes, err := ns.nodeInformer.Lister().List(labels.Everything()) @@ -93,7 +88,7 @@ func (ns *nodeSource) Endpoints(ctx context.Context) ([]*endpoint.Endpoint, erro return nil, err } - endpoints := map[endpointsKey]*endpoint.Endpoint{} + endpoints := map[endpointKey]*endpoint.Endpoint{} // create endpoints for all nodes for _, node := range nodes { @@ -141,7 +136,7 @@ func (ns *nodeSource) Endpoints(ctx context.Context) ([]*endpoint.Endpoint, erro ep.Labels = endpoint.NewLabels() for _, addr := range addrs { log.Debugf("adding endpoint %s target %s", ep, addr) - key := endpointsKey{ + key := endpointKey{ dnsName: ep.DNSName, recordType: suitableType(addr), } diff --git a/source/pod.go b/source/pod.go index 87772d75b..123468539 100644 --- a/source/pod.go +++ b/source/pod.go @@ -76,11 +76,6 @@ func NewPodSource(ctx context.Context, kubeClient kubernetes.Interface, namespac func (*podSource) AddEventHandler(ctx context.Context, handler func()) { } -type endpointKey struct { - domain string - recordType string -} - func (ps *podSource) Endpoints(ctx context.Context) ([]*endpoint.Endpoint, error) { pods, err := ps.podInformer.Lister().Pods(ps.namespace).List(labels.Everything()) if err != nil { @@ -128,14 +123,14 @@ func (ps *podSource) Endpoints(ctx context.Context) ([]*endpoint.Endpoint, error } endpoints := []*endpoint.Endpoint{} for key, targets := range endpointMap { - endpoints = append(endpoints, endpoint.NewEndpoint(key.domain, key.recordType, targets...)) + endpoints = append(endpoints, endpoint.NewEndpoint(key.dnsName, key.recordType, targets...)) } return endpoints, nil } func addToEndpointMap(endpointMap map[endpointKey][]string, domain string, recordType string, address string) { key := endpointKey{ - domain: domain, + dnsName: domain, recordType: recordType, } if _, ok := endpointMap[key]; !ok { diff --git a/source/source.go b/source/source.go index 8573772c3..91b83bb4f 100644 --- a/source/source.go +++ b/source/source.go @@ -86,6 +86,12 @@ type Source interface { AddEventHandler(context.Context, func()) } +// endpointKey is the type of a map key for separating endpoints or targets. +type endpointKey struct { + dnsName string + recordType string +} + func getTTLFromAnnotations(annotations map[string]string) (endpoint.TTL, error) { ttlNotConfigured := endpoint.TTL(0) ttlAnnotation, exists := annotations[ttlAnnotationKey]