Skip to content

Conversation

@AndrewCharlesHay
Copy link
Contributor

@AndrewCharlesHay AndrewCharlesHay commented Oct 6, 2025

What does it do ?

Migrate customhostname to v5

Motivation

Closes #5540

More

  • Yes, this PR title follows Conventional Commits
  • Yes, I added unit tests
  • Yes, I updated end user documentation accordingly

@k8s-ci-robot k8s-ci-robot added the cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. label Oct 6, 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 k8s-ci-robot added the provider Issues or PRs related to a provider label Oct 6, 2025
@k8s-ci-robot k8s-ci-robot requested a review from szuecs October 6, 2025 21:49
@k8s-ci-robot k8s-ci-robot added the size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. label Oct 6, 2025
@coveralls
Copy link

coveralls commented Oct 6, 2025

Pull Request Test Coverage Report for Build 18786857940

Warning: This coverage report may be inaccurate.

This pull request's base commit is no longer the HEAD commit of its target branch. This means it includes changes from outside the original pull request, including, potentially, unrelated coverage changes.

Details

  • 0 of 0 changed or added relevant lines in 0 files are covered.
  • 111 unchanged lines in 7 files lost coverage.
  • Overall coverage increased (+0.1%) to 78.695%

Files with Coverage Reduction New Missed Lines %
apis/externaldns/types.go 1 99.71%
execute.go 3 64.89%
txt.go 10 95.28%
zz_generated.deepcopy.go 11 0.0%
endpoint.go 12 90.42%
coredns/coredns.go 13 92.25%
cloudflare/cloudflare.go 61 91.17%
Totals Coverage Status
Change from base Build 18242454154: 0.1%
Covered Lines: 15883
Relevant Lines: 20183

💛 - Coveralls

Moved all tests from cloudflare_customhostname_test.go into cloudflare_test.go
to ensure proper coverage tracking by coveralls. Tests maintain 92.4% coverage.
@AndrewCharlesHay AndrewCharlesHay changed the title Andrewcharleshay/cloudflare migration v5 chore(cloudflare): migrate customhostname to v5 Oct 7, 2025
Co-authored-by: Michel Loiseleur <[email protected]>
@mloiseleur
Copy link
Collaborator

@vflaux @mrozentsvayg Any comment on this PR ? Do you think you can review it ?

