Skip to content

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

Open
wants to merge 10 commits into
base: master
Choose a base branch
from

Conversation

prasadkatti
Copy link
Contributor

@prasadkatti prasadkatti commented May 1, 2025

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

  1. I created a hosted zone called example.test
  2. Applied the manifests below to my cluster
  3. Ran a single control loop of external-dns locally
  4. Verified on the AWS console that new records for the services were created
  5. Deleted the services
  6. Ran another loop of external-dns
  7. Verified the records were deleted from Route53.

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 -

apiVersion: v1
kind: Service
metadata:
  name: nginx-test-region
  annotations:
    external-dns.alpha.kubernetes.io/hostname: nginx-test.example.test
    external-dns.alpha.kubernetes.io/target: 8.8.8.8
    external-dns.alpha.kubernetes.io/set-identifier: region
    external-dns.alpha.kubernetes.io/aws-geoproximitylocation-aws-region: us-west-2
    external-dns.alpha.kubernetes.io/aws-geoproximitylocation-bias: "10"
spec:
  ports:
  - port: 80
    targetPort: 80
  selector:
    app: nginx

---

apiVersion: v1
kind: Service
metadata:
  name: nginx-test-coordinates
  annotations:
    external-dns.alpha.kubernetes.io/hostname: nginx-test.example.test
    external-dns.alpha.kubernetes.io/target: 8.8.8.8
    external-dns.alpha.kubernetes.io/set-identifier: coordinates
    external-dns.alpha.kubernetes.io/aws-geoproximitylocation-coordinates: 90,90
spec:
  ports:
  - port: 80
    targetPort: 80
  selector:
    app: nginx

---

# I didn't test this one, but it should work

# apiVersion: v1
# kind: Service
# metadata:
#   name: nginx-test-local-zone
#   annotations:
#     external-dns.alpha.kubernetes.io/hostname: nginx-test.example.test
#     external-dns.alpha.kubernetes.io/target: 8.8.8.8
#     external-dns.alpha.kubernetes.io/set-identifier: localzone
#     external-dns.alpha.kubernetes.io/aws-geoproximitylocation-local-zone-group: "usw2-pdx1-az1"
# spec:
#   ports:
#   - port: 80
#     targetPort: 80
#   selector:
#     app: nginx

Fixes #4927

Checklist

  • Unit tests updated
  • End user documentation updated. Haven't yet updated the docs. Will get to it once my others questions get resolved.

@k8s-ci-robot k8s-ci-robot added the cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. label May 1, 2025
@k8s-ci-robot k8s-ci-robot requested a review from mloiseleur May 1, 2025 06:17
@k8s-ci-robot k8s-ci-robot added the needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. label May 1, 2025
@k8s-ci-robot
Copy link
Contributor

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 /ok-to-test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work. Regular contributors should join the org to skip this step.

Once the patch is verified, the new status will be reflected by the ok-to-test label.

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.

@prasadkatti prasadkatti marked this pull request as draft May 1, 2025 06:17
@k8s-ci-robot k8s-ci-robot added do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels May 1, 2025
@prasadkatti prasadkatti marked this pull request as ready for review May 1, 2025 06:51
@k8s-ci-robot k8s-ci-robot removed the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label May 1, 2025
@ivankatliarchuk
Copy link
Contributor

/ok-to-test

@k8s-ci-robot k8s-ci-robot added ok-to-test Indicates a non-member PR verified by an org member that is safe to test. and removed needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. labels May 1, 2025
@ivankatliarchuk
Copy link
Contributor

For this to review

  • shared how it was tested with results
  • share kubernetes manifests so that we could validate that as well

Copy link
Contributor

@ivankatliarchuk ivankatliarchuk left a 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"
Copy link
Contributor

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

Copy link
Contributor Author

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

Copy link
Contributor

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

