-
Notifications
You must be signed in to change notification settings - Fork 260
removed lock for version command #929
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
Changes from all commits
36b04ff
1651765
96c9ba9
0a802d9
91bf31d
a342c91
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -41,6 +41,7 @@ const ( | |
| ipVersion = "4" | ||
| ipamV6 = "azure-vnet-ipamv6" | ||
| defaultRequestTimeout = 15 * time.Second | ||
| azureCniName = "azure-vnet" | ||
| ) | ||
|
|
||
| // CNI Operation Types | ||
|
|
@@ -145,12 +146,6 @@ func (plugin *netPlugin) Start(config *common.PluginConfig) error { | |
| common.LogNetworkInterfaces() | ||
|
|
||
| // Initialize network manager. | ||
| err = plugin.nm.Initialize(config, rehydrateNetworkInfoOnReboot) | ||
| if err != nil { | ||
| log.Printf("[cni-net] Failed to initialize network manager, err:%v.", err) | ||
| return err | ||
| } | ||
|
|
||
| log.Printf("[cni-net] Plugin started.") | ||
|
|
||
| return nil | ||
|
|
@@ -282,7 +277,6 @@ func (plugin *netPlugin) setCNIReportDetails(nwCfg *cni.NetworkConfig, opType st | |
| plugin.report.SubContext = fmt.Sprintf("%+v", nwCfg) | ||
| plugin.report.EventMessage = msg | ||
| plugin.report.BridgeDetails.NetworkMode = nwCfg.Mode | ||
| plugin.report.InterfaceDetails.SecondaryCAUsedCount = plugin.nm.GetNumberOfEndpoints("", nwCfg.Name) | ||
| } | ||
|
|
||
| func addNatIPV6SubnetInfo(nwCfg *cni.NetworkConfig, | ||
|
|
@@ -301,6 +295,33 @@ func addNatIPV6SubnetInfo(nwCfg *cni.NetworkConfig, | |
| } | ||
| } | ||
|
|
||
| func acquireLockForStore(config *common.PluginConfig, plugin *netPlugin) error { | ||
tamilmani1989 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| var err error | ||
| if err = plugin.Store.Lock(true); err != nil { | ||
|
Comment on lines
+299
to
+300
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 (
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. |
||
| log.Printf("[CNI] Failed to lock store: %v. check if process running", err) | ||
| if isSafe, _ := plugin.IsSafeToRemoveLock(azureCniName); isSafe { | ||
| log.Printf("[CNI] Removing lock file as process holding lock exited") | ||
| if err = releaseLockForStore(plugin); err != nil { | ||
| log.Errorf("Failed to release lock file, err:%v.\n", err) | ||
| } | ||
| } | ||
| } | ||
|
|
||
| return err | ||
| } | ||
|
|
||
| func releaseLockForStore(plugin *netPlugin) error { | ||
rbtr marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| if plugin.Store != nil { | ||
| err := plugin.Store.Unlock(false) | ||
| if err != nil { | ||
| log.Printf("[cni] Failed to unlock store: %v.", err) | ||
| return err | ||
rbtr marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| } | ||
| } | ||
|
|
||
| log.Printf("Released lock file") | ||
| return nil | ||
| } | ||
| // | ||
| // CNI implementation | ||
| // https://github.com/containernetworking/cni/blob/master/SPEC.md | ||
|
|
@@ -349,6 +370,22 @@ func (plugin *netPlugin) Add(args *cniSkel.CmdArgs) error { | |
| iptables.DisableIPTableLock = nwCfg.DisableIPTableLock | ||
| plugin.setCNIReportDetails(nwCfg, CNI_ADD, "") | ||
|
|
||
| // acquire cni lock file | ||
| // TODO: check if we need pluginconfig and if not remove it | ||
| config := &common.PluginConfig{Store: plugin.Store} | ||
| if err := acquireLockForStore(config, plugin); err != nil { | ||
| log.Errorf("Couldn't acquire lock: %+v", err) | ||
| return err | ||
| } | ||
|
|
||
| defer releaseLockForStore(plugin) | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nope not needed, if this fails no need to unlock |
||
|
|
||
| // restore network state | ||
| if err = plugin.nm.Initialize(config, rehydrateNetworkInfoOnReboot); err != nil { | ||
| log.Printf("[cni-net] Failed to initialize network manager, err:%+v.", err) | ||
| return err | ||
| } | ||
|
|
||
| defer func() { | ||
| operationTimeMs := time.Since(startTime).Milliseconds() | ||
| cniMetric.Metric = aitelemetry.Metric{ | ||
|
|
@@ -774,6 +811,20 @@ func (plugin *netPlugin) Get(args *cniSkel.CmdArgs) error { | |
|
|
||
| iptables.DisableIPTableLock = nwCfg.DisableIPTableLock | ||
|
|
||
| config := &common.PluginConfig{Store: plugin.Store} | ||
| if err := acquireLockForStore(config, plugin); err != nil { | ||
| log.Errorf("Couldn't acquire lock: %+v", err) | ||
| return err | ||
| } | ||
|
|
||
| defer releaseLockForStore(plugin) | ||
|
|
||
| // restore network state | ||
| if err = plugin.nm.Initialize(config, rehydrateNetworkInfoOnReboot); err != nil { | ||
| log.Printf("[cni-net] Failed to initialize network manager, err:%+v.", err) | ||
| return err | ||
| } | ||
|
|
||
| // Parse Pod arguments. | ||
| if k8sPodName, k8sNamespace, err = plugin.getPodInfo(args.Args); err != nil { | ||
| return err | ||
|
|
@@ -859,6 +910,21 @@ func (plugin *netPlugin) Delete(args *cniSkel.CmdArgs) error { | |
|
|
||
| log.Printf("[cni-net] Read network configuration %+v.", nwCfg) | ||
|
|
||
| // acquire cni lock file | ||
| config := &common.PluginConfig{Store: plugin.Store} | ||
| if err := acquireLockForStore(config, plugin); err != nil { | ||
| log.Errorf("Couldn't acquire lock: %+v", err) | ||
| return err | ||
| } | ||
|
|
||
| defer releaseLockForStore(plugin) | ||
|
|
||
| // restore network state | ||
| if err = plugin.nm.Initialize(config, rehydrateNetworkInfoOnReboot); err != nil { | ||
| log.Printf("[cni-net] Failed to initialize network manager, err:%+v.", err) | ||
| return err | ||
| } | ||
|
|
||
| // Parse Pod arguments. | ||
| if k8sPodName, k8sNamespace, err = plugin.getPodInfo(args.Args); err != nil { | ||
| log.Printf("[cni-net] Failed to get POD info due to error: %v", err) | ||
|
|
@@ -1021,6 +1087,21 @@ func (plugin *netPlugin) Update(args *cniSkel.CmdArgs) error { | |
| iptables.DisableIPTableLock = nwCfg.DisableIPTableLock | ||
| plugin.setCNIReportDetails(nwCfg, CNI_UPDATE, "") | ||
|
|
||
| // acquire cni lock file | ||
| config := &common.PluginConfig{Store: plugin.Store} | ||
| if err := acquireLockForStore(config, plugin); err != nil { | ||
| log.Errorf("Couldn't acquire lock: %+v", err) | ||
| return err | ||
| } | ||
|
|
||
| defer releaseLockForStore(plugin) | ||
|
|
||
| // restore network state | ||
| if err = plugin.nm.Initialize(config, rehydrateNetworkInfoOnReboot); err != nil { | ||
| log.Printf("[cni-net] Failed to initialize network manager, err:%+v.", err) | ||
| return err | ||
| } | ||
|
|
||
| defer func() { | ||
| operationTimeMs := time.Since(startTime).Milliseconds() | ||
| cniMetric.Metric = aitelemetry.Metric{ | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.
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.
Why did we move this? #Resolved
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.
we restore state inside this call which we have to do after lock