[proxy] query weavedns for domain
This commit is contained in:
1 parent
b9850ac200
commit
99d9ad7042
1 file changed
+26
-2
@@ -3,6 +3,7 @@ package proxy
|
|||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
|
"fmt"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"net/http"
|
"net/http"
|
||||||
"strings"
|
"strings"
|
||||||
@@ -93,13 +94,36 @@ func (i *createContainerInterceptor) setWeaveDNS(container *createContainerReque
|
|||||||
name := r.URL.Query().Get("name")
|
name := r.URL.Query().Get("name")
|
||||||
if container.Hostname == "" && name != "" {
|
if container.Hostname == "" && name != "" {
|
||||||
container.Hostname = name
|
container.Hostname = name
|
||||||
// TODO: Get weaveDNS domain
|
container.Domainname = i.getDNSDomain()
|
||||||
container.Domainname = nameserver.DefaultLocalDomain
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (i *createContainerInterceptor) getDNSDomain() (domain string) {
|
||||||
|
domain = nameserver.DefaultLocalDomain
|
||||||
|
dnsContainer, err := i.proxy.client.InspectContainer("weavedns")
|
||||||
|
if err != nil ||
|
||||||
|
dnsContainer.NetworkSettings == nil ||
|
||||||
|
dnsContainer.NetworkSettings.IPAddress == "" {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
url := fmt.Sprintf("http://%s:6785/domain", dnsContainer.NetworkSettings.IPAddress)
|
||||||
|
resp, err := http.Get(url)
|
||||||
|
if err != nil || resp.StatusCode != http.StatusOK {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
defer resp.Body.Close()
|
||||||
|
|
||||||
|
b, err := ioutil.ReadAll(resp.Body)
|
||||||
|
if err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
return string(b)
|
||||||
|
}
|
||||||
|
|
||||||
func (i *createContainerInterceptor) InterceptResponse(r *http.Response) error {
|
func (i *createContainerInterceptor) InterceptResponse(r *http.Response) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
Reference in new issue
Block a user