-
Notifications
You must be signed in to change notification settings - Fork 943
feature: add network connect for container #1187
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feature: add network connect for container #1187
Conversation
b05f9a2 to
10fbafe
Compare
apis/server/network_bridge.go
Outdated
| 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) |
There was a problem hiding this comment.
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: |
There was a problem hiding this comment.
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` |
There was a problem hiding this comment.
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" |
There was a problem hiding this comment.
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.
daemon/mgr/container.go
Outdated
| // 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 { |
There was a problem hiding this comment.
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() |
There was a problem hiding this comment.
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?
daemon/mgr/container.go
Outdated
| } | ||
|
|
||
| // hasUserDefinedIPAddress returns whether the passed endpoint configuration contains IP address configuration | ||
| func hasUserDefinedIPAddress(epConfig *types.EndpointSettings) bool { |
There was a problem hiding this comment.
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.
pkg/stringid/stringid.go
Outdated
| @@ -0,0 +1,19 @@ | |||
| package stringid | |||
There was a problem hiding this comment.
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.
|
CI fails: I am wondering if it is proper to use a third-party binary to make it. |
f7a544e to
7157116
Compare
Codecov Report
@@ 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
|
| 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 |
There was a problem hiding this comment.
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 ?
There was a problem hiding this comment.
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.
7157116 to
e3885ef
Compare
Add network connect for container. Signed-off-by: Rudy Zhang <[email protected]> Signed-off-by: Zou Rui <[email protected]>
e3885ef to
ecba8a4
Compare
|
LGTM |
Ⅰ. 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]