From 5041b74451e9405e89ea2bb5606f518b961e1a07 Mon Sep 17 00:00:00 2001 From: Chris Telfer Date: Mon, 23 Jul 2018 17:18:16 -0400 Subject: [PATCH] Give LB sandboxes predictable names Change the sandbox IDs for the sandboxes of load-balancing endpoints to be "lb_XXXXXXXXX" where XXXXXXXXX is the network ID that this sandbox load balances for. This makes it easier to find these sandboxes in /var/run/docker/netns and thus makes debugging easier. Signed-off-by: Chris Telfer --- libnetwork/controller.go | 2 ++ libnetwork/network.go | 2 +- libnetwork/sandbox.go | 4 +++- 3 files changed, 6 insertions(+), 2 deletions(-) diff --git a/libnetwork/controller.go b/libnetwork/controller.go index eb5525300b..f956ddb280 100644 --- a/libnetwork/controller.go +++ b/libnetwork/controller.go @@ -1107,6 +1107,8 @@ func (c *controller) NewSandbox(containerID string, options ...SandboxOption) (S sb.config.hostsPath = filepath.Join(c.cfg.Daemon.DataDir, "/network/files/hosts") sb.config.resolvConfPath = filepath.Join(c.cfg.Daemon.DataDir, "/network/files/resolv.conf") sb.id = "ingress_sbox" + } else if sb.loadBalancerNID != "" { + sb.id = "lb_" + sb.loadBalancerNID } c.Unlock() diff --git a/libnetwork/network.go b/libnetwork/network.go index b639cdbb06..6781c857d6 100644 --- a/libnetwork/network.go +++ b/libnetwork/network.go @@ -2126,7 +2126,7 @@ func (n *network) lbEndpointName() string { func (n *network) createLoadBalancerSandbox() (retErr error) { sandboxName := n.lbSandboxName() // Mark the sandbox to be a load balancer - sbOptions := []SandboxOption{OptionLoadBalancer()} + sbOptions := []SandboxOption{OptionLoadBalancer(n.id)} if n.ingress { sbOptions = append(sbOptions, OptionIngress()) } diff --git a/libnetwork/sandbox.go b/libnetwork/sandbox.go index acbc243974..65a3800ff1 100644 --- a/libnetwork/sandbox.go +++ b/libnetwork/sandbox.go @@ -84,6 +84,7 @@ type sandbox struct { ingress bool ndotsSet bool oslTypes []osl.SandboxType // slice of properties of this sandbox + loadBalancerNID string // NID that this SB is a load balancer for sync.Mutex // This mutex is used to serialize service related operation for an endpoint // The lock is here because the endpoint is saved into the store so is not unique @@ -1169,8 +1170,9 @@ func OptionIngress() SandboxOption { // OptionLoadBalancer function returns an option setter for marking a // sandbox as a load balancer sandbox. -func OptionLoadBalancer() SandboxOption { +func OptionLoadBalancer(nid string) SandboxOption { return func(sb *sandbox) { + sb.loadBalancerNID = nid sb.oslTypes = append(sb.oslTypes, osl.SandboxTypeLoadBalancer) } }