Przeglądaj źródła

Merge pull request #236 from mrjana/cnm

Remove container data return value from Join
Madhu Venugopal 10 lat temu
rodzic
commit
17919459c5

+ 2 - 3
libnetwork/README.md

@@ -48,10 +48,9 @@ There are many networking solutions available to suit a broad range of use-cases
         }
         }
 
 
         // A container can join the endpoint by providing the container ID to the join
         // A container can join the endpoint by providing the container ID to the join
-        // api which returns the sandbox key which can be used to access the sandbox
-        // created for the container during join.
+        // api.
         // Join acceps Variadic arguments which will be made use of by libnetwork and Drivers
         // Join acceps Variadic arguments which will be made use of by libnetwork and Drivers
-        _, err = ep.Join("container1",
+        err = ep.Join("container1",
                 libnetwork.JoinOptionHostname("test"),
                 libnetwork.JoinOptionHostname("test"),
                 libnetwork.JoinOptionDomainname("docker.io"))
                 libnetwork.JoinOptionDomainname("docker.io"))
         if err != nil {
         if err != nil {

+ 2 - 2
libnetwork/api/api.go

@@ -407,11 +407,11 @@ func procJoinEndpoint(c libnetwork.NetworkController, vars map[string]string, bo
 		return nil, errRsp
 		return nil, errRsp
 	}
 	}
 
 
-	cd, err := ep.Join(ej.ContainerID, ej.parseOptions()...)
+	err = ep.Join(ej.ContainerID, ej.parseOptions()...)
 	if err != nil {
 	if err != nil {
 		return nil, convertNetworkError(err)
 		return nil, convertNetworkError(err)
 	}
 	}
-	return cd, &successResponse
+	return ep.Info().SandboxKey(), &successResponse
 }
 }
 
 
 func procLeaveEndpoint(c libnetwork.NetworkController, vars map[string]string, body []byte) (interface{}, *responseStatus) {
 func procLeaveEndpoint(c libnetwork.NetworkController, vars map[string]string, body []byte) (interface{}, *responseStatus) {

+ 3 - 11
libnetwork/api/api_test.go

@@ -46,14 +46,6 @@ func i2e(i interface{}) *endpointResource {
 	return s
 	return s
 }
 }
 
 
-func i2c(i interface{}) *libnetwork.ContainerData {
-	s, ok := i.(*libnetwork.ContainerData)
-	if !ok {
-		panic(fmt.Sprintf("Failed i2c for %v", i))
-	}
-	return s
-}
-
 func i2eL(i interface{}) []*endpointResource {
 func i2eL(i interface{}) []*endpointResource {
 	s, ok := i.([]*endpointResource)
 	s, ok := i.([]*endpointResource)
 	if !ok {
 	if !ok {
@@ -803,13 +795,13 @@ func TestJoinLeave(t *testing.T) {
 	}
 	}
 
 
 	vars[urlEpName] = "endpoint"
 	vars[urlEpName] = "endpoint"
-	cdi, errRsp := procJoinEndpoint(c, vars, jlb)
+	key, errRsp := procJoinEndpoint(c, vars, jlb)
 	if errRsp != &successResponse {
 	if errRsp != &successResponse {
 		t.Fatalf("Expected failure, got: %v", errRsp)
 		t.Fatalf("Expected failure, got: %v", errRsp)
 	}
 	}
 
 
-	cd := i2c(cdi)
-	if cd.SandboxKey == "" {
+	keyStr := i2s(key)
+	if keyStr == "" {
 		t.Fatalf("Empty sandbox key")
 		t.Fatalf("Empty sandbox key")
 	}
 	}
 	_, errRsp = procDeleteEndpoint(c, vars, nil)
 	_, errRsp = procDeleteEndpoint(c, vars, nil)

+ 2 - 3
libnetwork/cmd/readme_test/readme.go

@@ -44,10 +44,9 @@ func main() {
 	}
 	}
 
 
 	// A container can join the endpoint by providing the container ID to the join
 	// A container can join the endpoint by providing the container ID to the join
-	// api which returns the sandbox key which can be used to access the sandbox
-	// created for the container during join.
+	// api.
 	// Join acceps Variadic arguments which will be made use of by libnetwork and Drivers
 	// Join acceps Variadic arguments which will be made use of by libnetwork and Drivers
-	_, err = ep.Join("container1",
+	err = ep.Join("container1",
 		libnetwork.JoinOptionHostname("test"),
 		libnetwork.JoinOptionHostname("test"),
 		libnetwork.JoinOptionDomainname("docker.io"))
 		libnetwork.JoinOptionDomainname("docker.io"))
 	if err != nil {
 	if err != nil {

+ 2 - 3
libnetwork/controller.go

@@ -33,10 +33,9 @@ create network namespaces and allocate interfaces for containers to use.
         }
         }
 
 
         // A container can join the endpoint by providing the container ID to the join
         // A container can join the endpoint by providing the container ID to the join
-        // api which returns the sandbox key which can be used to access the sandbox
-        // created for the container during join.
+        // api.
         // Join acceps Variadic arguments which will be made use of by libnetwork and Drivers
         // Join acceps Variadic arguments which will be made use of by libnetwork and Drivers
-        _, err = ep.Join("container1",
+        err = ep.Join("container1",
                 libnetwork.JoinOptionHostname("test"),
                 libnetwork.JoinOptionHostname("test"),
                 libnetwork.JoinOptionDomainname("docker.io"))
                 libnetwork.JoinOptionDomainname("docker.io"))
         if err != nil {
         if err != nil {

+ 15 - 16
libnetwork/endpoint.go

@@ -30,8 +30,8 @@ type Endpoint interface {
 
 
 	// Join creates a new sandbox for the given container ID and populates the
 	// Join creates a new sandbox for the given container ID and populates the
 	// network resources allocated for the endpoint and joins the sandbox to
 	// network resources allocated for the endpoint and joins the sandbox to
-	// the endpoint. It returns the sandbox key to the caller
-	Join(containerID string, options ...EndpointOption) (*ContainerData, error)
+	// the endpoint.
+	Join(containerID string, options ...EndpointOption) error
 
 
 	// Leave removes the sandbox associated with  container ID and detaches
 	// Leave removes the sandbox associated with  container ID and detaches
 	// the network resources populated in the sandbox
 	// the network resources populated in the sandbox
@@ -203,11 +203,11 @@ func (ep *endpoint) joinLeaveEnd() {
 	}
 	}
 }
 }
 
 
-func (ep *endpoint) Join(containerID string, options ...EndpointOption) (*ContainerData, error) {
+func (ep *endpoint) Join(containerID string, options ...EndpointOption) error {
 	var err error
 	var err error
 
 
 	if containerID == "" {
 	if containerID == "" {
-		return nil, InvalidContainerIDError(containerID)
+		return InvalidContainerIDError(containerID)
 	}
 	}
 
 
 	ep.joinLeaveStart()
 	ep.joinLeaveStart()
@@ -216,7 +216,7 @@ func (ep *endpoint) Join(containerID string, options ...EndpointOption) (*Contai
 	ep.Lock()
 	ep.Lock()
 	if ep.container != nil {
 	if ep.container != nil {
 		ep.Unlock()
 		ep.Unlock()
-		return nil, ErrInvalidJoin{}
+		return ErrInvalidJoin{}
 	}
 	}
 
 
 	ep.container = &containerInfo{
 	ep.container = &containerInfo{
@@ -260,27 +260,27 @@ func (ep *endpoint) Join(containerID string, options ...EndpointOption) (*Contai
 
 
 	err = driver.Join(nid, epid, sboxKey, ep, container.config.generic)
 	err = driver.Join(nid, epid, sboxKey, ep, container.config.generic)
 	if err != nil {
 	if err != nil {
-		return nil, err
+		return err
 	}
 	}
 
 
 	err = ep.buildHostsFiles()
 	err = ep.buildHostsFiles()
 	if err != nil {
 	if err != nil {
-		return nil, err
+		return err
 	}
 	}
 
 
 	err = ep.updateParentHosts()
 	err = ep.updateParentHosts()
 	if err != nil {
 	if err != nil {
-		return nil, err
+		return err
 	}
 	}
 
 
 	err = ep.setupDNS()
 	err = ep.setupDNS()
 	if err != nil {
 	if err != nil {
-		return nil, err
+		return err
 	}
 	}
 
 
 	sb, err := ctrlr.sandboxAdd(sboxKey, !container.config.useDefaultSandBox)
 	sb, err := ctrlr.sandboxAdd(sboxKey, !container.config.useDefaultSandBox)
 	if err != nil {
 	if err != nil {
-		return nil, err
+		return err
 	}
 	}
 	defer func() {
 	defer func() {
 		if err != nil {
 		if err != nil {
@@ -300,31 +300,30 @@ func (ep *endpoint) Join(containerID string, options ...EndpointOption) (*Contai
 		}
 		}
 		err = sb.AddInterface(iface)
 		err = sb.AddInterface(iface)
 		if err != nil {
 		if err != nil {
-			return nil, err
+			return err
 		}
 		}
 	}
 	}
 	// Set up non-interface routes.
 	// Set up non-interface routes.
 	for _, r := range ep.joinInfo.StaticRoutes {
 	for _, r := range ep.joinInfo.StaticRoutes {
 		err = sb.AddStaticRoute(r)
 		err = sb.AddStaticRoute(r)
 		if err != nil {
 		if err != nil {
-			return nil, err
+			return err
 		}
 		}
 	}
 	}
 
 
 	err = sb.SetGateway(joinInfo.gw)
 	err = sb.SetGateway(joinInfo.gw)
 	if err != nil {
 	if err != nil {
-		return nil, err
+		return err
 	}
 	}
 
 
 	err = sb.SetGatewayIPv6(joinInfo.gw6)
 	err = sb.SetGatewayIPv6(joinInfo.gw6)
 	if err != nil {
 	if err != nil {
-		return nil, err
+		return err
 	}
 	}
 
 
 	container.data.SandboxKey = sb.Key()
 	container.data.SandboxKey = sb.Key()
-	cData := container.data
 
 
-	return &cData, nil
+	return nil
 }
 }
 
 
 func (ep *endpoint) Leave(containerID string, options ...EndpointOption) error {
 func (ep *endpoint) Leave(containerID string, options ...EndpointOption) error {

+ 17 - 17
libnetwork/libnetwork_test.go

@@ -97,7 +97,7 @@ func TestNull(t *testing.T) {
 		t.Fatal(err)
 		t.Fatal(err)
 	}
 	}
 
 
-	_, err = ep.Join("null_container",
+	err = ep.Join("null_container",
 		libnetwork.JoinOptionHostname("test"),
 		libnetwork.JoinOptionHostname("test"),
 		libnetwork.JoinOptionDomainname("docker.io"),
 		libnetwork.JoinOptionDomainname("docker.io"),
 		libnetwork.JoinOptionExtraHost("web", "192.168.0.1"))
 		libnetwork.JoinOptionExtraHost("web", "192.168.0.1"))
@@ -130,7 +130,7 @@ func TestHost(t *testing.T) {
 		t.Fatal(err)
 		t.Fatal(err)
 	}
 	}
 
 
-	_, err = ep1.Join("host_container1",
+	err = ep1.Join("host_container1",
 		libnetwork.JoinOptionHostname("test1"),
 		libnetwork.JoinOptionHostname("test1"),
 		libnetwork.JoinOptionDomainname("docker.io"),
 		libnetwork.JoinOptionDomainname("docker.io"),
 		libnetwork.JoinOptionExtraHost("web", "192.168.0.1"),
 		libnetwork.JoinOptionExtraHost("web", "192.168.0.1"),
@@ -144,7 +144,7 @@ func TestHost(t *testing.T) {
 		t.Fatal(err)
 		t.Fatal(err)
 	}
 	}
 
 
-	_, err = ep2.Join("host_container2",
+	err = ep2.Join("host_container2",
 		libnetwork.JoinOptionHostname("test2"),
 		libnetwork.JoinOptionHostname("test2"),
 		libnetwork.JoinOptionDomainname("docker.io"),
 		libnetwork.JoinOptionDomainname("docker.io"),
 		libnetwork.JoinOptionExtraHost("web", "192.168.0.1"),
 		libnetwork.JoinOptionExtraHost("web", "192.168.0.1"),
@@ -177,7 +177,7 @@ func TestHost(t *testing.T) {
 		t.Fatal(err)
 		t.Fatal(err)
 	}
 	}
 
 
-	_, err = ep3.Join("host_container3",
+	err = ep3.Join("host_container3",
 		libnetwork.JoinOptionHostname("test3"),
 		libnetwork.JoinOptionHostname("test3"),
 		libnetwork.JoinOptionDomainname("docker.io"),
 		libnetwork.JoinOptionDomainname("docker.io"),
 		libnetwork.JoinOptionExtraHost("web", "192.168.0.1"),
 		libnetwork.JoinOptionExtraHost("web", "192.168.0.1"),
@@ -804,7 +804,7 @@ func TestEndpointJoin(t *testing.T) {
 		t.Fatalf("Expected an empty sandbox key for an empty endpoint. Instead found a non-empty sandbox key: %s", info.SandboxKey())
 		t.Fatalf("Expected an empty sandbox key for an empty endpoint. Instead found a non-empty sandbox key: %s", info.SandboxKey())
 	}
 	}
 
 
-	_, err = ep.Join(containerID,
+	err = ep.Join(containerID,
 		libnetwork.JoinOptionHostname("test"),
 		libnetwork.JoinOptionHostname("test"),
 		libnetwork.JoinOptionDomainname("docker.io"),
 		libnetwork.JoinOptionDomainname("docker.io"),
 		libnetwork.JoinOptionExtraHost("web", "192.168.0.1"))
 		libnetwork.JoinOptionExtraHost("web", "192.168.0.1"))
@@ -847,7 +847,7 @@ func TestEndpointJoinInvalidContainerId(t *testing.T) {
 		t.Fatal(err)
 		t.Fatal(err)
 	}
 	}
 
 
-	_, err = ep.Join("")
+	err = ep.Join("")
 	if err == nil {
 	if err == nil {
 		t.Fatal("Expected to fail join with empty container id string")
 		t.Fatal("Expected to fail join with empty container id string")
 	}
 	}
@@ -872,7 +872,7 @@ func TestEndpointDeleteWithActiveContainer(t *testing.T) {
 		t.Fatal(err)
 		t.Fatal(err)
 	}
 	}
 
 
-	_, err = ep.Join(containerID,
+	err = ep.Join(containerID,
 		libnetwork.JoinOptionHostname("test"),
 		libnetwork.JoinOptionHostname("test"),
 		libnetwork.JoinOptionDomainname("docker.io"),
 		libnetwork.JoinOptionDomainname("docker.io"),
 		libnetwork.JoinOptionExtraHost("web", "192.168.0.1"))
 		libnetwork.JoinOptionExtraHost("web", "192.168.0.1"))
@@ -916,7 +916,7 @@ func TestEndpointMultipleJoins(t *testing.T) {
 		t.Fatal(err)
 		t.Fatal(err)
 	}
 	}
 
 
-	_, err = ep.Join(containerID,
+	err = ep.Join(containerID,
 		libnetwork.JoinOptionHostname("test"),
 		libnetwork.JoinOptionHostname("test"),
 		libnetwork.JoinOptionDomainname("docker.io"),
 		libnetwork.JoinOptionDomainname("docker.io"),
 		libnetwork.JoinOptionExtraHost("web", "192.168.0.1"))
 		libnetwork.JoinOptionExtraHost("web", "192.168.0.1"))
@@ -931,7 +931,7 @@ func TestEndpointMultipleJoins(t *testing.T) {
 		}
 		}
 	}()
 	}()
 
 
-	_, err = ep.Join("container2")
+	err = ep.Join("container2")
 	if err == nil {
 	if err == nil {
 		t.Fatal("Expected to fail multiple joins for the same endpoint")
 		t.Fatal("Expected to fail multiple joins for the same endpoint")
 	}
 	}
@@ -967,7 +967,7 @@ func TestEndpointInvalidLeave(t *testing.T) {
 		}
 		}
 	}
 	}
 
 
-	_, err = ep.Join(containerID,
+	err = ep.Join(containerID,
 		libnetwork.JoinOptionHostname("test"),
 		libnetwork.JoinOptionHostname("test"),
 		libnetwork.JoinOptionDomainname("docker.io"),
 		libnetwork.JoinOptionDomainname("docker.io"),
 		libnetwork.JoinOptionExtraHost("web", "192.168.0.1"))
 		libnetwork.JoinOptionExtraHost("web", "192.168.0.1"))
@@ -1017,7 +1017,7 @@ func TestEndpointUpdateParent(t *testing.T) {
 		t.Fatal(err)
 		t.Fatal(err)
 	}
 	}
 
 
-	_, err = ep1.Join(containerID,
+	err = ep1.Join(containerID,
 		libnetwork.JoinOptionHostname("test1"),
 		libnetwork.JoinOptionHostname("test1"),
 		libnetwork.JoinOptionDomainname("docker.io"),
 		libnetwork.JoinOptionDomainname("docker.io"),
 		libnetwork.JoinOptionExtraHost("web", "192.168.0.1"))
 		libnetwork.JoinOptionExtraHost("web", "192.168.0.1"))
@@ -1037,7 +1037,7 @@ func TestEndpointUpdateParent(t *testing.T) {
 		t.Fatal(err)
 		t.Fatal(err)
 	}
 	}
 
 
