Skip to content
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

Support SRV record creation with cloudflare provider #4754

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

Conversation

starcraft66
Copy link

@starcraft66 starcraft66 commented Sep 17, 2024

Description

Implements SRV record creation when using the cloudflare provider. Cloudflare's API requires sending SRV record data in structured fields rather than a bare string with the record.

I'm not a Go developer and just did the bare minimum to get this working and tested, I've confirmed this works on my personal cluster. Feel free to suggest improvements.

Fixes #4751

Checklist

  • Unit tests updated
  • End user documentation updated

Copy link

linux-foundation-easycla bot commented Sep 17, 2024

CLA Signed

The committers listed above are authorized under a signed CLA.

@k8s-ci-robot
Copy link
Contributor

Welcome @starcraft66!

It looks like this is your first PR to kubernetes-sigs/external-dns 🎉. Please refer to our pull request process documentation to help your PR have a smooth ride to approval.

You will be prompted by a bot to use commands during the review process. Do not be afraid to follow the prompts! It is okay to experiment. Here is the bot commands documentation.

You can also check if kubernetes-sigs/external-dns has its own contribution guidelines.

You may want to refer to our testing guide if you run into trouble with your tests not passing.

If you are having difficulty getting your pull request seen, please follow the recommended escalation practices. Also, for tips and tricks in the contribution process you may want to read the Kubernetes contributor cheat sheet. We want to make sure your contribution gets all the attention it needs!

Thank you, and welcome to Kubernetes. 😃

@k8s-ci-robot
Copy link
Contributor

Hi @starcraft66. 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. cncf-cla: no Indicates the PR's author has not signed the CNCF CLA. size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. and removed cncf-cla: no Indicates the PR's author has not signed the CNCF CLA. labels Sep 17, 2024
@starcraft66 starcraft66 force-pushed the feature/tgh/cloudflare-srv-records branch 4 times, most recently from 78a12d5 to 5f828ae Compare September 17, 2024 21:43
@k8s-ci-robot k8s-ci-robot added size/L Denotes a PR that changes 100-499 lines, ignoring generated files. and removed size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. labels Sep 17, 2024
return nil, fmt.Errorf("invalid port in SRV record content: %s", parts[2])
}

target := parts[3]
Copy link
Contributor

Choose a reason for hiding this comment

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

Wdyt of checking IP format with ParseIP ?

Copy link
Author

@starcraft66 starcraft66 Sep 22, 2024

Choose a reason for hiding this comment

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

It wouldn't really make sense here afaik because the the target could be a hostname that would have to be resolved, so pretty much anything goes.

Copy link
Contributor

@mloiseleur mloiseleur left a comment

Choose a reason for hiding this comment

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

Thanks for this PR. Overall it looks good, and it's tested 👍.
Wdyt of updating documentation in order to show how to create a SRV record ?

@mloiseleur
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 Sep 18, 2024
@starcraft66
Copy link
Author

Just added documentation

# SRV record with CRD source

You can create and manage SRV records with the help of [CRD source](../contributing/crd-source.md)
and `DNSEndpoint` CRD. The implementation of this feature depends on provider API support, this feature is currently known to be supported supported by `akamai`, `civo`, `cloudflare`, `ibmcloud`, `linode`, `rfc2136` and `pdns` providers.
Copy link
Author

Choose a reason for hiding this comment

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

This might not be completely accurate but I can't test every provider, I just built this list by grepping for mentions of SRV in the providers folder and searching the issue tracker.

@starcraft66 starcraft66 requested a review from mloiseleur October 1, 2024 21:26
@mloiseleur
Copy link
Contributor

@starcraft66 Thanks for the documentation. See my comments for a first review of the code.

@kashalls
Copy link

@starcraft66 Do you need any help with this PR, glad to help if possible.

@starcraft66
Copy link
Author

I was going to take a look at this as soon as I have some time but haven't gotten to it yet.

Feel free to link some commits and I can push them to my branch, I love open source collaboration ☺️

@k8s-ci-robot k8s-ci-robot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Nov 1, 2024
@mloiseleur
Copy link
Contributor

mloiseleur commented Feb 20, 2025

It seems we can proceed with final review and merge for this one.

@starcraft66 Do you think you can address the last comments and rebase this PR ?

@starcraft66
Copy link
Author

Hey sorry, I was on vacation. Will rebase this asap.

@starcraft66 starcraft66 force-pushed the feature/tgh/cloudflare-srv-records branch from 8dd6fe6 to 7372d50 Compare February 27, 2025 01:23
@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 mloiseleur 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 k8s-ci-robot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Feb 27, 2025
@starcraft66
Copy link
Author

@mloiseleur ready for review

@ivankatliarchuk
Copy link
Contributor

Hi. Nice on, I'll do an initial review.

/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 Feb 27, 2025
In order to start managing MX records you need to set the `--managed-record-types SRV` flag.

```console
external-dns --source crd --provider {akamai|civo|cloudflare|ibmcloud|linode|rfc2136|pdns} --managed-record-types A --managed-record-types CNAME --managed-record-types SRV
Copy link
Contributor

Choose a reason for hiding this comment

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

are we sure all this providers support SRV?

- dnsName: _sip._udp.example.com
recordTTL: 180
recordType: SRV
targets:
Copy link
Contributor

Choose a reason for hiding this comment

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

Would it be possible to share smoke tests as well, could you please also provide a way to test this manually with manifests and kubectl commands? Similar to this example #5111 (comment)

for cloudflare is enough, I'll do for aws or google?

I'm unsure where or not multiple targets supported, never tried that case.

}

if cfc.ResourceRecord.Type == "SRV" {
Copy link
Contributor

Choose a reason for hiding this comment

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

this seems identical to cloudflare.CreateDNSRecordParams. Shell we create a shared method?

Copy link
Contributor

Choose a reason for hiding this comment

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

New lines added, not covered with unit tests
Screenshot 2025-02-27 at 07 18 54

}

// parseSRVContent parses the SRV record content string into the structured data required by the Cloudflare API
func parseSRVContent(content string) (map[string]interface{}, error) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Error cases not covered, could we add unit-test coverege for them? We are aiming to increase test-coverage

Screenshot 2025-02-27 at 07 21 33


target := parts[3]

return map[string]interface{}{
Copy link
Contributor

Choose a reason for hiding this comment

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

Could we have a struct instead?

if endpoint.RecordType == "SRV" {
srvData, err := parseSRVContent(target)
if err != nil {
log.Errorf("Error parsing SRV content: %v", err)
Copy link
Contributor

Choose a reason for hiding this comment

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

error case not covered
Screenshot 2025-02-27 at 07 24 57

@@ -707,7 +765,19 @@ func groupByNameAndTypeWithCustomHostnames(records []cloudflare.DNSRecord, chs [
}
targets := make([]string, len(records))
for i, record := range records {
targets[i] = record.Content
if record.Type == "SRV" {
if dataMap, ok := record.Data.(map[string]interface{}); ok {
Copy link
Contributor

Choose a reason for hiding this comment

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

Not covered with tests
Screenshot 2025-02-27 at 07 25 23

targets[i] = record.Content
if record.Type == "SRV" {
if dataMap, ok := record.Data.(map[string]interface{}); ok {
priority, _ := dataMap["priority"].(float64)
Copy link
Contributor

Choose a reason for hiding this comment

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

same apply, could we have a concrete struct, so we do not need to cast?

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. ok-to-test Indicates a non-member PR verified by an org member that is safe to test. size/L Denotes a PR that changes 100-499 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.

SRV records cannot be created by the cloudflare provider
5 participants