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 18617256505

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.
  • 93 unchanged lines in 6 files lost coverage.
  • Overall coverage increased (+0.05%) to 78.603%

Files with Coverage Reduction New Missed Lines %
openshift_route.go 1 79.49%
apis/externaldns/types.go 1 99.71%
execute.go 3 61.28%
zz_generated.deepcopy.go 11 0.0%
endpoint.go 12 90.42%
cloudflare/cloudflare.go 65 90.93%
Totals Coverage Status
Change from base Build 18242454154: 0.05%
Covered Lines: 15866
Relevant Lines: 20185

💛 - 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 ?

@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?

}

// TestZoneIDByName tests the ZoneIDByName function
func TestZoneIDByName(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.

I think it's unrelated to this PR and add nothing to the current tests.
This test provider.Zones() which is already covered by TestCloudFlareZones*() tests.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah sorry I couldn't figure out how to rerun the tests and didn't want to do an empty commit. I'll remove it

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

5 participants