-	_, err = ep2.Join("container2",
+	err = ep2.Join("container2",
 		libnetwork.JoinOptionHostname("test2"),
 		libnetwork.JoinOptionHostname("test2"),
 		libnetwork.JoinOptionDomainname("docker.io"),
 		libnetwork.JoinOptionDomainname("docker.io"),
 		libnetwork.JoinOptionHostsPath("/var/lib/docker/test_network/container2/hosts"),
 		libnetwork.JoinOptionHostsPath("/var/lib/docker/test_network/container2/hosts"),
@@ -1104,7 +1104,7 @@ func TestEnableIPv6(t *testing.T) {
 	resolvConfPath := "/tmp/libnetwork_test/resolv.conf"
 	resolvConfPath := "/tmp/libnetwork_test/resolv.conf"
 	defer os.Remove(resolvConfPath)
 	defer os.Remove(resolvConfPath)
 
 
-	_, err = ep1.Join(containerID,
+	err = ep1.Join(containerID,
 		libnetwork.JoinOptionResolvConfPath(resolvConfPath))
 		libnetwork.JoinOptionResolvConfPath(resolvConfPath))
 
 
 	if err != nil {
 	if err != nil {
@@ -1171,7 +1171,7 @@ func TestResolvConf(t *testing.T) {
 	resolvConfPath := "/tmp/libnetwork_test/resolv.conf"
 	resolvConfPath := "/tmp/libnetwork_test/resolv.conf"
 	defer os.Remove(resolvConfPath)
 	defer os.Remove(resolvConfPath)
 
 
-	_, err = ep1.Join(containerID,
+	err = ep1.Join(containerID,
 		libnetwork.JoinOptionResolvConfPath(resolvConfPath))
 		libnetwork.JoinOptionResolvConfPath(resolvConfPath))
 	if err != nil {
 	if err != nil {
 		t.Fatal(err)
 		t.Fatal(err)
@@ -1211,7 +1211,7 @@ func TestResolvConf(t *testing.T) {
 		t.Fatal(err)
 		t.Fatal(err)
 	}
 	}
 
 
-	_, err = ep1.Join(containerID,
+	err = ep1.Join(containerID,
 		libnetwork.JoinOptionResolvConfPath(resolvConfPath))
 		libnetwork.JoinOptionResolvConfPath(resolvConfPath))
 	if err != nil {
 	if err != nil {
 		t.Fatal(err)
 		t.Fatal(err)
@@ -1235,7 +1235,7 @@ func TestResolvConf(t *testing.T) {
 		t.Fatal(err)
 		t.Fatal(err)
 	}
 	}
 
 
-	_, err = ep1.Join(containerID,
+	err = ep1.Join(containerID,
 		libnetwork.JoinOptionResolvConfPath(resolvConfPath))
 		libnetwork.JoinOptionResolvConfPath(resolvConfPath))
 	if err != nil {
 	if err != nil {
 		t.Fatal(err)
 		t.Fatal(err)
@@ -1417,7 +1417,7 @@ func debugf(format string, a ...interface{}) (int, error) {
 
 
 func parallelJoin(t *testing.T, ep libnetwork.Endpoint, thrNumber int) {
 func parallelJoin(t *testing.T, ep libnetwork.Endpoint, thrNumber int) {
 	debugf("J%d.", thrNumber)
 	debugf("J%d.", thrNumber)
-	_, err := ep.Join("racing_container")
+	err := ep.Join("racing_container")
 	runtime.LockOSThread()
 	runtime.LockOSThread()
 	if err != nil {
 	if err != nil {
 		if _, ok := err.(libnetwork.ErrNoContainer); !ok {
 		if _, ok := err.(libnetwork.ErrNoContainer); !ok {