Skip to content

Conversation

@tamilmani1989
Copy link
Member

Reason for Change:

Issue Fixed:

Requirements:

Notes:

@tamilmani1989 tamilmani1989 requested review from neaggarwMS and rbtr July 10, 2021 01:07
// acquire cni lock file
config := &common.PluginConfig{}
acquireLockForStore(config, plugin)
defer releaseLockForStore(plugin)
Copy link
Member

Choose a reason for hiding this comment

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

defer releaseLockForStore(plugin)

Shouldnt this be above acquire, always safe to release in case it got acquired above and failed after

Copy link
Member Author

Choose a reason for hiding this comment

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

nope not needed, if this fails no need to unlock

common.LogNetworkInterfaces()

// Initialize network manager.
err = plugin.nm.Initialize(config, rehydrateNetworkInfoOnReboot)
Copy link
Member

@neaggarwMS neaggarwMS Jul 12, 2021

Choose a reason for hiding this comment

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

Why did we move this? #Resolved

Copy link
Member Author

Choose a reason for hiding this comment

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

we restore state inside this call which we have to do after lock

Copy link
Member

@neaggarwMS neaggarwMS left a comment

Choose a reason for hiding this comment

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

🕐

neaggarwMS
neaggarwMS previously approved these changes Jul 12, 2021
Copy link
Member

@neaggarwMS neaggarwMS left a comment

Choose a reason for hiding this comment

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

:shipit:

@tamilmani1989
Copy link
Member Author

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

Comment on lines +299 to +300
var err error
if err = plugin.Store.Lock(true); 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.

following this err is hard. it might be better to make this a one-line declaration/initialization (if err := ...; err != nil) and in the nested ifs below, explicitly return err or nil early instead of sometimes setting err = nil and returning err at the end of the function.

Copy link
Member Author

@tamilmani1989 tamilmani1989 Jul 12, 2021

Choose a reason for hiding this comment

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

i wanted to avoid multiple returns but i agree it affects readability. Let me redesign this a bit

Copy link
Collaborator

Choose a reason for hiding this comment

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

multiple returns are okay, in go it's encouraged to return early when you can. returning early on errors lets us keep the code linear and not need to nest it as deeply.

// restore network state
err = plugin.nm.Initialize(config, rehydrateNetworkInfoOnReboot)
if err != nil {
log.Printf("[cni-net] Failed to initialize network manager, err:%v.", err)
Copy link
Collaborator

Choose a reason for hiding this comment

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

for readability i would like to see space in err:%v. -> err: %v., but that applies to the whole codebase so i won't block for that

@tamilmani1989 tamilmani1989 merged commit 6079bf3 into Azure:master Jul 12, 2021
tamilmani1989 added a commit that referenced this pull request Jul 13, 2021
tamilmani1989 added a commit that referenced this pull request Jul 14, 2021
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.

3 participants