Address review comment

This commit is contained in:
John Gardiner Myers 2023-05-09 19:42:56 -07:00
parent 683663e9c2
commit 4745ddbb0e
3 changed files with 10 additions and 14 deletions

View File

@ -76,11 +76,6 @@ func NewNodeSource(ctx context.Context, kubeClient kubernetes.Interface, annotat
}, nil }, nil
} }
type endpointsKey struct {
dnsName string
recordType string
}
// Endpoints returns endpoint objects for each service that should be processed. // Endpoints returns endpoint objects for each service that should be processed.
func (ns *nodeSource) Endpoints(ctx context.Context) ([]*endpoint.Endpoint, error) { func (ns *nodeSource) Endpoints(ctx context.Context) ([]*endpoint.Endpoint, error) {
nodes, err := ns.nodeInformer.Lister().List(labels.Everything()) 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 return nil, err
} }
endpoints := map[endpointsKey]*endpoint.Endpoint{} endpoints := map[endpointKey]*endpoint.Endpoint{}
// create endpoints for all nodes // create endpoints for all nodes
for _, node := range nodes { for _, node := range nodes {
@ -141,7 +136,7 @@ func (ns *nodeSource) Endpoints(ctx context.Context) ([]*endpoint.Endpoint, erro
ep.Labels = endpoint.NewLabels() ep.Labels = endpoint.NewLabels()
for _, addr := range addrs { for _, addr := range addrs {
log.Debugf("adding endpoint %s target %s", ep, addr) log.Debugf("adding endpoint %s target %s", ep, addr)
key := endpointsKey{ key := endpointKey{
dnsName: ep.DNSName, dnsName: ep.DNSName,
recordType: suitableType(addr), recordType: suitableType(addr),
} }

View File

@ -76,11 +76,6 @@ func NewPodSource(ctx context.Context, kubeClient kubernetes.Interface, namespac
func (*podSource) AddEventHandler(ctx context.Context, handler func()) { 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) { func (ps *podSource) Endpoints(ctx context.Context) ([]*endpoint.Endpoint, error) {
pods, err := ps.podInformer.Lister().Pods(ps.namespace).List(labels.Everything()) pods, err := ps.podInformer.Lister().Pods(ps.namespace).List(labels.Everything())
if err != nil { if err != nil {
@ -128,14 +123,14 @@ func (ps *podSource) Endpoints(ctx context.Context) ([]*endpoint.Endpoint, error
} }
endpoints := []*endpoint.Endpoint{} endpoints := []*endpoint.Endpoint{}
for key, targets := range endpointMap { 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 return endpoints, nil
} }
func addToEndpointMap(endpointMap map[endpointKey][]string, domain string, recordType string, address string) { func addToEndpointMap(endpointMap map[endpointKey][]string, domain string, recordType string, address string) {
key := endpointKey{ key := endpointKey{
domain: domain, dnsName: domain,
recordType: recordType, recordType: recordType,
} }
if _, ok := endpointMap[key]; !ok { if _, ok := endpointMap[key]; !ok {

View File

@ -86,6 +86,12 @@ type Source interface {
AddEventHandler(context.Context, func()) 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) { func getTTLFromAnnotations(annotations map[string]string) (endpoint.TTL, error) {
ttlNotConfigured := endpoint.TTL(0) ttlNotConfigured := endpoint.TTL(0)
ttlAnnotation, exists := annotations[ttlAnnotationKey] ttlAnnotation, exists := annotations[ttlAnnotationKey]