-
Notifications
You must be signed in to change notification settings - Fork 2.6k
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
[TXT Registry] Fix handling of records produced by toNewTXTName
in toEndpoint
#3724
[TXT Registry] Fix handling of records produced by toNewTXTName
in toEndpoint
#3724
Conversation
toNewTXTName
function in toEndpoint
toNewTXTName
function in toEndpoint
toNewTXTName
in toEndpoint
/ok-to-test |
@mloiseleur can you review this one? ty |
fe02767
to
0f14da0
Compare
@szuecs I'll check it this week. |
ac75b88
to
74be95a
Compare
Thank you both for looking at this! As soon as this is merged it should also enable: #3735 |
It is unfortunate that this is as overengineered as it is. It is far more configurable than it needs to be and this leads to bugs such as the handling of |
Co-authored-by: John Gardiner Myers <jgmyers@proofpoint.com>
… into fix/to-endpoint-name
It is currently the only option when working with APEX cname records, as mentioned here: #449 |
That would be solved with |
It wouldn't as the record type gets prepended to the hostname not the affix. Lines 432 to 434 in bd8658e
|
The record type demonstrably gets prepended to the prefix. |
@johngmyers I would love to see that demonstration. Running just now against the func TestToNewTXTName(t *testing.T) {
tests := []struct {
name string
pr affixNameMapper
endpointDNSName string
recordType string
expectedNewTXTName string
}{
{
name: "Test 1",
pr: affixNameMapper{
prefix: "prefix",
suffix: "",
},
endpointDNSName: "example.com",
recordType: "A",
expectedNewTXTName: "prefixa-example.com",
},
{
name: "Test 2",
pr: affixNameMapper{
prefix: "prefix.",
suffix: "",
},
endpointDNSName: "test.example.com",
recordType: "A",
expectedNewTXTName: "prefix.a-test.example.com",
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
result := tt.pr.toNewTXTName(tt.endpointDNSName, tt.recordType)
assert.Equal(t, tt.expectedNewTXTName, result)
})
}
}
|
@Sewci0 would you be able to address my review comments? |
Hi @johngmyers, sorry it took me so long. I've been pretty busy. Thank you for your comments, I implemented all of your suggestions. Let me know your thoughts! |
e76c681
to
1ffcc5d
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for fixing this!
/lgtm
/assign @szuecs
@@ -35,6 +34,12 @@ const ( | |||
providerSpecificForceUpdate = "txt/force-update" | |||
) | |||
|
|||
type endpointKey struct { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not use endpoint.EndpointKey
instead of redefining?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's no such thing. Did you mean endpoint.Endpoint
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
func (pr affixNameMapper) dropAffix(name string) string { | ||
// dropAffixExtractType strips TXT record to find an endpoint name it manages | ||
// it also returns the record type | ||
func (pr affixNameMapper) dropAffixExtractType(name string) (baseName, recordType string) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is no use of named return values, so we can also just do:
(baseName, recordType string)
-> (string, string)
If there is a blank return then we would return "",""
in the current version
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The problem with (string, string)
is it makes it difficult to know what the strings contain. The names convey the semantics.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This could be also a comment instead of named return values, which actually define variables in scope of the func.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Named return values work better with IDEs than comments do.
@@ -371,20 +396,24 @@ func (pr affixNameMapper) isSuffix() bool { | |||
return len(pr.prefix) == 0 && len(pr.suffix) > 0 | |||
} | |||
|
|||
func (pr affixNameMapper) toEndpointName(txtDNSName string) (endpointName string, isAAAA bool) { | |||
lowerDNSName, recordType := extractRecordType(strings.ToLower(txtDNSName)) | |||
func (pr affixNameMapper) toEndpointName(txtDNSName string) (endpointName string, recordType string) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same as in https://github.com/kubernetes-sigs/external-dns/pull/3724/files#r1290447277 , I would be in favor of dropping the "named return" in case we do not use it.
@johngmyers from my side we can merge as I only have some nitpicks that we could address ourselves. As you added lgtm, I guess we are good to go. /approve |
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: johngmyers, Sewci0, szuecs The full list of commands accepted by this bot can be found here. The pull request process is described here
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
hmm 2 jobs |
/retest |
@mloiseleur: The
Use 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/test-infra repository. |
/retest |
There was an issue, which got fixed by this PR: #3031 |
The current implementation of the
toEndpoint
function is unable to handle records generated by thetoNewTXTName
function. As a result, domains created with a prefix such as%{record_type}foo.
are not deleted after the associated CRD is removed.This PR addresses this issue by improving the handling of records produced by the
toNewTXTName
function in thetoEndpoint
function. Additionally, it covers edge cases related to dashes or dots in the affix. A new test,TestToEndpointNameNewTXT
, has been added to ensure the proper conversion between the output oftoNewTXTName
and its input using thetoEndpoint
function.Additionally, this PR fixes the
testTXTRegistryRecordsPrefixed
test, which previously operated under the incorrect assumption that the output oftoNewTXTName
with the prefixtxt.
fordualstack.test-zone.example.org
would beaaaa-txt.dualstack.test-zone.example.org
. In reality when not using a templated record type, the type will be prepended to the domain rather than the affix.Here are the results of the new test before the change:
Potentially fixes: #3007 #3186
Checklist