Register container name and its network aliases with weaveDNS

This commit is contained in:
Konstantin Suvorov committed 2020-07-14 18:15:37 +03:00
1 parent 1ff09fd4d1
commit fa5e032e49
1 file changed
+9 -1
+9 -1
View File
@@ -39,10 +39,18 @@ func (w *watcher) ContainerStarted(id string) {
if network.isOurs { if network.isOurs {
if w.driver.dns { if w.driver.dns {
fqdn := fmt.Sprintf("%s.%s", info.Config.Hostname, info.Config.Domainname) fqdn := fmt.Sprintf("%s.%s", info.Config.Hostname, info.Config.Domainname)
if err := w.weave.RegisterWithDNS(id, fqdn, net.IPAddress); err != nil { weaveDomain, _ := w.weave.DNSDomain()
// Container name is prefixed with '/' so we cut first character
name := fmt.Sprintf("%s.%s", info.Name[1:], weaveDomain)
aliases := append([]string(nil), fqdn, name)
aliases = append(aliases, net.Aliases...)
for _, alias := range aliases {
w.driver.debug("ContainerStarted", "going to register %s with weaveDNS", alias)
if err := w.weave.RegisterWithDNS(id, alias, net.IPAddress); err != nil {
w.driver.warn("ContainerStarted", "unable to register %s with weaveDNS: %s", id, err) w.driver.warn("ContainerStarted", "unable to register %s with weaveDNS: %s", id, err)
} }
} }
}
netNSPath := weavenet.NSPathByPidWithProc(w.driver.procPath, info.State.Pid) netNSPath := weavenet.NSPathByPidWithProc(w.driver.procPath, info.State.Pid)
if err := weavenet.WithNetNSByPath(netNSPath, func() error { if err := weavenet.WithNetNSByPath(netNSPath, func() error {
return weavenet.ConfigureARP(weavenet.VethName, w.driver.procPath) return weavenet.ConfigureARP(weavenet.VethName, w.driver.procPath)