@@ -926,6 +961,39 @@ func (p *AWSProvider) newChange(action route53types.ChangeAction, ep *endpoint.E
if useGeolocation {
change.ResourceRecordSet.GeoLocation = geolocation
}

geoproximity := &route53types.GeoProximityLocation{}
Copy link
Contributor

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?

Copy link
Contributor Author

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.

Copy link
Contributor

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

@prasadkatti
Copy link
Contributor Author

@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 make cover-html and that shows me that I have added good coverage for the lines I added. I don't know how to share that with you.

Copy link
Contributor

@ivankatliarchuk ivankatliarchuk left a 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

}
useGeoproximity = true
} else {
log.Errorf("Invalid coordinates format for %s: %s; expected format 'latitude,longitude'", providerSpecificGeoProximityLocationCoordinates, prop)
Copy link
Contributor

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

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I feel an Errorf here is okay, because the user is going to expect e-dns to create those records but it won't. That object with the invalid coordinates is just going to fail to reconcile.
We are also using an Errorf here even when the record will get created.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Warning please, we will correct this in follow up if needed

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure if I agree with the coding style, where methods with same prefix with* have different return types bool,none and have side effects with logging errors.

If there is an error, so we most likely do need to return an error, as we have concepts of soft erorrs as well, and we capture them in metrics

@k8s-ci-robot k8s-ci-robot added the provider Issues or PRs related to a provider label Jun 2, 2025
@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by:
Once this PR has been reviewed and has the lgtm label, please ask for approval from ivankatliarchuk. For more information see the Code Review Process.

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 /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@ivankatliarchuk
Copy link
Contributor

Any chance you share here a result of a smoke test? With geoproximity and without geoproximity settings, share relevant kube manifests as well pls. Does it require AWS IAM specific actions?

Docs needs updating as well https://github.com/kubernetes-sigs/external-dns/blob/master/docs/tutorials/aws.md

@ivankatliarchuk
Copy link
Contributor

/label tide/merge-method-squash

@k8s-ci-robot k8s-ci-robot added the tide/merge-method-squash Denotes a PR that should be squashed by tide when it merges. label Jun 3, 2025
@prasadkatti
Copy link
Contributor Author

New changes -

  • updated the docs by adding the new annotations for geoproximity
  • added some more tests. The code coverage should be pretty good for the code that was updated.

Does it require AWS IAM specific actions?

No. It doesn't. It's just the same actions except the routing policy will be different.

Any chance you share here a result of a smoke test? With geoproximity and without geoproximity settings, share relevant kube manifests as well pls.

I have shared a manifest that I have been using for testing in the PR description. Let me know if that doesn't work for some reason. Here is a screenshot of the records that get added for those services in that manifest.
CleanShot 2025-06-09 at 01 24 31

Let me know if you need anything else from me at this point. Thanks so much for all your help so far @ivankatliarchuk !

@ivankatliarchuk
Copy link
Contributor

Nice one. Any chance you fix linter before we do a review?

Copy link
Contributor

@ivankatliarchuk ivankatliarchuk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Found few areas that require code coverage as well
Screenshot 2025-06-09 at 11 30 12
Screenshot 2025-06-09 at 11 30 21

}
useGeoproximity = true
} else {
log.Errorf("Invalid coordinates format for %s: %s; expected format 'latitude,longitude'", providerSpecificGeoProximityLocationCoordinates, prop)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Warning please, we will correct this in follow up if needed

return nil
}

func withGeoProximityCoordinates(ep *endpoint.Endpoint, geoproximity *route53types.GeoProximityLocation) bool {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This and similar methods contains too much of the side effects, return boolean, update endpoint and etc, etc.

Can we do it in more object oriented way, something like

type geoProximity {
  loc   *route53types.GeoProximityLocation
  ep.   *endpoint.Endpoint
  isSet bool
}

func (gp *geoproximity) withX() 
func (gp *geoproximity) withY() 
func (gp *geoproximity) withZ() 

and in the method

func withGeoProximityCoordinates ...
      ....
     change.ResourceRecordSet.GeoProximityLocation = geoProximity.build()

And add tests per each method for the private type geoProximity

This should simply operational support for us

}
useGeoproximity = true
} else {
log.Errorf("Invalid coordinates format for %s: %s; expected format 'latitude,longitude'", providerSpecificGeoProximityLocationCoordinates, prop)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure if I agree with the coding style, where methods with same prefix with* have different return types bool,none and have side effects with logging errors.

If there is an error, so we most likely do need to return an error, as we have concepts of soft erorrs as well, and we capture them in metrics

This commit addresses the review feedback by making the following changes:

- use a more object-oriented approach for geoProximity handling
- change log levels to warnings instead of errors
- add more test cases for geoProximity
@k8s-ci-robot k8s-ci-robot added size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. and removed size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Jun 27, 2025
@prasadkatti
Copy link
Contributor Author

New changes since last review:

  • used a more object oriented approach for handling geoproximity. Created a new private type for it.
  • used early return to reduce nesting
  • removed usage of magic numbers
  • updated log levels to warnings as suggested
  • added more tests to ensure good code coverage

This is ready for another review. Thanks!

Copy link
Contributor

@ivankatliarchuk ivankatliarchuk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/lgtm

cc: @mloiseleur

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Jun 27, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. docs lgtm "Looks good to me", indicates that a PR is ready to be merged. ok-to-test Indicates a non-member PR verified by an org member that is safe to test. provider Issues or PRs related to a provider size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. tide/merge-method-squash Denotes a PR that should be squashed by tide when it merges.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add support for Geoproximity routing in AWS Route 53 provider
3 participants