-
Notifications
You must be signed in to change notification settings - Fork 460
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
Fix external name not solving by reloading resolv.conf. #225
Conversation
/ok-to-test |
pkg/dns/dns.go
Outdated
kd.SkyDNSConfig.Nameservers = nameServers | ||
if len(nameServers) == 0 { | ||
kd.SkyDNSConfig.Nameservers = kd.loadDefaultNameserver() | ||
} |
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.
Seems like kd.SkyDNSConfig.Nameservers = nameServers
is still needed?
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.
Fixed..
Now skydns will be configured with resolv.conf when nameserver is empty.
pkg/dns/dns.go
Outdated
@@ -139,6 +140,19 @@ func NewKubeDNS(client clientset.Interface, clusterDomain string, timeout time.D | |||
return kd | |||
} | |||
|
|||
func (kd *KubeDNS) loadDefaultNameserver() []string { | |||
nameservers := []string{} | |||
if c, err := dns.ClientConfigFromFile("/etc/resolv.conf"); !os.IsNotExist(err) { |
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.
How is not exist
different from parse error
in this case? I think we should return empty array in both cases (feel like there are some redundant logic)?
Can we log if ClientConfigFromFile
returns error?
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.
Logged using verbose level 1.
pkg/dns/dns.go
Outdated
} | ||
return nameservers | ||
} | ||
|
||
func (kd *KubeDNS) updateConfig(nextConfig *config.Config) { |
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.
Is it possible to add a unit test for updating nameservers?
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.
Unit test for updateConfig added.
Keep @bowei in the loop. |
4834ebb
to
bf3f6e8
Compare
Done. Unit test added. PTAL thx |
pkg/dns/dns.go
Outdated
nameservers = append(nameservers, net.JoinHostPort(s, c.Port)) | ||
} | ||
} else { | ||
glog.V(1).Infof("Load nameserver from resolv.conf failed: %v", err) |
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.
We should use glog.Errorf() here. Can we move the error case up and early return?
if c, err := dns.ClientConfigFromFile(defaultResolvFile); err != nil {
// log error
return
}
// do the rest
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.
Done.
pkg/dns/dns.go
Outdated
@@ -148,12 +164,20 @@ func (kd *KubeDNS) updateConfig(nextConfig *config.Config) { | |||
for _, nameServer := range nextConfig.UpstreamNameservers { | |||
if ip, port, err := util.ValidateNameserverIpAndPort(nameServer); err != nil { | |||
glog.V(1).Infof("Invalid nameserver %q: %v", nameServer, err) |
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.
glog.Errorf()?
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.
Done.
Now skyDNS nameservers will fall back to resolv.conf whenever it's empty.
if c, err := dns.ClientConfigFromFile(defaultResolvFile); err != nil { | ||
glog.Errorf("Load nameserver from resolv.conf failed: %v", err) | ||
return []string{} | ||
} else { |
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 else block seems unnecessary.
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.
I see, we are using thec
.
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.
No worries, let keep this as is.
pkg/dns/dns.go
Outdated
glog.Errorf("Invalid nameserver %q: %v", nameServer, err) | ||
if len(kd.SkyDNSConfig.Nameservers) == 0 { | ||
// Fall back to resolv.conf on initialization failed. | ||
kd.SkyDNSConfig.Nameservers = kd.loadDefaultNameserver() |
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.
I think we should fall through here --- append whatever valid nameservers are passed in, and reuse the 0 length detection logic below:
if ip, port, err := util.ValidateNameserverIpAndPort(nameServer); err != nil {
glog.Errorf("Invalid nameserver %q: %v", nameServer, err)
} else {
nameServers = append(nameServers, net.JoinHostPort(ip, port))
}
...
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 idea is, we don't want to pollute kd.config with invalid input. (But the truth is, kd.config.UpstreamNameservers are never used so it's okay to be polluted)
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.
Sounds good, though having duplicated logic here seems bad. What about:
if kd.SkyDNSConfig != nil {
var nameServers []string
for _, nameServer := range nextConfig.UpstreamNameservers {
if ip, port, err := util.ValidateNameserverIpAndPort(nameServer); err != nil {
glog.Errorf("Invalid nameserver %q: %v", nameServer, err)
// Don't populate nameServers if invalid input is detected.
nameServers = []string{}
break
} else {
nameServers = append(nameServers, net.JoinHostPort(ip, port))
}
}
if len(nameServers) == 0 {
...
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.
Sorry what I wrote is wrong. I got what you were saying.
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.
But we can still do the partially update and leave kd.config untouched. Do you want me to do that?
I am kind of against this since kd.SkyDNSConfig is partially updated and kd.config is not which might be confusing in some extreme cases.
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.
I am kind of against this since kd.SkyDNSConfig is partially updated and kd.config is not which might be confusing in some extreme cases.
Agreed, that sounds bad. Let's keep this.
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.
/lgtm
pkg/dns/dns.go
Outdated
glog.V(1).Infof("Invalid nameserver %q: %v", nameServer, err) | ||
glog.Errorf("Invalid nameserver %q: %v", nameServer, err) | ||
if len(kd.SkyDNSConfig.Nameservers) == 0 { | ||
// Fall back to resolv.conf on initialization failed. |
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.
nit: initialization failed -> initialization failure
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.
Fixed.
pkg/dns/dns.go
Outdated
glog.Errorf("Invalid nameserver %q: %v", nameServer, err) | ||
if len(kd.SkyDNSConfig.Nameservers) == 0 { | ||
// Fall back to resolv.conf on initialization failed. | ||
kd.SkyDNSConfig.Nameservers = kd.loadDefaultNameserver() |
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.
I am kind of against this since kd.SkyDNSConfig is partially updated and kd.config is not which might be confusing in some extreme cases.
Agreed, that sounds bad. Let's keep this.
Thanks for review! |
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.
/lgtm
Will merge this once travis passes. |
Now skydns will be configured with resolv.conf when nameserver is empty.
Fixes#224 (#224)
\assign @MrHohn