-
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?
Conversation
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: The full list of commands accepted by this bot can be found here.
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
Hi @prasadkatti. Thanks for your PR. I'm waiting for a kubernetes-sigs member to verify that this patch is reasonable to test. If it is, they should reply with Once the patch is verified, the new status will be reflected by the I understand the commands that are listed here. Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository. |
/ok-to-test |
For this to review
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
pls share code coverage for new code as well
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 comment
The reason will be displayed to describe this comment to others. Learn more.
aws-region
not required, just region
There was a problem hiding this comment.
Choose a reason for hiding this comment
The 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 comment
The reason will be displayed to describe this comment to others. Learn more.
aws/geoproximitylocation-aws-region
does not looks right
provider/aws/aws.go
Outdated
@@ -926,6 +961,39 @@ func (p *AWSProvider) newChange(action route53types.ChangeAction, ep *endpoint.E | |||
if useGeolocation { | |||
change.ResourceRecordSet.GeoLocation = geolocation | |||
} | |||
|
|||
geoproximity := &route53types.GeoProximityLocation{} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what if geoproximity not enabled? why we even have it here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Honestly, I looked at how Geolocation works and tried to follow suit.
If there are no annotations corresponding to GeoProximity, then the GeoProximityLocation
field of the ResourceRecordSet
just stays nil
. The field is populated iff any of the geoproximity annotations are seen.
Also, I wish there was a separate annotation for specifying routing policy. But since that isn't present, I have to check for the presence of all possible geoproximity annotations before I can definitively say that the record is not using geoproximity.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This way it could be a breaking change, so unsure
@ivankatliarchuk - First of all, thanks for the taking the time to review. I have pushed another commit to address some of your review comments. I have also updated the PR description to include the manifests used for testing this. Let me know if you need anything else. I am still trying to figure out how to get code coverage for just the files I touched. I ran |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
would be nice to add docs with example setup and links to AWS docs.
https://github.com/kubernetes-sigs/external-dns/blob/master/docs/tutorials/aws.md
@@ -939,6 +982,40 @@ func (p *AWSProvider) newChange(action route53types.ChangeAction, ep *endpoint.E | |||
return change | |||
} | |||
|
|||
func buildChangeForGeoProximityEndpoint(change *Route53Change, ep *endpoint.Endpoint) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@@ -560,6 +566,22 @@ func (p *AWSProvider) records(ctx context.Context, zones map[string]*profiledZon | |||
return endpoints, nil | |||
} | |||
|
|||
func handleGeoProximityLocationRecord(r *route53types.ResourceRecordSet, ep *endpoint.Endpoint) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here is suggested improvements
- Use Early Returns: If the GeoProximityLocation is nil, return early to avoid unnecessary checks.
- Slightly rewrite the logic, to simplify readability.
if r.GeoProximityLocation == nil {
return
}
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)
}
@@ -939,6 +982,40 @@ func (p *AWSProvider) newChange(action route53types.ChangeAction, ep *endpoint.E | |||
return change | |||
} | |||
|
|||
func buildChangeForGeoProximityEndpoint(change *Route53Change, ep *endpoint.Endpoint) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
func buildChangeForGeoProximityEndpoint(change *Route53Change, ep *endpoint.Endpoint) { | |
func witchChangeForGeoProximityEndpoint(change *Route53Change, ep *endpoint.Endpoint) { |
@@ -939,6 +982,40 @@ func (p *AWSProvider) newChange(action route53types.ChangeAction, ep *endpoint.E | |||
return change | |||
} | |||
|
|||
func buildChangeForGeoProximityEndpoint(change *Route53Change, ep *endpoint.Endpoint) { | |||
geoproximity := &route53types.GeoProximityLocation{} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This method complexity is quite high, we need to split it most likely, example
func buildChangeForGeoProximityEndpoin(......)
geoproximity := &route53types.GeoProximityLocation{}
isGeoproximity := false
isGeoproximity = withGeoProximityAWSRegion(ep, geoproximity) || useGeoproximity
isGeoproximity = withGeoProximityBias(ep, geoproximity) || useGeoproximity
isGeoproximity = withGeoProximityCoordinates(ep, geoproximity) || useGeoproximity
isGeoproximity = withGeoProximityLocalZoneGroup(ep, geoproximity) || useGeoproximity
if isGeoproximity {
change.ResourceRecordSet.GeoProximityLocation = geoproximity
}
}
where
func withGeoProximityLocalZoneGroup(ep *endpoint.Endpoint, geoproximity *route53types.GeoProximityLocation) bool {
if prop, ok := ep.GetProviderSpecificProperty(providerSpecificGeoProximityLocationLocalZoneGroup); ok {
geoproximity.LocalZoneGroup = aws.String(prop)
return true
}
return false
}
latitude := coordinates[0] | ||
longitude := coordinates[1] | ||
geoproximity.Coordinates = &route53types.Coordinates{ | ||
Latitude: aws.String(latitude), | ||
Longitude: aws.String(longitude), | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would be nice to add some validation here as well
type Coordinates struct {
// Specifies a coordinate of the north–south position of a geographic point on
// the surface of the Earth (-90 - 90).
//
// This member is required.
Latitude *string
// Specifies a coordinate of the east–west position of a geographic point on the
// surface of the Earth (-180 - 180).
//
// This member is required.
Longitude *string
}
Probably something like
// validateCoordinates checks if the given latitude and longitude are valid.
func (c *Coordinates) validate(lat, lon string) error {
latitude, err := strconv.ParseFloat(lat, 64)
if err != nil || latitude < -90 || latitude > 90 {
return errors.New("invalid latitude: must be a number between -90 and 90")
}
longitude, err := strconv.ParseFloat(lon, 64)
if err != nil || longitude < -180 || longitude > 180 {
return errors.New("invalid longitude: must be a number between -180 and 180")
}
return nil
}
// Example usage
func (c *Coordinates) validateAndSet(coordinates string) (*route53types.Coordinates, error) {
parts := strings.Split(coordinates, ",")
if len(parts) != 2 {
return nil, errors.New("invalid coordinates format: expected 'latitude,longitude'")
}
lat := strings.TrimSpace(parts[0])
lon := strings.TrimSpace(parts[1])
if err := validateCoordinates(lat, lon); err != nil {
return nil, err
}
return &route53types.Coordinates{
Latitude: aws.String(lat),
Longitude: aws.String(lon),
}, nil
}
} | ||
useGeoproximity = true | ||
} else { | ||
log.Errorf("Invalid coordinates format for %s: %s; expected format 'latitude,longitude'", providerSpecificGeoProximityLocationCoordinates, prop) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is debatable, but most likely should be log.Warn, to warn user so they need to change configuraiton
Description
This PR adds support for Geoproximity routing in route53 to the AWS provider.
It adds four new annotations to enable this support.
Testing done
example.test
Also did some more testing along these lines to ensure there are no unnecessary Upserts when the service isn't changed.
I used these service manifests for testing -
Fixes #4927
Checklist