Skip to content

Commit

Permalink
Filter out records without target
Browse files Browse the repository at this point in the history
  • Loading branch information
BadLiveware committed Mar 5, 2023
1 parent 0f4d143 commit e816cc4
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion controller/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -175,12 +175,14 @@ func (c *Controller) RunOnce(ctx context.Context) error {
registryARecords.Set(float64(len(regARecords)))
ctx = context.WithValue(ctx, provider.RecordsContextKey, records)

endpoints, err := c.Source.Endpoints(ctx)
unfilteredEndpoints, err := c.Source.Endpoints(ctx)
if err != nil {
sourceErrorsTotal.Inc()
deprecatedSourceErrors.Inc()
return err
}
endpoints := filterRecordsWithoutTarget(unfilteredEndpoints)

sourceEndpointsTotal.Set(float64(len(endpoints)))
srcARecords := filterARecords(endpoints)
sourceARecords.Set(float64(len(srcARecords)))
Expand Down Expand Up @@ -254,6 +256,18 @@ func fetchMatchingARecords(endpoints []*endpoint.Endpoint, registryRecords []*en
return cm
}

func filterRecordsWithoutTarget(endpoints []*endpoint.Endpoint) []*endpoint.Endpoint {
var records []*endpoint.Endpoint
for _, endPoint := range endpoints {
if len(endPoint.Targets) > 0 {
records = append(records, endPoint)
} else {
log.Debugf("Skipping record %s as it has no targets", endPoint)
}
}
return records
}

func filterARecords(endpoints []*endpoint.Endpoint) []string {
var aRecords []string
for _, endPoint := range endpoints {
Expand Down

0 comments on commit e816cc4

Please sign in to comment.