Skip to content

Conversation

@rudyfly
Copy link
Collaborator

@rudyfly rudyfly commented Apr 23, 2018

Ⅰ. Describe what this PR did

Add network connect for container.

Ⅱ. Does this pull request fix one issue?

NONE

Ⅲ. Describe how you did it

Ⅳ. Describe how to verify it

see test case: TestNetworkConnect

Ⅴ. Special notes for reviews

Signed-off-by: Rudy Zhang [email protected]
Signed-off-by: Zou Rui [email protected]

func (s *Server) connectToNetwork(ctx context.Context, rw http.ResponseWriter, req *http.Request) error {
networkIDOrName := mux.Vars(req)["id"]

net, err := s.NetworkMgr.Get(ctx, networkIDOrName)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about moving this part after request body validation. Maybe the order below will be better:

  • validation thing
  • inner logic within pouchd's manager

WDYT?

responses:
200:
description: "No error"
404:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add 400, since you have code return httputils.NewHTTPError(err, http.StatusBadRequest)

cli/network.go Outdated

// networkConnectExample shows examples in network connect command, and is used in auto-generated cli docs.
func networkConnectExample() string {
return `$ pouch network connect`
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add the output message here when success:

fmt.Printf("container %s is connected to network %s\n", container, network)

"github.com/alibaba/pouch/pkg/reference"
"github.com/alibaba/pouch/pkg/stringid"
"github.com/alibaba/pouch/pkg/utils"
"github.com/alibaba/pouch/storage/quota"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add a blank line here.

// Connect is used to connect a container to a network.
func (mgr *ContainerManager) Connect(ctx context.Context, name string, networkIDOrName string, epConfig *types.EndpointSettings) error {
c, err := mgr.container(name)
if err != nil || c == nil {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I do not think we should combine err != nil and c==nil. Because we did not output the error message in log and err.

if epConfig == nil {
epConfig = &types.EndpointSettings{}
}
c.Lock()
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this lock locked to much logic?

}

// hasUserDefinedIPAddress returns whether the passed endpoint configuration contains IP address configuration
func hasUserDefinedIPAddress(epConfig *types.EndpointSettings) bool {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This kind of function should be encapsulated in network utils or something like that. Here in container manager is quite unreasonable.

@@ -0,0 +1,19 @@
package stringid
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please add a unit test of this file. Thanks a lot.

@allencloud
Copy link
Collaborator

allencloud commented Apr 23, 2018

CI fails:

FAIL: /go/src/github.com/alibaba/pouch/test/cli_network_test.go:348: PouchNetworkSuite.TestNetworkConnect
/go/src/github.com/alibaba/pouch/test/cli_network_test.go:354:
    // create bridge device
    icmd.RunCommand("brctl", "addbr", bridgeName).Assert(c, icmd.Success)
/go/src/github.com/alibaba/pouch/vendor/github.com/gotestyourself/gotestyourself/icmd/command.go:61:
    t.Fatalf("at %s:%d - %s\n", filepath.Base(file), line, err.Error())
... Error: at cli_network_test.go:354 - 
Command:  brctl addbr p1
ExitCode: 127
Error:    exec: "brctl": executable file not found in $PATH
Stdout:   
Stderr:   
Failures:
ExitCode was 127 expected 0
Expected no error

I am wondering if it is proper to use a third-party binary to make it.
In the future , we will keep this in netlink. How about that?
@rudyfly

@rudyfly rudyfly force-pushed the network-connect branch 4 times, most recently from f7a544e to 7157116 Compare April 24, 2018 12:57
@codecov-io
Copy link

Codecov Report

Merging #1187 into master will decrease coverage by 0.26%.
The diff coverage is 0%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #1187      +/-   ##
==========================================
- Coverage   16.03%   15.76%   -0.27%     
==========================================
  Files         176      177       +1     
  Lines       10155    10327     +172     
==========================================
  Hits         1628     1628              
- Misses       8407     8579     +172     
  Partials      120      120
Impacted Files Coverage Δ
pkg/utils/utils.go 77.03% <0%> (+1.12%) ⬆️
daemon/mgr/network_utils.go 0% <0%> (ø) ⬆️
apis/server/router.go 0% <0%> (ø) ⬆️
cli/network.go 0% <0%> (ø) ⬆️
client/network_connect.go 0% <0%> (ø)
apis/server/network_bridge.go 0% <0%> (ø) ⬆️
daemon/mgr/container.go 0% <0%> (ø) ⬆️

Restart(ctx context.Context, name string, timeout int64) error

// Connect is used to connect a container to a network.
Connect(ctx context.Context, name string, networkIDOrName string, epConfig *types.EndpointSettings) error
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Connect or ConnectContainerToNetwork ?

Disconnect or DisconnectContainerFromNetwork ?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think short function name is more better, write the detail information in comments is ok.

Add network connect for container.

Signed-off-by: Rudy Zhang <[email protected]>
Signed-off-by: Zou Rui <[email protected]>
@HusterWan
Copy link
Contributor

LGTM

@pouchrobot pouchrobot added the LGTM one maintainer or community participant agrees to merge the pull reuqest. label Apr 25, 2018
@HusterWan HusterWan merged commit 0713c83 into AliyunContainerService:master Apr 25, 2018
@rudyfly rudyfly mentioned this pull request Apr 25, 2018
2 tasks
@rudyfly rudyfly deleted the network-connect branch October 29, 2018 09:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

areas/network kind/feature LGTM one maintainer or community participant agrees to merge the pull reuqest. size/XL

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants