From 7fa568872c26d78269c7ad36e0ac3a802d349b00 Mon Sep 17 00:00:00 2001 From: Tom Wilkie Date: Tue, 11 Aug 2015 10:57:28 +0000 Subject: [PATCH 1/2] Ensure we delete the fqdn is the container fails to start. --- nameserver/http.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/nameserver/http.go b/nameserver/http.go index 7b3eb352d9..66d4e11276 100644 --- a/nameserver/http.go +++ b/nameserver/http.go @@ -27,7 +27,7 @@ func (n *Nameserver) HandleHTTP(router *mux.Router) { vars = mux.Vars(r) container = vars["container"] ipStr = vars["ip"] - hostname = r.FormValue("fqdn") + hostname = dns.Fqdn(r.FormValue("fqdn")) ip, err = address.ParseIP(ipStr) ) if err != nil { @@ -35,7 +35,7 @@ func (n *Nameserver) HandleHTTP(router *mux.Router) { 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)) return } From 6a5044fc70e955b758f1f96b7393aeb7c5c995c9 Mon Sep 17 00:00:00 2001 From: Tom Wilkie Date: Tue, 11 Aug 2015 10:58:42 +0000 Subject: [PATCH 2/2] Make nameserver logging more consistent. --- nameserver/http.go | 19 +++++++++---------- nameserver/nameserver.go | 2 ++ 2 files changed, 11 insertions(+), 10 deletions(-) diff --git a/nameserver/http.go b/nameserver/http.go index 66d4e11276..771a1e234e 100644 --- a/nameserver/http.go +++ b/nameserver/http.go @@ -8,13 +8,12 @@ import ( "github.com/gorilla/mux" "github.com/miekg/dns" - "github.com/weaveworks/weave/common" "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) - common.Log.Warningf("[gossipdns]: %v", err) + n.infof("%v", err) } func (n *Nameserver) HandleHTTP(router *mux.Router) { @@ -31,19 +30,19 @@ func (n *Nameserver) HandleHTTP(router *mux.Router) { ip, err = address.ParseIP(ipStr) ) if err != nil { - badRequest(w, err) + n.badRequest(w, err) return } 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 } 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 { - 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"] ip, err := address.ParseIP(ipStr) if ok && err != nil { - badRequest(w, err) + n.badRequest(w, err) return } else if !ok { ipStr = "*" } 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 } w.WriteHeader(204) @@ -88,7 +87,7 @@ func (n *Nameserver) HandleHTTP(router *mux.Router) { n.RLock() defer n.RUnlock() 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)) } }) } diff --git a/nameserver/nameserver.go b/nameserver/nameserver.go index 1827df95cf..4bc434ce1d 100644 --- a/nameserver/nameserver.go +++ b/nameserver/nameserver.go @@ -170,6 +170,8 @@ func (n *Nameserver) Delete(hostname, containerid, ipStr string, ip address.Addr if ipStr != "*" && e.Addr != ip { return false } + + n.infof("tombstoning entry %v", e) return true }) n.Unlock()