Comment on lines 369 to 371
if strings.Contains(errStr, "exceeded available rate limit retries") ||
strings.Contains(errStr, "rate limit") ||
strings.Contains(errStr, "429") {
Copy link
Contributor

Choose a reason for hiding this comment

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

I think we should handle this according to the doc here: https://github.com/cloudflare/cloudflare-go?tab=readme-ov-file#errors

    var apierr *cloudflare.Error
	if errors.As(err, &apierr) {
		if apierr.StatusCode == http.StatusTooManyRequests {
		}
	}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This was implemented

Copy link
Contributor

@szuecs szuecs Oct 24, 2025

Choose a reason for hiding this comment

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

so why do we have this code here?

  1. Rate limit errors are not returned as ErrorTypeRateLimit cloudflare/cloudflare-go#4155 talks about the v0 version of the library which we don't use after merging your PR.
  2. the first string.Contains is not needed if you have the second one.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sorry forgot to commit it. It's gone now

@k8s-ci-robot
Copy link
Contributor

@vflaux: changing LGTM is restricted to collaborators

In response to this:

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.

AndrewCharlesHay and others added 6 commits October 9, 2025 20:58
Co-authored-by: vflaux <[email protected]>
…Flare API

- Change CustomHostnames method signature to return autoPager[CustomHostnameListResponse]
  instead of processed []CustomHostname for better API matching and testability
- Keep listAllCustomHostnames helper function for callers that need processed results
- Update mock implementation to return autoPager with realistic CloudFlare API behavior
- All tests continue to pass with improved interface design

Addresses PR feedback about method signatures being closer to CloudFlare API for better mocking.
- Handle CloudFlare v5 SDK errors according to official documentation
- Use errors.As() to check for cloudflare.Error type
- Convert 429 (rate limit) status codes to SoftError for retry logic
- Add comprehensive test coverage for v5 error handling
- Use wrapper types in tests to avoid CloudFlare SDK internal nil pointer issues

Addresses PR comment on line 376 requesting proper v5 error handling.
@AndrewCharlesHay
Copy link
Contributor Author

How did broken tests get merged in?

@vflaux
Copy link
Contributor

vflaux commented Oct 13, 2025

How did broken tests get merged in?

This should be fixed, see #5896.

@AndrewCharlesHay
Copy link
Contributor Author

/retest

@AndrewCharlesHay
Copy link
Contributor Author

@vflaux everything look good now?

Copy link
Contributor

@vflaux vflaux left a comment

Choose a reason for hiding this comment

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

I've not review all the new tests yet.
Looks like IA generated, some clearly improve test coverage, others seems less relevant. 😄

Comment on lines 428 to 430
if client == nil {
return nil, fmt.Errorf("failed to initialize cloudflare provider")
}
Copy link
Contributor

Choose a reason for hiding this comment

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

I's unreachable, right?

Suggested change
if client == nil {
return nil, fmt.Errorf("failed to initialize cloudflare provider")
}

Comment on lines +232 to +261
func (z zoneService) CreateCustomHostname(ctx context.Context, zoneID string, ch CustomHostname) error {
params := custom_hostnames.CustomHostnameNewParams{
ZoneID: cloudflare.F(zoneID),
Hostname: cloudflare.F(ch.Hostname),
}

if ch.SSL != nil {
sslParams := custom_hostnames.CustomHostnameNewParamsSSL{}
if ch.SSL.Method != "" {
sslParams.Method = cloudflare.F(custom_hostnames.DCVMethod(ch.SSL.Method))
}
if ch.SSL.Type != "" {
sslParams.Type = cloudflare.F(custom_hostnames.DomainValidationType(ch.SSL.Type))
}
if ch.SSL.BundleMethod != "" {
sslParams.BundleMethod = cloudflare.F(custom_hostnames.BundleMethod(ch.SSL.BundleMethod))
}
if ch.SSL.CertificateAuthority != "" && ch.SSL.CertificateAuthority != "none" {
sslParams.CertificateAuthority = cloudflare.F(cloudflare.CertificateCA(ch.SSL.CertificateAuthority))
}
if ch.SSL.Settings.MinTLSVersion != "" {
sslParams.Settings = cloudflare.F(custom_hostnames.CustomHostnameNewParamsSSLSettings{
MinTLSVersion: cloudflare.F(custom_hostnames.CustomHostnameNewParamsSSLSettingsMinTLSVersion(ch.SSL.Settings.MinTLSVersion)),
})
}
params.SSL = cloudflare.F(sslParams)
}

_, err := z.service.CustomHostnames.New(ctx, params)
return err
Copy link
Contributor

Choose a reason for hiding this comment

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

Is it possible to do the same you've done with CustomHostnames() ?
Signature close to the cloudflare api & extract the build of CustomHostnameNewParams{} to another func + tests ?

})
}

func TestBuildCustomHostnameSSLParams(t *testing.T) {
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 what this is supposed to test 😄.
This doesn't call any function from this package.

Comment on lines 4191 to 4198
var foundID string
for _, h := range hostnames {
if h.Hostname == "test.example.com" {
foundID = h.ID
break
}
}
assert.Equal(t, "ch1", foundID)
Copy link
Contributor

Choose a reason for hiding this comment

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

No need to loop over the list as there is only one element.

Suggested change
var foundID string
for _, h := range hostnames {
if h.Hostname == "test.example.com" {
foundID = h.ID
break
}
}
assert.Equal(t, "ch1", foundID)
assert.Equal(t, "ch1", hostnames[0].ID)

}
})

t.Run("IteratorError", func(t *testing.T) {
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 case is very similar to the next one (PartialIteratorError). I'm not sure if this one is needed?

@AndrewCharlesHay
Copy link
Contributor Author

The tests just fail because of rate limits to coveralls

Hostname: cloudflare.F(ch.Hostname),
}

if ch.SSL != nil {
Copy link
Contributor

Choose a reason for hiding this comment

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

This smells like extract function refactoring. Put the whole branch in a function please

@szuecs
Copy link
Contributor

szuecs commented Oct 31, 2025

Did you @AndrewCharlesHay address comments by @vflaux ?

Cleaning up things that are not useful is always great for maintaining the software.

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 provider Issues or PRs related to a provider size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

cloudflare: bump library to v4

6 participants