Plumb through /proc path config to Docker plugin
This commit is contained in:
1 parent
e2088ef401
commit
6ad3e69faf
6 files changed
+17
-18
No files matched your search
+3
-3
@@ -55,9 +55,9 @@ func WithNetNSByPath(path string, work func() error) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func NSPathByPid(pid int) string {
|
func NSPathByPid(pid int) string {
|
||||||
return NSPathByPidWithRoot("/", pid)
|
return NSPathByPidWithProc("/proc", pid)
|
||||||
}
|
}
|
||||||
|
|
||||||
func NSPathByPidWithRoot(root string, pid int) string {
|
func NSPathByPidWithProc(procPath string, pid int) string {
|
||||||
return filepath.Join(root, fmt.Sprintf("/proc/%d/ns/net", pid))
|
return filepath.Join(procPath, fmt.Sprint(pid), "/ns/net")
|
||||||
}
|
}
|
||||||
+2
-2
@@ -236,7 +236,7 @@ func setupIface(procPath, ifaceName, newIfName string) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// configureARP is a helper for the Docker plugin which doesn't set the addresses itself
|
// configureARP is a helper for the Docker plugin which doesn't set the addresses itself
|
||||||
func ConfigureARP(prefix, rootPath string) error {
|
func ConfigureARP(prefix, procPath string) error {
|
||||||
links, err := netlink.LinkList()
|
links, err := netlink.LinkList()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
@@ -244,7 +244,7 @@ func ConfigureARP(prefix, rootPath string) error {
|
|||||||
for _, link := range links {
|
for _, link := range links {
|
||||||
ifName := link.Attrs().Name
|
ifName := link.Attrs().Name
|
||||||
if strings.HasPrefix(ifName, prefix) {
|
if strings.HasPrefix(ifName, prefix) {
|
||||||
configureARPCache(rootPath+"/proc", ifName)
|
configureARPCache(procPath, ifName)
|
||||||
if addrs, err := netlink.AddrList(link, netlink.FAMILY_V4); err == nil {
|
if addrs, err := netlink.AddrList(link, netlink.FAMILY_V4); err == nil {
|
||||||
for _, addr := range addrs {
|
for _, addr := range addrs {
|
||||||
arping.GratuitousArpOverIfaceByName(addr.IPNet.IP, ifName)
|
arping.GratuitousArpOverIfaceByName(addr.IPNet.IP, ifName)
|
||||||
|
|||||||
@@ -39,9 +39,10 @@ type driver struct {
|
|||||||
// used only by plugin-v2
|
// used only by plugin-v2
|
||||||
forceMulticast bool
|
forceMulticast bool
|
||||||
networks map[string]network
|
networks map[string]network
|
||||||
|
procPath string
|
||||||
}
|
}
|
||||||
|
|
||||||
func New(client *docker.Client, weave *weaveapi.Client, name, scope string, dns, isPluginV2, forceMulticast bool) (skel.Driver, error) {
|
func New(client *docker.Client, weave *weaveapi.Client, name, scope string, dns, isPluginV2, forceMulticast bool, procPath string) (skel.Driver, error) {
|
||||||
driver := &driver{
|
driver := &driver{
|
||||||
name: name,
|
name: name,
|
||||||
scope: scope,
|
scope: scope,
|
||||||
@@ -51,6 +52,7 @@ func New(client *docker.Client, weave *weaveapi.Client, name, scope string, dns,
|
|||||||
// make sure that it's used only by plugin-v2
|
// make sure that it's used only by plugin-v2
|
||||||
forceMulticast: isPluginV2 && forceMulticast,
|
forceMulticast: isPluginV2 && forceMulticast,
|
||||||
networks: make(map[string]network),
|
networks: make(map[string]network),
|
||||||
|
procPath: procPath,
|
||||||
}
|
}
|
||||||
|
|
||||||
// Do not start watcher in the case of plugin v2, which prevents us from
|
// Do not start watcher in the case of plugin v2, which prevents us from
|
||||||
@@ -134,7 +136,7 @@ func (driver *driver) CreateEndpoint(create *api.CreateEndpointRequest) (*api.Cr
|
|||||||
|
|
||||||
// create veths. note we assume endpoint IDs are unique in the first 9 chars
|
// create veths. note we assume endpoint IDs are unique in the first 9 chars
|
||||||
name, peerName := vethPair(create.EndpointID)
|
name, peerName := vethPair(create.EndpointID)
|
||||||
if _, err := weavenet.CreateAndAttachVeth("/proc", name, peerName, weavenet.WeaveBridgeName, 0, false, true, nil); err != nil {
|
if _, err := weavenet.CreateAndAttachVeth(driver.procPath, name, peerName, weavenet.WeaveBridgeName, 0, false, true, nil); err != nil {
|
||||||
return nil, driver.error("JoinEndpoint", "%s", err)
|
return nil, driver.error("JoinEndpoint", "%s", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -43,14 +43,9 @@ func (w *watcher) ContainerStarted(id string) {
|
|||||||
w.driver.warn("ContainerStarted", "unable to register %s with weaveDNS: %s", id, err)
|
w.driver.warn("ContainerStarted", "unable to register %s with weaveDNS: %s", id, err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
rootDir := "/"
|
netNSPath := weavenet.NSPathByPidWithProc(w.driver.procPath, info.State.Pid)
|
||||||
if w.driver.isPluginV2 {
|
|
||||||
// We bind mount host's /proc to /host/proc for plugin-v2
|
|
||||||
rootDir = "/host"
|
|
||||||
}
|
|
||||||
netNSPath := weavenet.NSPathByPidWithRoot(rootDir, info.State.Pid)
|
|
||||||
if err := weavenet.WithNetNSByPath(netNSPath, func() error {
|
if err := weavenet.WithNetNSByPath(netNSPath, func() error {
|
||||||
return weavenet.ConfigureARP(weavenet.VethName, rootDir)
|
return weavenet.ConfigureARP(weavenet.VethName, w.driver.procPath)
|
||||||
}); err != nil {
|
}); err != nil {
|
||||||
w.driver.warn("ContainerStarted", "unable to configure interfaces: %s", err)
|
w.driver.warn("ContainerStarted", "unable to configure interfaces: %s", err)
|
||||||
}
|
}
|
||||||
|
|||||||
+5
-4
@@ -32,6 +32,7 @@ type Config struct {
|
|||||||
EnableV2Multicast bool
|
EnableV2Multicast bool
|
||||||
DNS bool
|
DNS bool
|
||||||
DefaultSubnet string
|
DefaultSubnet string
|
||||||
|
ProcPath string // path to reach host /proc filesystem
|
||||||
}
|
}
|
||||||
|
|
||||||
type Plugin struct {
|
type Plugin struct {
|
||||||
@@ -62,7 +63,7 @@ func (plugin *Plugin) run(dockerClient *docker.Client, weave *weaveapi.Client, r
|
|||||||
endChan := make(chan error, 1)
|
endChan := make(chan error, 1)
|
||||||
|
|
||||||
if plugin.Socket != "" {
|
if plugin.Socket != "" {
|
||||||
globalListener, err := listenAndServe(dockerClient, weave, plugin.Socket, endChan, "global", false, plugin.DNS, plugin.EnableV2, plugin.EnableV2Multicast)
|
globalListener, err := listenAndServe(dockerClient, weave, plugin.Socket, endChan, "global", false, plugin.DNS, plugin.EnableV2, plugin.EnableV2Multicast, plugin.ProcPath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@@ -70,7 +71,7 @@ func (plugin *Plugin) run(dockerClient *docker.Client, weave *weaveapi.Client, r
|
|||||||
defer globalListener.Close()
|
defer globalListener.Close()
|
||||||
}
|
}
|
||||||
if plugin.MeshSocket != "" {
|
if plugin.MeshSocket != "" {
|
||||||
meshListener, err := listenAndServe(dockerClient, weave, plugin.MeshSocket, endChan, "local", true, plugin.DNS, plugin.EnableV2, plugin.EnableV2Multicast)
|
meshListener, err := listenAndServe(dockerClient, weave, plugin.MeshSocket, endChan, "local", true, plugin.DNS, plugin.EnableV2, plugin.EnableV2Multicast, plugin.ProcPath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@@ -87,7 +88,7 @@ func (plugin *Plugin) run(dockerClient *docker.Client, weave *weaveapi.Client, r
|
|||||||
return <-endChan
|
return <-endChan
|
||||||
}
|
}
|
||||||
|
|
||||||
func listenAndServe(dockerClient *docker.Client, weave *weaveapi.Client, address string, endChan chan<- error, scope string, withIpam, dns bool, isPluginV2, forceMulticast bool) (net.Listener, error) {
|
func listenAndServe(dockerClient *docker.Client, weave *weaveapi.Client, address string, endChan chan<- error, scope string, withIpam, dns bool, isPluginV2, forceMulticast bool, procPath string) (net.Listener, error) {
|
||||||
var name string
|
var name string
|
||||||
if isPluginV2 {
|
if isPluginV2 {
|
||||||
name = pluginV2Name
|
name = pluginV2Name
|
||||||
@@ -95,7 +96,7 @@ func listenAndServe(dockerClient *docker.Client, weave *weaveapi.Client, address
|
|||||||
name = pluginNameFromAddress(address)
|
name = pluginNameFromAddress(address)
|
||||||
}
|
}
|
||||||
|
|
||||||
d, err := netplugin.New(dockerClient, weave, name, scope, dns, isPluginV2, forceMulticast)
|
d, err := netplugin.New(dockerClient, weave, name, scope, dns, isPluginV2, forceMulticast, procPath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -453,6 +453,7 @@ func main() {
|
|||||||
|
|
||||||
pluginConfig.DNS = !noDNS
|
pluginConfig.DNS = !noDNS
|
||||||
pluginConfig.DefaultSubnet = defaultSubnet.String()
|
pluginConfig.DefaultSubnet = defaultSubnet.String()
|
||||||
|
pluginConfig.ProcPath = procPath
|
||||||
plugin := plugin.NewPlugin(pluginConfig)
|
plugin := plugin.NewPlugin(pluginConfig)
|
||||||
|
|
||||||
// The weave script always waits for a status call to succeed,
|
// The weave script always waits for a status call to succeed,
|
||||||
|
|||||||
Reference in new issue
Block a user