Merge pull request #1282 from weaveworks/1281-dns-remove-dead-quick
Remove DNS entries for dead containers when adding correctly. Fixes #1281.
This commit is contained in:
commit
f1b9cf4fc0
2 files changed
+13
-12
No files matched your search
+11
-12
@@ -8,13 +8,12 @@ import (
|
|||||||
"github.com/gorilla/mux"
|
"github.com/gorilla/mux"
|
||||||
"github.com/miekg/dns"
|
"github.com/miekg/dns"
|
||||||
|
|
||||||
"github.com/weaveworks/weave/common"
|
|
||||||
"github.com/weaveworks/weave/net/address"
|
"github.com/weaveworks/weave/net/address"
|
||||||
)
|
)
|
||||||
|
|
||||||
func badRequest(w http.ResponseWriter, err error) {
|
func (n *Nameserver) badRequest(w http.ResponseWriter, err error) {
|
||||||
http.Error(w, err.Error(), http.StatusBadRequest)
|
http.Error(w, err.Error(), http.StatusBadRequest)
|
||||||
common.Log.Warningf("[gossipdns]: %v", err)
|
n.infof("%v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (n *Nameserver) HandleHTTP(router *mux.Router) {
|
func (n *Nameserver) HandleHTTP(router *mux.Router) {
|
||||||
@@ -27,23 +26,23 @@ func (n *Nameserver) HandleHTTP(router *mux.Router) {
|
|||||||
vars = mux.Vars(r)
|
vars = mux.Vars(r)
|
||||||
container = vars["container"]
|
container = vars["container"]
|
||||||
ipStr = vars["ip"]
|
ipStr = vars["ip"]
|
||||||
hostname = r.FormValue("fqdn")
|
hostname = dns.Fqdn(r.FormValue("fqdn"))
|
||||||
ip, err = address.ParseIP(ipStr)
|
ip, err = address.ParseIP(ipStr)
|
||||||
)
|
)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
badRequest(w, err)
|
n.badRequest(w, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := n.AddEntry(dns.Fqdn(hostname), container, n.ourName, ip); err != nil {
|
if err := n.AddEntry(hostname, container, n.ourName, ip); err != nil {
|
||||||
badRequest(w, fmt.Errorf("Unable to add entry: %v", err))
|
n.badRequest(w, fmt.Errorf("Unable to add entry: %v", err))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if r.FormValue("check-alive") == "true" && n.docker.IsContainerNotRunning(container) {
|
if r.FormValue("check-alive") == "true" && n.docker.IsContainerNotRunning(container) {
|
||||||
common.Log.Infof("[gossipdns] '%s' is not running: removing", container)
|
n.infof("container '%s' is not running: removing", container)
|
||||||
if err := n.Delete(hostname, container, ipStr, ip); err != nil {
|
if err := n.Delete(hostname, container, ipStr, ip); err != nil {
|
||||||
common.Log.Infof("[gossipdns] failed to remove: %v", err)
|
n.infof("failed to remove: %v", err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -68,14 +67,14 @@ func (n *Nameserver) HandleHTTP(router *mux.Router) {
|
|||||||
ipStr, ok := vars["ip"]
|
ipStr, ok := vars["ip"]
|
||||||
ip, err := address.ParseIP(ipStr)
|
ip, err := address.ParseIP(ipStr)
|
||||||
if ok && err != nil {
|
if ok && err != nil {
|
||||||
badRequest(w, err)
|
n.badRequest(w, err)
|
||||||
return
|
return
|
||||||
} else if !ok {
|
} else if !ok {
|
||||||
ipStr = "*"
|
ipStr = "*"
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := n.Delete(hostname, container, ipStr, ip); err != nil {
|
if err := n.Delete(hostname, container, ipStr, ip); err != nil {
|
||||||
badRequest(w, fmt.Errorf("Unable to delete entries: %v", err))
|
n.badRequest(w, fmt.Errorf("Unable to delete entries: %v", err))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
w.WriteHeader(204)
|
w.WriteHeader(204)
|
||||||
@@ -88,7 +87,7 @@ func (n *Nameserver) HandleHTTP(router *mux.Router) {
|
|||||||
n.RLock()
|
n.RLock()
|
||||||
defer n.RUnlock()
|
defer n.RUnlock()
|
||||||
if err := json.NewEncoder(w).Encode(n.entries); err != nil {
|
if err := json.NewEncoder(w).Encode(n.entries); err != nil {
|
||||||
badRequest(w, fmt.Errorf("Error marshalling response: %v", err))
|
n.badRequest(w, fmt.Errorf("Error marshalling response: %v", err))
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@@ -170,6 +170,8 @@ func (n *Nameserver) Delete(hostname, containerid, ipStr string, ip address.Addr
|
|||||||
if ipStr != "*" && e.Addr != ip {
|
if ipStr != "*" && e.Addr != ip {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
n.infof("tombstoning entry %v", e)
|
||||||
return true
|
return true
|
||||||
})
|
})
|
||||||
n.Unlock()
|
n.Unlock()
|
||||||
|
|||||||
Reference in new issue
Block a user