Skip to content
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: inspect network by ID #1040

Merged

Conversation

faycheng
Copy link
Contributor

@faycheng faycheng commented Apr 3, 2018

Signed-off-by: 程飞 fay.cheng.cn@gmail.com

Ⅰ. Describe what this PR did

add network inspection with network ID

Ⅱ. Does this pull request fix one issue?

Ⅲ. Describe how you did it

Ⅳ. Describe how to verify it

> pouch network inspect ab65cbdb889a6b02
{
    "Driver": "bridge",
    "ID": "ab65cbdb889a6b0218aa075a0d56b6bd1d81ffd5dcc179ba9489f749c829ffa3",
    "IPAM": {
        "Config": [
            {
                "Gateway": "172.19.0.1",
                "Subnet": "172.19.0.0/16"
            }
        ],
        "Driver": "default"
    },
    "Name": "bridge-0"
}

Ⅴ. Special notes for reviews

@codecov-io
Copy link

Codecov Report

Merging #1040 into master will decrease coverage by 0.07%.
The diff coverage is 0%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #1040      +/-   ##
==========================================
- Coverage   15.68%   15.61%   -0.08%     
==========================================
  Files         139      139              
  Lines        8499     8538      +39     
==========================================
  Hits         1333     1333              
- Misses       7066     7105      +39     
  Partials      100      100
Impacted Files Coverage Δ
daemon/mgr/network.go 3.53% <0%> (-0.42%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 800c68a...45eddc0. Read the comment docs.

return ok
}

// Get returns the information of network that specified name/id.
Copy link
Collaborator

Choose a reason for hiding this comment

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

Could you add more function Get logic in the comments to help add readability?

}
matchedNetworks := nm.GetNetworksByID(id)
if len(matchedNetworks) == 0 {
return nil, errors.Wrap(errtypes.ErrNotfound, libnetwork.ErrNoSuchNetwork(id).Error())
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 wrap this, since we have already indentify this is a libnetwork.ErrNoSuchNetwork(id).
Or remove the latter one to keep the errors.Wrap?
WDYT? @faycheng

}

if n != nil {
if err == nil {
Copy link
Collaborator

Choose a reason for hiding this comment

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

If the logic is correct, I should suggest to use return fast to avoid the large ident. Like:

if err != nil {
    return nil, err
}
return &types.Network{
     ......
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@allencloud Thanks a lot for your reviews.
I have modified the code according to your suggestions.

var matchedNetworks []*types.Network

walker := func(nw libnetwork.Network) bool {
if strings.HasPrefix(nw.ID(), id) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

I don't know why it appears the same prefix id of networks? Id is not uniquely identifies?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@rudyfly
Thanks a lot for your reviews.
id represents prefix of network ID, or full network ID, and id is renamed partialID.
Sorry for making you confused.

Signed-off-by: 程飞 <fay.cheng.cn@gmail.com>
@allencloud
Copy link
Collaborator

Could you help to make this move on? @rudyfly

@rudyfly
Copy link
Collaborator

rudyfly commented Apr 8, 2018

LGTM

@pouchrobot pouchrobot added the LGTM one maintainer or community participant agrees to merge the pull reuqest. label Apr 8, 2018
@rudyfly rudyfly merged commit f3b1c8e into AliyunContainerService:master Apr 8, 2018
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/L
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants