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

flannel: remove net conf file after DEL succeed #449

Merged
merged 1 commit into from
Aug 26, 2020

Conversation

mars1024
Copy link
Member

@mars1024 mars1024 commented Feb 4, 2020

consumeScratchNetConf will remove net conf file in defer, so if invoke.DelegateDel fails and CNI DEL is called again, it will always be successful because net conf file has been removed already.

So I think the better way is to remove net conf file after invoke.DelegateDel succeed, this will make sure the CNI DEL retry will go through invoke.DelegateDel every time.

Signed-off-by: Bruce Ma [email protected]

plugins/meta/flannel/flannel_linux.go Outdated Show resolved Hide resolved
plugins/meta/flannel/flannel_windows.go Outdated Show resolved Hide resolved
@@ -78,10 +78,18 @@ func doCmdDel(args *skel.CmdArgs, n *NetConf) error {
return err
}

defer func() {
// remove net conf after DEL succeed
if err == nil {
Copy link
Member Author

Choose a reason for hiding this comment

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

To make the return of invoke.DelegateDel can be judged here, @jellonek

Copy link
Contributor

Choose a reason for hiding this comment

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

You could avoid this by having (err error) as the return, i.e. a named return variable, and changing err := to err =. Both are pretty subtle points of Go behaviour.

Copy link
Member Author

Choose a reason for hiding this comment

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

thanks, will update this


return ioutil.ReadFile(path)
// cleanup should be called after DEL succeed
cleanup := func() {
Copy link
Contributor

Choose a reason for hiding this comment

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

if you set this to a no-op function on error then the caller can do cleanup() every time; doesn't have to know the coupling between error and cleanup.

Copy link
Member Author

Choose a reason for hiding this comment

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

got it, thanks!

@mars1024 mars1024 force-pushed the bugfix/flannel_clean branch from 64d0fd0 to b0c42ce Compare February 12, 2020 13:03
@mars1024
Copy link
Member Author

Although the DEL retry mechanism of kubelet is disturbing something, but I still think the idempotency of each retry is important in CNI plugins. To avoid leaking or some wrong error messages.

@@ -65,10 +65,13 @@ func doCmdDel(args *skel.CmdArgs, n *NetConf) error {
return err
}

// cleanup will work when no error happens
defer cleanup(err)
Copy link
Contributor

Choose a reason for hiding this comment

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

I think this doesn't work because it gets the value of err at the time control passes through this line.
See https://play.golang.org/p/3W5_yxRJJ_6 vs https://play.golang.org/p/-9c9Z3pvVFO

Copy link
Member

@dcbw dcbw Feb 12, 2020

Choose a reason for hiding this comment

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

The alternative is to make your cleanup function take a pointer to the error, and then defer cleanup(&err) and then it'll work :) https://play.golang.org/p/KUTcEEMB--n

But Brian thinks this is terrible and he's not wrong.

Copy link
Member Author

Choose a reason for hiding this comment

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

updated, thanks!

@mars1024 mars1024 force-pushed the bugfix/flannel_clean branch from b0c42ce to 53854dd Compare February 19, 2020 13:00
@mars1024
Copy link
Member Author

updated, PTAL, thanks ~

@dcbw
Copy link
Member

dcbw commented Aug 26, 2020

/lgtm

@dcbw dcbw merged commit 9b8de6a into containernetworking:master Aug 26, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants