mirror of
https://github.com/moby/moby.git
synced 2026-01-11 18:51:37 +00:00
libnet: Add ctx to NewSandbox
Signed-off-by: Albin Kerouanton <albinker@gmail.com>
This commit is contained in:
@@ -119,7 +119,7 @@ func (iface *lnInterface) init(c *libnetwork.Controller, n *libnetwork.Network)
|
||||
return
|
||||
}
|
||||
|
||||
sbx, err := c.NewSandbox(id, libnetwork.OptionUseExternalKey(), libnetwork.OptionHostsPath(filepath.Join(iface.provider.Root, id, "hosts")),
|
||||
sbx, err := c.NewSandbox(context.TODO(), id, libnetwork.OptionUseExternalKey(), libnetwork.OptionHostsPath(filepath.Join(iface.provider.Root, id, "hosts")),
|
||||
libnetwork.OptionResolvConfPath(filepath.Join(iface.provider.Root, id, "resolv.conf")))
|
||||
if err != nil {
|
||||
iface.err = err
|
||||
|
||||
@@ -542,7 +542,7 @@ func (daemon *Daemon) allocateNetwork(ctx context.Context, cfg *config.Config, c
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
sb, err := daemon.netController.NewSandbox(container.ID, sbOptions...)
|
||||
sb, err := daemon.netController.NewSandbox(ctx, container.ID, sbOptions...)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -784,7 +784,7 @@ func (daemon *Daemon) connectToNetwork(ctx context.Context, cfg *config.Config,
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
sb, err = daemon.netController.NewSandbox(container.ID, sbOptions...)
|
||||
sb, err = daemon.netController.NewSandbox(ctx, container.ID, sbOptions...)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -73,6 +73,7 @@ import (
|
||||
"github.com/docker/docker/pkg/stringid"
|
||||
"github.com/moby/locker"
|
||||
"github.com/pkg/errors"
|
||||
"go.opentelemetry.io/otel"
|
||||
)
|
||||
|
||||
// NetworkWalker is a client provided function which will be used to walk the Networks.
|
||||
@@ -871,11 +872,14 @@ func (c *Controller) NetworkByID(id string) (*Network, error) {
|
||||
}
|
||||
|
||||
// NewSandbox creates a new sandbox for containerID.
|
||||
func (c *Controller) NewSandbox(containerID string, options ...SandboxOption) (_ *Sandbox, retErr error) {
|
||||
func (c *Controller) NewSandbox(ctx context.Context, containerID string, options ...SandboxOption) (_ *Sandbox, retErr error) {
|
||||
if containerID == "" {
|
||||
return nil, types.InvalidParameterErrorf("invalid container ID")
|
||||
}
|
||||
|
||||
ctx, span := otel.Tracer("").Start(ctx, "libnetwork.Controller.NewSandbox")
|
||||
defer span.End()
|
||||
|
||||
var sb *Sandbox
|
||||
c.mu.Lock()
|
||||
for _, s := range c.sandboxes {
|
||||
|
||||
@@ -38,7 +38,7 @@ fe90::2 somehost.example.com somehost
|
||||
}
|
||||
defer os.Remove(hostsFile.Name())
|
||||
|
||||
sbx, err := ctrlr.NewSandbox("sandbox1", OptionHostsPath(hostsFile.Name()), OptionHostname("somehost.example.com"))
|
||||
sbx, err := ctrlr.NewSandbox(context.Background(), "sandbox1", OptionHostsPath(hostsFile.Name()), OptionHostname("somehost.example.com"))
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
@@ -377,7 +377,7 @@ func TestSRVServiceQuery(t *testing.T) {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
sb, err := c.NewSandbox("c1")
|
||||
sb, err := c.NewSandbox(context.Background(), "c1")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
@@ -476,7 +476,7 @@ func TestServiceVIPReuse(t *testing.T) {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
sb, err := c.NewSandbox("c1")
|
||||
sb, err := c.NewSandbox(context.Background(), "c1")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
@@ -97,7 +97,7 @@ func TestNull(t *testing.T) {
|
||||
defer netnsutils.SetupTestOSContext(t)()
|
||||
controller := newController(t)
|
||||
|
||||
cnt, err := controller.NewSandbox("null_container",
|
||||
cnt, err := controller.NewSandbox(context.Background(), "null_container",
|
||||
libnetwork.OptionHostname("test"),
|
||||
libnetwork.OptionDomainname("example.com"),
|
||||
libnetwork.OptionExtraHost("web", "192.168.0.1"))
|
||||
@@ -878,7 +878,7 @@ func TestEndpointDeleteWithActiveContainer(t *testing.T) {
|
||||
}
|
||||
}()
|
||||
|
||||
cnt, err := controller.NewSandbox(containerID,
|
||||
cnt, err := controller.NewSandbox(context.Background(), containerID,
|
||||
libnetwork.OptionHostname("test"),
|
||||
libnetwork.OptionDomainname("example.com"),
|
||||
libnetwork.OptionExtraHost("web", "192.168.0.1"))
|
||||
@@ -937,7 +937,7 @@ func TestEndpointMultipleJoins(t *testing.T) {
|
||||
}
|
||||
}()
|
||||
|
||||
sbx1, err := controller.NewSandbox(containerID,
|
||||
sbx1, err := controller.NewSandbox(context.Background(), containerID,
|
||||
libnetwork.OptionHostname("test"),
|
||||
libnetwork.OptionDomainname("example.com"),
|
||||
libnetwork.OptionExtraHost("web", "192.168.0.1"),
|
||||
@@ -951,7 +951,7 @@ func TestEndpointMultipleJoins(t *testing.T) {
|
||||
}
|
||||
}()
|
||||
|
||||
sbx2, err := controller.NewSandbox("c2")
|
||||
sbx2, err := controller.NewSandbox(context.Background(), "c2")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
@@ -1025,7 +1025,7 @@ func TestLeaveAll(t *testing.T) {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
cnt, err := controller.NewSandbox("leaveall")
|
||||
cnt, err := controller.NewSandbox(context.Background(), "leaveall")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
@@ -1074,7 +1074,7 @@ func TestContainerInvalidLeave(t *testing.T) {
|
||||
}
|
||||
}()
|
||||
|
||||
cnt, err := controller.NewSandbox(containerID,
|
||||
cnt, err := controller.NewSandbox(context.Background(), containerID,
|
||||
libnetwork.OptionHostname("test"),
|
||||
libnetwork.OptionDomainname("example.com"),
|
||||
libnetwork.OptionExtraHost("web", "192.168.0.1"))
|
||||
@@ -1139,7 +1139,7 @@ func TestEndpointUpdateParent(t *testing.T) {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
sbx1, err := controller.NewSandbox(containerID,
|
||||
sbx1, err := controller.NewSandbox(context.Background(), containerID,
|
||||
libnetwork.OptionHostname("test"),
|
||||
libnetwork.OptionDomainname("example.com"),
|
||||
libnetwork.OptionExtraHost("web", "192.168.0.1"))
|
||||
@@ -1152,7 +1152,7 @@ func TestEndpointUpdateParent(t *testing.T) {
|
||||
}
|
||||
}()
|
||||
|
||||
sbx2, err := controller.NewSandbox("c2",
|
||||
sbx2, err := controller.NewSandbox(context.Background(), "c2",
|
||||
libnetwork.OptionHostname("test2"),
|
||||
libnetwork.OptionDomainname("example.com"),
|
||||
libnetwork.OptionHostsPath("/var/lib/docker/test_network/container2/hosts"),
|
||||
@@ -1310,7 +1310,7 @@ func TestHost(t *testing.T) {
|
||||
defer netnsutils.SetupTestOSContext(t)()
|
||||
controller := newController(t)
|
||||
|
||||
sbx1, err := controller.NewSandbox("host_c1",
|
||||
sbx1, err := controller.NewSandbox(context.Background(), "host_c1",
|
||||
libnetwork.OptionHostname("test1"),
|
||||
libnetwork.OptionDomainname("example.com"),
|
||||
libnetwork.OptionExtraHost("web", "192.168.0.1"),
|
||||
@@ -1324,7 +1324,7 @@ func TestHost(t *testing.T) {
|
||||
}
|
||||
}()
|
||||
|
||||
sbx2, err := controller.NewSandbox("host_c2",
|
||||
sbx2, err := controller.NewSandbox(context.Background(), "host_c2",
|
||||
libnetwork.OptionHostname("test2"),
|
||||
libnetwork.OptionDomainname("example.com"),
|
||||
libnetwork.OptionExtraHost("web", "192.168.0.1"),
|
||||
@@ -1374,7 +1374,7 @@ func TestHost(t *testing.T) {
|
||||
}
|
||||
|
||||
// Try to create another host endpoint and join/leave that.
|
||||
cnt3, err := controller.NewSandbox("host_c3",
|
||||
cnt3, err := controller.NewSandbox(context.Background(), "host_c3",
|
||||
libnetwork.OptionHostname("test3"),
|
||||
libnetwork.OptionDomainname("example.com"),
|
||||
libnetwork.OptionExtraHost("web", "192.168.0.1"),
|
||||
@@ -1557,7 +1557,7 @@ func TestEndpointJoin(t *testing.T) {
|
||||
t.Fatalf("Unexpected error type returned: %T", err)
|
||||
}
|
||||
|
||||
sb, err := controller.NewSandbox(containerID,
|
||||
sb, err := controller.NewSandbox(context.Background(), containerID,
|
||||
libnetwork.OptionHostname("test"),
|
||||
libnetwork.OptionDomainname("example.com"),
|
||||
libnetwork.OptionExtraHost("web", "192.168.0.1"))
|
||||
@@ -1711,7 +1711,7 @@ func externalKeyTest(t *testing.T, reexec bool) {
|
||||
}
|
||||
}()
|
||||
|
||||
cnt, err := controller.NewSandbox(containerID,
|
||||
cnt, err := controller.NewSandbox(context.Background(), containerID,
|
||||
libnetwork.OptionHostname("test"),
|
||||
libnetwork.OptionDomainname("example.com"),
|
||||
libnetwork.OptionUseExternalKey(),
|
||||
@@ -1873,7 +1873,7 @@ func TestResolvConf(t *testing.T) {
|
||||
libnetwork.OptionResolvConfPath(resolvConfPath),
|
||||
libnetwork.OptionOriginResolvConfPath(originResolvConfPath),
|
||||
)
|
||||
sb, err := c.NewSandbox(containerID, sbOpts...)
|
||||
sb, err := c.NewSandbox(context.Background(), containerID, sbOpts...)
|
||||
assert.NilError(t, err)
|
||||
defer func() {
|
||||
err := sb.Delete()
|
||||
@@ -2002,11 +2002,11 @@ func TestParallel(t *testing.T) {
|
||||
}
|
||||
|
||||
sboxes := make([]*libnetwork.Sandbox, numThreads)
|
||||
if sboxes[first-1], err = controller.NewSandbox(fmt.Sprintf("%drace", first), libnetwork.OptionUseDefaultSandbox()); err != nil {
|
||||
if sboxes[first-1], err = controller.NewSandbox(context.Background(), fmt.Sprintf("%drace", first), libnetwork.OptionUseDefaultSandbox()); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
for thd := first + 1; thd <= last; thd++ {
|
||||
if sboxes[thd-1], err = controller.NewSandbox(fmt.Sprintf("%drace", thd)); err != nil {
|
||||
if sboxes[thd-1], err = controller.NewSandbox(context.Background(), fmt.Sprintf("%drace", thd)); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
@@ -2059,7 +2059,7 @@ func TestBridge(t *testing.T) {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
sb, err := controller.NewSandbox(containerID, libnetwork.OptionPortMapping(getPortMapping()))
|
||||
sb, err := controller.NewSandbox(context.Background(), containerID, libnetwork.OptionPortMapping(getPortMapping()))
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
@@ -2116,7 +2116,7 @@ func (n *Network) createLoadBalancerSandbox() (retErr error) {
|
||||
if n.ingress {
|
||||
sbOptions = append(sbOptions, OptionIngress())
|
||||
}
|
||||
sb, err := n.ctrlr.NewSandbox(sandboxName, sbOptions...)
|
||||
sb, err := n.ctrlr.NewSandbox(context.TODO(), sandboxName, sbOptions...)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -38,7 +38,7 @@ func TestDNSIPQuery(t *testing.T) {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
sb, err := c.NewSandbox("c1")
|
||||
sb, err := c.NewSandbox(context.Background(), "c1")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
@@ -131,7 +131,7 @@ func TestDNSProxyServFail(t *testing.T) {
|
||||
}
|
||||
}()
|
||||
|
||||
sb, err := c.NewSandbox("c1")
|
||||
sb, err := c.NewSandbox(context.Background(), "c1")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
package libnetwork
|
||||
|
||||
import (
|
||||
"context"
|
||||
"runtime"
|
||||
"testing"
|
||||
|
||||
@@ -18,7 +19,7 @@ func TestDNSOptions(t *testing.T) {
|
||||
c, err := New(OptionBoltdbWithRandomDBFile(t))
|
||||
assert.NilError(t, err)
|
||||
|
||||
sb, err := c.NewSandbox("cnt1", nil)
|
||||
sb, err := c.NewSandbox(context.Background(), "cnt1", nil)
|
||||
assert.NilError(t, err)
|
||||
|
||||
cleanup := func(s *Sandbox) {
|
||||
@@ -57,7 +58,7 @@ func TestDNSOptions(t *testing.T) {
|
||||
assert.Check(t, is.Len(dnsOptionsList, 1))
|
||||
assert.Check(t, is.Equal("ndots:5", dnsOptionsList[0]))
|
||||
|
||||
sb2, err := c.NewSandbox("cnt2", nil)
|
||||
sb2, err := c.NewSandbox(context.Background(), "cnt2", nil)
|
||||
assert.NilError(t, err)
|
||||
defer cleanup(sb2)
|
||||
sb2.startResolver(false)
|
||||
|
||||
@@ -74,7 +74,7 @@ func TestControllerGetSandbox(t *testing.T) {
|
||||
})
|
||||
t.Run("existing sandbox", func(t *testing.T) {
|
||||
const cID = "test-container-id"
|
||||
expected, err := ctrlr.NewSandbox(cID)
|
||||
expected, err := ctrlr.NewSandbox(context.Background(), cID)
|
||||
assert.Check(t, err)
|
||||
|
||||
sb, err := ctrlr.GetSandbox(cID)
|
||||
@@ -96,7 +96,7 @@ func TestControllerGetSandbox(t *testing.T) {
|
||||
func TestSandboxAddEmpty(t *testing.T) {
|
||||
ctrlr, _ := getTestEnv(t)
|
||||
|
||||
sbx, err := ctrlr.NewSandbox("sandbox0")
|
||||
sbx, err := ctrlr.NewSandbox(context.Background(), "sandbox0")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
@@ -124,7 +124,7 @@ func TestSandboxAddMultiPrio(t *testing.T) {
|
||||
|
||||
ctrlr, nws := getTestEnv(t, opts...)
|
||||
|
||||
sbx, err := ctrlr.NewSandbox("sandbox1")
|
||||
sbx, err := ctrlr.NewSandbox(context.Background(), "sandbox1")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
@@ -209,7 +209,7 @@ func TestSandboxAddSamePrio(t *testing.T) {
|
||||
|
||||
ctrlr, nws := getTestEnv(t, opts...)
|
||||
|
||||
sbx, err := ctrlr.NewSandbox("sandbox1")
|
||||
sbx, err := ctrlr.NewSandbox(context.Background(), "sandbox1")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user