Skip to content

Commit

Permalink
Address review comment
Browse files Browse the repository at this point in the history
  • Loading branch information
johngmyers committed May 10, 2023
1 parent 683663e commit 4745ddb
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 14 deletions.
9 changes: 2 additions & 7 deletions source/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand All @@ -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 {
Expand Down Expand Up @@ -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),
}
Expand Down
9 changes: 2 additions & 7 deletions source/pod.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down
6 changes: 6 additions & 0 deletions source/source.go
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down

0 comments on commit 4745ddb

Please sign in to comment.