-
Notifications
You must be signed in to change notification settings - Fork 693
Convert built-in hosts to unambiguous domain names #1104
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
Conversation
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.
Needs some changes we discussed in person
94bb788
to
c47eb28
Compare
Signed-off-by: Nino Kodabande <nkodabande@suse.com>
c47eb28
to
7c79a59
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.
Use dns.CanonicalName
instead of re-implementing it.
pkg/hostagent/dns/dns.go
Outdated
@@ -132,10 +131,11 @@ func NewHandler(opts HandlerOptions) (dns.Handler, error) { | |||
hostToIP: make(map[string]net.IP), | |||
} | |||
for host, address := range opts.StaticHosts { | |||
fqdn := cname(host) |
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.
fqdn := cname(host) | |
cname := dns.CanonicalName(host) |
pkg/hostagent/dns/dns.go
Outdated
if ip := net.ParseIP(address); ip != nil { | ||
h.hostToIP[host] = ip | ||
h.hostToIP[fqdn] = ip |
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.
h.hostToIP[fqdn] = ip | |
h.hostToIP[cname] = ip |
pkg/hostagent/dns/dns.go
Outdated
} else { | ||
h.cnameToHost[host] = limayaml.Cname(address) | ||
h.cnameToHost[fqdn] = cname(address) |
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.
h.cnameToHost[fqdn] = cname(address) | |
h.cnameToHost[cname] = dns.CanonicalName(address) |
pkg/hostagent/dns/dns.go
Outdated
|
||
func cname(host string) string { | ||
host = strings.ToLower(host) | ||
if !strings.HasSuffix(host, ".") { | ||
host += "." | ||
} | ||
return host | ||
} |
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 cname(host string) string { | |
host = strings.ToLower(host) | |
if !strings.HasSuffix(host, ".") { | |
host += "." | |
} | |
return host | |
} |
7c79a59
to
d34b86e
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.
Please leave the tests in pkg/limayaml/defaults_tests.go
. The names are no longer normalized to canonical names, but we still want to test the merging behaviour. So just adjust the expected values to match the original values without any modifications.
- Adds test cases for A records and Cnames - Move cname conversion out of yaml into dns package Signed-off-by: Nino Kodabande <nkodabande@suse.com>
d34b86e
to
e78d91d
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.
Thank you!
This change ensures that user-defined host names are converted correctly to unambiguous domain names. Regardless if the user declares them as fully qualified or not we always convert them to fully qualified.
Addresses: rancher-sandbox/rancher-desktop#3163
Signed-off-by: Nino Kodabande nkodabande@suse.com