Skip to content

feat(cloudflare): add support for MX records #5283

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 13 commits into
base: master
Choose a base branch
from

Conversation

arthlr
Copy link
Contributor

@arthlr arthlr commented Apr 13, 2025

Hi there! 👋

Description

This PR introduces support for MX records for the Cloudflare provider.

  • Cloudflare can now manage MX records via the DNSEndpoint CRD.
  • Adds logic to parse MX records and extract priority and mail host
  • Extends unit tests to validate proper MX record creation and priority
  • Updates the documentation to reflect support for cloudflare in MX record management.

Fixes #5282

Checklist

  • Unit tests updated
  • End user documentation updated (docs/sources/mx-record.md)

Thanks for checking this out! 🙏
Looking forward to your feedback — happy to make any changes if needed.

@k8s-ci-robot k8s-ci-robot added the cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. label Apr 13, 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 assign szuecs for approval. 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

@k8s-ci-robot
Copy link
Contributor

Hi @arthlr. 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.

@k8s-ci-robot k8s-ci-robot added needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Apr 13, 2025
@mloiseleur
Copy link
Collaborator

/ok-to-test
@AndrewCharlesHay @mrozentsvayg do you think you can review this PR ?

@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 Apr 13, 2025
@arthlr arthlr force-pushed the feat/mx-record branch 2 times, most recently from 14185d5 to 4f51703 Compare April 13, 2025 19:08
@arthlr
Copy link
Contributor Author

arthlr commented Apr 13, 2025

/retest


priority := (*uint16)(nil)
if ep.RecordType == "MX" {
parsedPriority, mailHost, err := parseMXRecord(target)
Copy link
Contributor

Choose a reason for hiding this comment

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

There is already similar logic in endpoint.ValidateMXRecord()
I would suggest to deduplicate it.

Copy link
Contributor

Choose a reason for hiding this comment

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ok I will deduplicate then 👍

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 deduplicated the logic of endpoint.ValidateMXRecord() by changing a bit the logic and the return values. However, I have added tests to increase the cover of this part.

registry/txt.go Outdated
@@ -108,7 +108,7 @@ func NewTXTRegistry(provider provider.Provider, txtPrefix, txtSuffix, ownerID st
}

func getSupportedTypes() []string {
return []string{endpoint.RecordTypeA, endpoint.RecordTypeAAAA, endpoint.RecordTypeCNAME, endpoint.RecordTypeNS}
return []string{endpoint.RecordTypeA, endpoint.RecordTypeAAAA, endpoint.RecordTypeCNAME, endpoint.RecordTypeNS, endpoint.RecordTypeMX, endpoint.RecordTypeTXT}
Copy link
Contributor

Choose a reason for hiding this comment

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

Not sure about the idea to use txt registry for the txt records.
If it's not an integral part of the PR, i would postpone it until we better understand the txt registry roadmap, especially the part of deprecating old records.

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'll remove it then 👍
However, we'll need it one day (I would like to use MX and TXT records to automatically deploy sengrid-like DNS records)

Copy link
Contributor

Choose a reason for hiding this comment

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

using the TXT registry, specifically?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, I am not using AWS and still don't want a noop registry.
Then, a TXT registry, to store the metadata of TXT records created by external-dns is must-have for my team and I.

@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 Apr 16, 2025
@@ -801,7 +839,7 @@ func (p *CloudFlareProvider) newCustomHostname(customHostname string, origin str
}
}

func (p *CloudFlareProvider) newCloudFlareChange(action string, ep *endpoint.Endpoint, target string, current *endpoint.Endpoint) *cloudFlareChange {
func (p *CloudFlareProvider) newCloudFlareChange(action string, ep *endpoint.Endpoint, target string, current *endpoint.Endpoint) (*cloudFlareChange, error) {
Copy link
Contributor

Choose a reason for hiding this comment

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

why do we need to add error to the return values?
it's always nil, and this method is not intended to ever fail

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 think we should add an error, because the behavior of p.newCloudFlareChange changes. Since we're now parsing the MX record, there's a possibility that the parsing might fail. In such cases, we need to explicitly return that the change won't occur because the parsing didn't succeed.

@k8s-ci-robot k8s-ci-robot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Apr 26, 2025
@arthlr arthlr requested a review from mrozentsvayg April 30, 2025 12:01
@mloiseleur
Copy link
Collaborator

@mrozentsvayg anything left on your side ?
@AndrewCharlesHay any comments on this PR ?

@k8s-ci-robot k8s-ci-robot added docs provider and removed needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. labels May 30, 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 ok-to-test Indicates a non-member PR verified by an org member that is safe to test. provider size/XL Denotes a PR that changes 500-999 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Feat: support MX record for Cloudflare provider
6 participants