Move initial DNS population into Go code
This commit is contained in:
1 parent
ef9f95f653
commit
4ad1c22ef6
3 files changed
+52
-13
No files matched your search
@@ -384,6 +384,9 @@ func main() {
|
|||||||
ns.Start()
|
ns.Start()
|
||||||
defer ns.Stop()
|
defer ns.Stop()
|
||||||
dnsserver.ActivateAndServe()
|
dnsserver.ActivateAndServe()
|
||||||
|
if dockerCli != nil {
|
||||||
|
populateDNS(ns, dockerCli, name, bridgeConfig.WeaveBridgeName)
|
||||||
|
}
|
||||||
defer dnsserver.Stop()
|
defer dnsserver.Stop()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -2,13 +2,16 @@ package main
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"net"
|
"net"
|
||||||
|
"strings"
|
||||||
|
|
||||||
docker "github.com/fsouza/go-dockerclient"
|
docker "github.com/fsouza/go-dockerclient"
|
||||||
|
|
||||||
|
"github.com/weaveworks/mesh"
|
||||||
"github.com/weaveworks/weave/api"
|
"github.com/weaveworks/weave/api"
|
||||||
"github.com/weaveworks/weave/common"
|
"github.com/weaveworks/weave/common"
|
||||||
weavedocker "github.com/weaveworks/weave/common/docker"
|
weavedocker "github.com/weaveworks/weave/common/docker"
|
||||||
"github.com/weaveworks/weave/ipam"
|
"github.com/weaveworks/weave/ipam"
|
||||||
|
"github.com/weaveworks/weave/nameserver"
|
||||||
weavenet "github.com/weaveworks/weave/net"
|
weavenet "github.com/weaveworks/weave/net"
|
||||||
"github.com/weaveworks/weave/net/address"
|
"github.com/weaveworks/weave/net/address"
|
||||||
)
|
)
|
||||||
@@ -87,3 +90,49 @@ func findExistingAddresses(dockerCli *weavedocker.Client, bridgeName string) (ad
|
|||||||
}
|
}
|
||||||
return addrs, nil
|
return addrs, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func populateDNS(ns *nameserver.Nameserver, dockerCli *weavedocker.Client, ourName mesh.PeerName, bridgeName string) (addrs []ipam.PreClaim, err error) {
|
||||||
|
// Find all veths connected to the bridge
|
||||||
|
peerIDs, err := weavenet.ConnectedToBridgeVethPeerIds(bridgeName)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
// Now iterate over all containers to see if they have a network
|
||||||
|
// namespace with an attached interface
|
||||||
|
if dockerCli != nil {
|
||||||
|
containerIDs, err := dockerCli.RunningContainerIDs()
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, cid := range containerIDs {
|
||||||
|
container, err := dockerCli.InspectContainer(cid)
|
||||||
|
if err != nil {
|
||||||
|
if _, ok := err.(*docker.NoSuchContainer); ok {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
if container.State.Pid != 0 {
|
||||||
|
// Docker allows containers to have fqdns in two wauys:
|
||||||
|
// where the container explicitly has a domain name, and when its
|
||||||
|
// hostname contains the domain name, recognized by it having dots.
|
||||||
|
if container.Config.Domainname == "" && !strings.Contains(container.Config.Hostname, ".") {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
netDevs, err := weavenet.GetNetDevsByVethPeerIds(container.State.Pid, peerIDs)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
fqdn := container.Config.Hostname + "." + container.Config.Domainname
|
||||||
|
for _, netDev := range netDevs {
|
||||||
|
for _, cidr := range netDev.CIDRs {
|
||||||
|
ns.AddEntryFQDN(fqdn, cid, ourName, address.FromIP4(cidr.IP))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return addrs, nil
|
||||||
|
}
|
||||||
@@ -1417,7 +1417,6 @@ launch_router() {
|
|||||||
"$@")
|
"$@")
|
||||||
wait_for_status $CONTAINER_NAME http_call $HTTP_ADDR
|
wait_for_status $CONTAINER_NAME http_call $HTTP_ADDR
|
||||||
setup_awsvpc
|
setup_awsvpc
|
||||||
populate_router
|
|
||||||
|
|
||||||
if [ -n "$ENABLE_PLUGIN" ]; then
|
if [ -n "$ENABLE_PLUGIN" ]; then
|
||||||
wait_for_status $CONTAINER_NAME http_call_unix $CONTAINER_NAME plugin-status.sock
|
wait_for_status $CONTAINER_NAME http_call_unix $CONTAINER_NAME plugin-status.sock
|
||||||
@@ -1437,17 +1436,6 @@ fetch_router_args() {
|
|||||||
NO_DNS_OPT=$(echo $CONTAINER_ARGS | grep -o -e '--no-dns') || true
|
NO_DNS_OPT=$(echo $CONTAINER_ARGS | grep -o -e '--no-dns') || true
|
||||||
}
|
}
|
||||||
|
|
||||||
populate_dns_for_one_container() {
|
|
||||||
[ -z "$4" ] || with_container_fqdn $1 put_dns_fqdn $4
|
|
||||||
}
|
|
||||||
|
|
||||||
populate_router() {
|
|
||||||
if [ -z "$NO_DNS_OPT" ] ; then
|
|
||||||
# Tell the newly-started weaveDNS about existing weave IPs
|
|
||||||
with_container_addresses populate_dns_for_one_container weave:allids
|
|
||||||
fi
|
|
||||||
}
|
|
||||||
|
|
||||||
stop_router() {
|
stop_router() {
|
||||||
! is_plugin_v1_enabled || util_op remove-plugin-network weave || true
|
! is_plugin_v1_enabled || util_op remove-plugin-network weave || true
|
||||||
stop $CONTAINER_NAME "Weave"
|
stop $CONTAINER_NAME "Weave"
|
||||||
@@ -1673,7 +1661,6 @@ EOF
|
|||||||
fetch_router_args
|
fetch_router_args
|
||||||
wait_for_status $CONTAINER_NAME http_call $HTTP_ADDR
|
wait_for_status $CONTAINER_NAME http_call $HTTP_ADDR
|
||||||
setup_awsvpc
|
setup_awsvpc
|
||||||
populate_router
|
|
||||||
;;
|
;;
|
||||||
launch-proxy)
|
launch-proxy)
|
||||||
deprecation_warnings "$@"
|
deprecation_warnings "$@"
|
||||||
|
|||||||
Reference in new issue
Block a user