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

bugfix: use netNSPath dynamically #2443

Merged
merged 1 commit into from
Nov 8, 2018

Conversation

starnop
Copy link
Contributor

@starnop starnop commented Nov 7, 2018

Signed-off-by: Starnop [email protected]

Ⅰ. Describe what this PR did

The sandbox will be stopped due to various reasons ,such as the physical machine restart, if perform delete operations at this time which will cause the failure of network IP release. The reason for this is that can't find netnspath because the pid has changed and the cache has not been updated. Eventually leading to pod has been terminating and IP leakage.
So instead of using cache, we use container's pid to splice netnspath which will ensure that the netNSPath is correct.

Ⅱ. Does this pull request fix one issue?

None.

Ⅲ. Why don't you add test cases (unit test/integration test)? (你真的觉得不需要加测试吗?)

None.

Ⅳ. Describe how to verify it

Ⅴ. Special notes for reviews

@codecov
Copy link

codecov bot commented Nov 7, 2018

Codecov Report

Merging #2443 into master will increase coverage by 0.13%.
The diff coverage is 73.07%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #2443      +/-   ##
==========================================
+ Coverage   68.71%   68.84%   +0.13%     
==========================================
  Files         276      276              
  Lines       18252    18220      -32     
==========================================
+ Hits        12541    12543       +2     
+ Misses       4288     4256      -32     
+ Partials     1423     1421       -2
Flag Coverage Δ
#criv1alpha1test 31.43% <7.69%> (-0.07%) ⬇️
#criv1alpha2test 35.61% <57.69%> (+0.17%) ⬆️
#integrationtest 40.12% <0%> (-0.01%) ⬇️
#nodee2etest 33.07% <73.07%> (+0.03%) ⬆️
#unittest 26.64% <0%> (+0.05%) ⬆️
Impacted Files Coverage Δ
cri/v1alpha2/cri_types.go 100% <ø> (ø) ⬆️
cri/v1alpha2/cri_utils.go 91.17% <50%> (-0.34%) ⬇️
cri/v1alpha2/cri.go 70.03% <76.47%> (+2.64%) ⬆️
cri/ocicni/cni_manager.go 70.58% <80%> (-0.85%) ⬇️
daemon/mgr/system.go 67.93% <0%> (-5.35%) ⬇️
ctrd/watch.go 78.78% <0%> (-4.55%) ⬇️
daemon/mgr/events.go 96.29% <0%> (-3.71%) ⬇️
ctrd/client.go 66.92% <0%> (-2.31%) ⬇️
cri/v1alpha1/cri.go 60.26% <0%> (-0.34%) ⬇️
daemon/mgr/container.go 59% <0%> (ø) ⬆️
... and 7 more

@pouchrobot pouchrobot added kind/bug This is bug report for project size/L labels Nov 7, 2018
@@ -77,6 +77,9 @@ func (c *CniManager) SetUpPodNetwork(podNetwork *ocicni.PodNetwork) error {
func (c *CniManager) TearDownPodNetwork(podNetwork *ocicni.PodNetwork) error {
err := c.plugin.TearDownPod(*podNetwork)
if err != nil {
if _, err = os.Stat(podNetwork.NetNS); err != nil {
Copy link
Contributor

Choose a reason for hiding this comment

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

There is a more clear codestyle:

if err == nil {
      return nil
}

if _, err = os.Stat(podNetwork.NetNS); err != nil {
          return err
}
return fmt.Errorf("failed to destroy network for sandbox %q: %v", podNetwork.ID, err)

Decrease the nested layers is a quie important rule in clean codes

Copy link
Collaborator

Choose a reason for hiding this comment

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

agree

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Agree with that, THX.

@@ -473,10 +473,10 @@ func (c *CriManager) setupPodNetwork(ctx context.Context, id string, config *run
PortMappings: toCNIPortMappings(config.GetPortMappings()),
})
if err != nil {
return "", err
return err
Copy link
Contributor

@fengzixu fengzixu Nov 7, 2018

Choose a reason for hiding this comment

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

It seems like that there is no need to check error single. A recommended format:

if err :=  c.CniMgr.SetUpPodNetwork(&ocicni.PodNetwork{
        PortMappings: toCNIPortMappings(config.GetPortMappings()),
}); err != nil {
      return err
}

@@ -77,6 +77,9 @@ func (c *CniManager) SetUpPodNetwork(podNetwork *ocicni.PodNetwork) error {
func (c *CniManager) TearDownPodNetwork(podNetwork *ocicni.PodNetwork) error {
err := c.plugin.TearDownPod(*podNetwork)
if err != nil {
if _, err = os.Stat(podNetwork.NetNS); err != nil {
return err
}
return fmt.Errorf("failed to destroy network for sandbox %q: %v", podNetwork.ID, err)
Copy link
Collaborator

Choose a reason for hiding this comment

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

use errors.Wrapf to wrap error

@@ -77,6 +77,9 @@ func (c *CniManager) SetUpPodNetwork(podNetwork *ocicni.PodNetwork) error {
func (c *CniManager) TearDownPodNetwork(podNetwork *ocicni.PodNetwork) error {
err := c.plugin.TearDownPod(*podNetwork)
if err != nil {
if _, err = os.Stat(podNetwork.NetNS); 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.

agree

@@ -76,10 +77,14 @@ func (c *CniManager) SetUpPodNetwork(podNetwork *ocicni.PodNetwork) error {
// TearDownPodNetwork is the method called before a pod's sandbox container will be deleted.
func (c *CniManager) TearDownPodNetwork(podNetwork *ocicni.PodNetwork) error {
err := c.plugin.TearDownPod(*podNetwork)
Copy link
Contributor

Choose a reason for hiding this comment

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

how about:

if err :=  c.plugin.TearDownPod(*podNetwork); err == nil {
    return nil
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

err will be used later. So no need to change. :)

Copy link
Contributor

Choose a reason for hiding this comment

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

make sense

@rudyfly
Copy link
Collaborator

rudyfly commented Nov 8, 2018

LGTM

@pouchrobot pouchrobot added the LGTM one maintainer or community participant agrees to merge the pull reuqest. label Nov 8, 2018
@allencloud allencloud merged commit e6e9c1a into AliyunContainerService:master Nov 8, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/bug This is bug report for project 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.

6 participants