-
Notifications
You must be signed in to change notification settings - Fork 2.7k
feat(aws): add support for geoproximity routing #5347
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
266a566
633a9ca
3692a3b
79a7318
a4d1329
99cb5aa
674269c
eb200f8
1519d8c
4a44a13
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -53,19 +53,27 @@ const ( | |
// providerSpecificEvaluateTargetHealth specifies whether an AWS ALIAS record | ||
// has the EvaluateTargetHealth field set to true. Present iff the endpoint | ||
// has a `providerSpecificAlias` value of `true`. | ||
providerSpecificEvaluateTargetHealth = "aws/evaluate-target-health" | ||
providerSpecificWeight = "aws/weight" | ||
providerSpecificRegion = "aws/region" | ||
providerSpecificFailover = "aws/failover" | ||
providerSpecificGeolocationContinentCode = "aws/geolocation-continent-code" | ||
providerSpecificGeolocationCountryCode = "aws/geolocation-country-code" | ||
providerSpecificGeolocationSubdivisionCode = "aws/geolocation-subdivision-code" | ||
providerSpecificMultiValueAnswer = "aws/multi-value-answer" | ||
providerSpecificHealthCheckID = "aws/health-check-id" | ||
sameZoneAlias = "same-zone" | ||
providerSpecificEvaluateTargetHealth = "aws/evaluate-target-health" | ||
providerSpecificWeight = "aws/weight" | ||
providerSpecificRegion = "aws/region" | ||
providerSpecificFailover = "aws/failover" | ||
providerSpecificGeolocationContinentCode = "aws/geolocation-continent-code" | ||
providerSpecificGeolocationCountryCode = "aws/geolocation-country-code" | ||
providerSpecificGeolocationSubdivisionCode = "aws/geolocation-subdivision-code" | ||
providerSpecificGeoProximityLocationAWSRegion = "aws/geoproximitylocation-aws-region" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I have tried to match it with the field names in the GeoProximityLocation type There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
does not looks right |
||
providerSpecificGeoProximityLocationBias = "aws/geoproximitylocation-bias" | ||
providerSpecificGeoProximityLocationCoordinates = "aws/geoproximitylocation-coordinates" | ||
providerSpecificGeoProximityLocationLocalZoneGroup = "aws/geoproximitylocation-local-zone-group" | ||
prasadkatti marked this conversation as resolved.
Show resolved
Hide resolved
|
||
providerSpecificMultiValueAnswer = "aws/multi-value-answer" | ||
providerSpecificHealthCheckID = "aws/health-check-id" | ||
sameZoneAlias = "same-zone" | ||
// Currently supported up to 10 health checks or hosted zones. | ||
// https://docs.aws.amazon.com/Route53/latest/APIReference/API_ListTagsForResources.html#API_ListTagsForResources_RequestSyntax | ||
batchSize = 10 | ||
batchSize = 10 | ||
minLatitude = -90.0 | ||
maxLatitude = 90.0 | ||
minLongitude = -180.0 | ||
maxLongitude = 180.0 | ||
) | ||
|
||
// see elb: https://docs.aws.amazon.com/general/latest/gr/elb.html | ||
|
@@ -231,6 +239,12 @@ type profiledZone struct { | |
zone *route53types.HostedZone | ||
} | ||
|
||
type geoProximity struct { | ||
location *route53types.GeoProximityLocation | ||
endpoint *endpoint.Endpoint | ||
isSet bool | ||
} | ||
|
||
func (cs Route53Changes) Route53Changes() []route53types.Change { | ||
var ret []route53types.Change | ||
for _, c := range cs { | ||
|
@@ -542,6 +556,8 @@ func (p *AWSProvider) records(ctx context.Context, zones map[string]*profiledZon | |
ep.WithProviderSpecific(providerSpecificGeolocationSubdivisionCode, *r.GeoLocation.SubdivisionCode) | ||
} | ||
} | ||
case r.GeoProximityLocation != nil: | ||
prasadkatti marked this conversation as resolved.
Show resolved
Hide resolved
|
||
handleGeoProximityLocationRecord(&r, ep) | ||
default: | ||
// one of the above needs to be set, otherwise SetIdentifier doesn't make sense | ||
} | ||
|
@@ -560,6 +576,25 @@ func (p *AWSProvider) records(ctx context.Context, zones map[string]*profiledZon | |
return endpoints, nil | ||
} | ||
|
||
func handleGeoProximityLocationRecord(r *route53types.ResourceRecordSet, ep *endpoint.Endpoint) { | ||
prasadkatti marked this conversation as resolved.
Show resolved
Hide resolved
|
||
if region := aws.ToString(r.GeoProximityLocation.AWSRegion); region != "" { | ||
ep.WithProviderSpecific(providerSpecificGeoProximityLocationAWSRegion, region) | ||
} | ||
|
||
if bias := r.GeoProximityLocation.Bias; bias != nil { | ||
ep.WithProviderSpecific(providerSpecificGeoProximityLocationBias, fmt.Sprintf("%d", aws.ToInt32(bias))) | ||
} | ||
|
||
if coords := r.GeoProximityLocation.Coordinates; coords != nil { | ||
coordinates := fmt.Sprintf("%s,%s", aws.ToString(coords.Latitude), aws.ToString(coords.Longitude)) | ||
ep.WithProviderSpecific(providerSpecificGeoProximityLocationCoordinates, coordinates) | ||
} | ||
|
||
if localZoneGroup := aws.ToString(r.GeoProximityLocation.LocalZoneGroup); localZoneGroup != "" { | ||
ep.WithProviderSpecific(providerSpecificGeoProximityLocationLocalZoneGroup, localZoneGroup) | ||
} | ||
} | ||
|
||
// Identify if old and new endpoints require DELETE/CREATE instead of UPDATE. | ||
func (p *AWSProvider) requiresDeleteCreate(old *endpoint.Endpoint, newE *endpoint.Endpoint) bool { | ||
// a change of a record type | ||
|
@@ -832,12 +867,32 @@ func (p *AWSProvider) AdjustEndpoints(endpoints []*endpoint.Endpoint) ([]*endpoi | |
} else { | ||
ep.DeleteProviderSpecificProperty(providerSpecificEvaluateTargetHealth) | ||
} | ||
|
||
adjustGeoProximityLocationEndpoint(ep) | ||
} | ||
|
||
endpoints = append(endpoints, aliasCnameAaaaEndpoints...) | ||
return endpoints, nil | ||
} | ||
|
||
// if the endpoint is using geoproximity, set the bias to 0 if not set | ||
// this is needed to avoid unnecessary Upserts if the desired endpoint doesn't specify a bias | ||
func adjustGeoProximityLocationEndpoint(ep *endpoint.Endpoint) { | ||
if ep.SetIdentifier == "" { | ||
return | ||
} | ||
_, ok1 := ep.GetProviderSpecificProperty(providerSpecificGeoProximityLocationAWSRegion) | ||
_, ok2 := ep.GetProviderSpecificProperty(providerSpecificGeoProximityLocationLocalZoneGroup) | ||
_, ok3 := ep.GetProviderSpecificProperty(providerSpecificGeoProximityLocationCoordinates) | ||
|
||
if ok1 || ok2 || ok3 { | ||
// check if ep has bias property and if not, set it to 0 | ||
if _, ok := ep.GetProviderSpecificProperty(providerSpecificGeoProximityLocationBias); !ok { | ||
ep.SetProviderSpecificProperty(providerSpecificGeoProximityLocationBias, "0") | ||
} | ||
} | ||
} | ||
|
||
// newChange returns a route53 Change | ||
// returned Change is based on the given record by the given action, e.g. | ||
// action=ChangeActionCreate returns a change for creation of the record and | ||
|
@@ -926,6 +981,8 @@ func (p *AWSProvider) newChange(action route53types.ChangeAction, ep *endpoint.E | |
if useGeolocation { | ||
change.ResourceRecordSet.GeoLocation = geolocation | ||
} | ||
|
||
withChangeForGeoProximityEndpoint(change, ep) | ||
} | ||
|
||
if prop, ok := ep.GetProviderSpecificProperty(providerSpecificHealthCheckID); ok { | ||
|
@@ -939,6 +996,99 @@ func (p *AWSProvider) newChange(action route53types.ChangeAction, ep *endpoint.E | |
return change | ||
} | ||
|
||
func newGeoProximity(ep *endpoint.Endpoint) *geoProximity { | ||
return &geoProximity{ | ||
location: &route53types.GeoProximityLocation{}, | ||
endpoint: ep, | ||
isSet: false, | ||
} | ||
} | ||
|
||
func (gp *geoProximity) withAWSRegion() *geoProximity { | ||
if prop, ok := gp.endpoint.GetProviderSpecificProperty(providerSpecificGeoProximityLocationAWSRegion); ok { | ||
gp.location.AWSRegion = aws.String(prop) | ||
gp.isSet = true | ||
} | ||
return gp | ||
} | ||
|
||
// add a method to set the local zone group for the geoproximity location | ||
func (gp *geoProximity) withLocalZoneGroup() *geoProximity { | ||
if prop, ok := gp.endpoint.GetProviderSpecificProperty(providerSpecificGeoProximityLocationLocalZoneGroup); ok { | ||
gp.location.LocalZoneGroup = aws.String(prop) | ||
gp.isSet = true | ||
} | ||
return gp | ||
} | ||
|
||
// add a method to set the bias for the geoproximity location | ||
func (gp *geoProximity) withBias() *geoProximity { | ||
if prop, ok := gp.endpoint.GetProviderSpecificProperty(providerSpecificGeoProximityLocationBias); ok { | ||
bias, err := strconv.ParseInt(prop, 10, 32) | ||
if err != nil { | ||
log.Warnf("Failed parsing value of %s: %s: %v; using bias of 0", providerSpecificGeoProximityLocationBias, prop, err) | ||
bias = 0 | ||
} | ||
gp.location.Bias = aws.Int32(int32(bias)) | ||
gp.isSet = true | ||
} | ||
return gp | ||
} | ||
|
||
// validateCoordinates checks if the given latitude and longitude are valid. | ||
func validateCoordinates(lat, long string) error { | ||
latitude, err := strconv.ParseFloat(lat, 64) | ||
if err != nil || latitude < minLatitude || latitude > maxLatitude { | ||
return fmt.Errorf("invalid latitude: must be a number between %f and %f", minLatitude, maxLatitude) | ||
} | ||
|
||
longitude, err := strconv.ParseFloat(long, 64) | ||
if err != nil || longitude < minLongitude || longitude > maxLongitude { | ||
return fmt.Errorf("invalid longitude: must be a number between %f and %f", minLongitude, maxLongitude) | ||
} | ||
|
||
return nil | ||
} | ||
|
||
func (gp *geoProximity) withCoordinates() *geoProximity { | ||
if prop, ok := gp.endpoint.GetProviderSpecificProperty(providerSpecificGeoProximityLocationCoordinates); ok { | ||
coordinates := strings.Split(prop, ",") | ||
if len(coordinates) == 2 { | ||
latitude := coordinates[0] | ||
longitude := coordinates[1] | ||
if err := validateCoordinates(latitude, longitude); err != nil { | ||
log.Warnf("Invalid coordinates %s for name=%s setIdentifier=%s; %v", prop, gp.endpoint.DNSName, gp.endpoint.SetIdentifier, err) | ||
} else { | ||
gp.location.Coordinates = &route53types.Coordinates{ | ||
Latitude: aws.String(latitude), | ||
Longitude: aws.String(longitude), | ||
} | ||
gp.isSet = true | ||
} | ||
} else { | ||
log.Warnf("Invalid coordinates format for %s: %s; expected format 'latitude,longitude'", providerSpecificGeoProximityLocationCoordinates, prop) | ||
} | ||
} | ||
return gp | ||
} | ||
|
||
func (gp *geoProximity) build() *route53types.GeoProximityLocation { | ||
if gp.isSet { | ||
return gp.location | ||
} | ||
return nil | ||
} | ||
|
||
func withChangeForGeoProximityEndpoint(change *Route53Change, ep *endpoint.Endpoint) { | ||
geoProx := newGeoProximity(ep). | ||
withAWSRegion(). | ||
withCoordinates(). | ||
withLocalZoneGroup(). | ||
withBias() | ||
|
||
change.ResourceRecordSet.GeoProximityLocation = geoProx.build() | ||
} | ||
|
||
// searches for `changes` that are contained in `queue` and returns the `changes` separated by whether they were found in the queue (`foundChanges`) or not (`notFoundChanges`) | ||
func findChangesInQueue(changes Route53Changes, queue Route53Changes) (foundChanges, notFoundChanges Route53Changes) { | ||
if queue == nil { | ||
|
Uh oh!
There was an error while loading. Please reload this page.