stop weavedns from complaining when a container has no docker ip
e.g. when it was started with --net=none weavedns wasn't actually using the docker-assigned ip for anything, so this change is a simple matter of eradicating it from the code.
This commit is contained in:
1 parent
65c77df279
commit
24702e3a7a
5 files changed
+14
-27
No files matched your search
+3
-10
@@ -47,18 +47,11 @@ func ListenHttp(domain string, db Zone, port int) {
|
||||
case "PUT":
|
||||
ident, weaveIPstr, err := parseUrl(r.URL.Path)
|
||||
name := r.FormValue("fqdn")
|
||||
localIPstr := r.FormValue("local_ip")
|
||||
if ident == "" || weaveIPstr == "" || name == "" || localIPstr == "" {
|
||||
if ident == "" || weaveIPstr == "" || name == "" {
|
||||
reqError("Invalid request", "Invalid request: %s, %s", r.URL, r.Form)
|
||||
return
|
||||
}
|
||||
|
||||
localIP := net.ParseIP(localIPstr)
|
||||
if localIP == nil {
|
||||
reqError("Invalid IP in request", "Invalid IP in request: %s", localIPstr)
|
||||
return
|
||||
}
|
||||
|
||||
weaveIP := net.ParseIP(weaveIPstr)
|
||||
if weaveIP == nil {
|
||||
reqError("Invalid weave IP", "Invalid weave IP in request: %s", weaveIPstr)
|
||||
@@ -66,8 +59,8 @@ func ListenHttp(domain string, db Zone, port int) {
|
||||
}
|
||||
|
||||
if dns.IsSubDomain(domain, name) {
|
||||
Info.Printf("Adding %s (%s) -> %s", name, localIPstr, weaveIPstr)
|
||||
if err = db.AddRecord(ident, name, localIP, weaveIP); err != nil {
|
||||
Info.Printf("Adding %s -> %s", name, weaveIPstr)
|
||||
if err = db.AddRecord(ident, name, weaveIP); err != nil {
|
||||
if dup, ok := err.(DuplicateError); !ok {
|
||||
httpErrorAndLog(
|
||||
Error, w, "Internal error", http.StatusInternalServerError,
|
||||
|
||||
@@ -32,9 +32,8 @@ func sendQuery(name string, querytype uint16) error {
|
||||
func TestServerSimpleQuery(t *testing.T) {
|
||||
log.Println("TestServerSimpleQuery starting")
|
||||
var zone = new(ZoneDb)
|
||||
dockerIP := net.ParseIP("9.8.7.6")
|
||||
weaveIP, _, _ := net.ParseCIDR(testAddr1)
|
||||
zone.AddRecord(containerID, "test.weave.", dockerIP, weaveIP)
|
||||
zone.AddRecord(containerID, "test.weave.", weaveIP)
|
||||
|
||||
mdnsServer, err := NewMDNSServer(zone)
|
||||
assertNoErr(t, err)
|
||||
|
||||
+3
-4
@@ -7,7 +7,7 @@ import (
|
||||
)
|
||||
|
||||
type Zone interface {
|
||||
AddRecord(ident string, name string, localIP net.IP, weaveIP net.IP) error
|
||||
AddRecord(ident string, name string, weaveIP net.IP) error
|
||||
DeleteRecord(ident string, weaveIp net.IP) error
|
||||
DeleteRecordsFor(ident string) error
|
||||
MatchLocal(name string) (net.IP, error)
|
||||
@@ -17,7 +17,6 @@ type Zone interface {
|
||||
type Record struct {
|
||||
Ident string
|
||||
Name string
|
||||
LocalIP net.IP
|
||||
WeaveIP net.IP
|
||||
}
|
||||
|
||||
@@ -75,7 +74,7 @@ func (zone *ZoneDb) MatchLocalIP(ip net.IP) (string, error) {
|
||||
return "", LookupError(ip.String())
|
||||
}
|
||||
|
||||
func (zone *ZoneDb) AddRecord(ident string, name string, localIP net.IP, weaveIP net.IP) error {
|
||||
func (zone *ZoneDb) AddRecord(ident string, name string, weaveIP net.IP) error {
|
||||
zone.mx.Lock()
|
||||
defer zone.mx.Unlock()
|
||||
fqdn := dns.Fqdn(name)
|
||||
@@ -83,7 +82,7 @@ func (zone *ZoneDb) AddRecord(ident string, name string, localIP net.IP, weaveIP
|
||||
func(r Record) bool { return r.Name == fqdn && r.WeaveIP.Equal(weaveIP) }); index != -1 {
|
||||
return DuplicateError{fqdn, weaveIP, zone.recs[index].Ident}
|
||||
}
|
||||
zone.recs = append(zone.recs, Record{ident, fqdn, localIP, weaveIP})
|
||||
zone.recs = append(zone.recs, Record{ident, fqdn, weaveIP})
|
||||
return nil
|
||||
}
|
||||
|
||||
|
||||
@@ -10,20 +10,18 @@ func TestZone(t *testing.T) {
|
||||
containerID = "deadbeef"
|
||||
successTestName = "test1.weave."
|
||||
testAddr1 = "10.0.2.1/24"
|
||||
dockerIP = "9.8.7.6"
|
||||
)
|
||||
|
||||
var zone = new(ZoneDb)
|
||||
|
||||
ip := net.ParseIP(dockerIP)
|
||||
weaveIP, _, _ := net.ParseCIDR(testAddr1)
|
||||
err := zone.AddRecord(containerID, successTestName, ip, weaveIP)
|
||||
err := zone.AddRecord(containerID, successTestName, weaveIP)
|
||||
assertNoErr(t, err)
|
||||
|
||||
// Add a few more records to make the job harder
|
||||
err = zone.AddRecord("abcdef0123", "adummy.weave.", net.ParseIP("1.1.1.1"), net.ParseIP("10.0.0.1"))
|
||||
err = zone.AddRecord("abcdef0123", "adummy.weave.", net.ParseIP("10.0.0.1"))
|
||||
assertNoErr(t, err)
|
||||
err = zone.AddRecord("0123abcdef", "zdummy.weave.", net.ParseIP("2.2.2.2"), net.ParseIP("10.0.0.2"))
|
||||
err = zone.AddRecord("0123abcdef", "zdummy.weave.", net.ParseIP("10.0.0.2"))
|
||||
assertNoErr(t, err)
|
||||
|
||||
// Check that the address is now there.
|
||||
@@ -43,7 +41,7 @@ func TestZone(t *testing.T) {
|
||||
}
|
||||
|
||||
// Now try to add the same address again
|
||||
err = zone.AddRecord(containerID, successTestName, ip, weaveIP)
|
||||
err = zone.AddRecord(containerID, successTestName, weaveIP)
|
||||
assertErrorType(t, err, (*DuplicateError)(nil), "duplicate add")
|
||||
|
||||
// Now delete the record
|
||||
@@ -65,13 +63,11 @@ func TestDeleteFor(t *testing.T) {
|
||||
name = "foo.weave."
|
||||
addr1 = "10.1.2.3/24"
|
||||
addr2 = "10.2.7.8/24"
|
||||
dockerIP = "172.16.0.4"
|
||||
)
|
||||
zone := new(ZoneDb)
|
||||
ip := net.ParseIP(dockerIP)
|
||||
for _, addr := range []string{addr1, addr2} {
|
||||
weaveIP, _, _ := net.ParseCIDR(addr)
|
||||
err := zone.AddRecord(id, name, ip, weaveIP)
|
||||
err := zone.AddRecord(id, name, weaveIP)
|
||||
assertNoErr(t, err)
|
||||
}
|
||||
|
||||
|
||||
@@ -316,7 +316,7 @@ tell_dns() {
|
||||
CONTAINER=$(docker inspect --format '{{.Id}}' $2 2>/dev/null)
|
||||
# extract IP address and routing prefix from CIDR
|
||||
WEAVE_ADDR_IP=$(echo $3 | sed -e 's/\([^/]*\)\/\(.*\)/\1/')
|
||||
MORE_ARGS=$(docker inspect --format '--data-urlencode local_ip={{ .NetworkSettings.IPAddress }} --data-urlencode fqdn={{ .Config.Hostname }}.{{ .Config.Domainname }}.' $CONTAINER 2>/dev/null) && true
|
||||
MORE_ARGS=$(docker inspect --format '--data-urlencode fqdn={{ .Config.Hostname }}.{{ .Config.Domainname }}.' $CONTAINER 2>/dev/null) && true
|
||||
http_call $DNS_CONTAINER_NAME $DNS_HTTP_PORT $1 /name/$CONTAINER/$WEAVE_ADDR_IP $MORE_ARGS
|
||||
}
|
||||
|
||||
@@ -334,7 +334,7 @@ populate_dns() {
|
||||
fi
|
||||
|
||||
for CONTAINER in $(docker ps -q); do
|
||||
MORE_ARGS=$(docker inspect --format '--data-urlencode local_ip={{ .NetworkSettings.IPAddress }} --data-urlencode fqdn={{ .Config.Hostname }}.{{ .Config.Domainname }}.' $CONTAINER 2>/dev/null) && true
|
||||
MORE_ARGS=$(docker inspect --format '--data-urlencode fqdn={{ .Config.Hostname }}.{{ .Config.Domainname }}.' $CONTAINER 2>/dev/null) && true
|
||||
if CONTAINER_ADDRS=$(with_container_netns $CONTAINER container_weave_addrs 2>&1) ; then
|
||||
CONTAINER_IPS=$(echo "$CONTAINER_ADDRS" | grep -o 'inet .*' | sed -e 's/inet \([^/]*\)\/\(.*\)/\1/')
|
||||
for IP in $CONTAINER_IPS; do
|
||||
|
||||
Reference in new issue
Block a user