-
Notifications
You must be signed in to change notification settings - Fork 949
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
bugfix: use netNSPath dynamically #2443
Conversation
Codecov Report
@@ 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
|
a8ee4f1
to
aee86dc
Compare
cri/ocicni/cni_manager.go
Outdated
@@ -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 { |
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.
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
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.
agree
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.
Agree with that, THX.
cri/v1alpha2/cri_utils.go
Outdated
@@ -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 |
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.
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
}
aee86dc
to
6f53348
Compare
cri/ocicni/cni_manager.go
Outdated
@@ -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) |
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.
use errors.Wrapf
to wrap error
cri/ocicni/cni_manager.go
Outdated
@@ -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 { |
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.
agree
6f53348
to
b000337
Compare
@@ -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) |
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:
if err := c.plugin.TearDownPod(*podNetwork); err == nil {
return 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.
err
will be used later. So no need to change. :)
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.
make sense
Signed-off-by: Starnop <[email protected]>
b000337
to
04bf872
Compare
LGTM |
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