Skip to content

Commit 3510ac4

Browse files
no need to remove lock files on reboot (#1041)
1 parent 5882752 commit 3510ac4

File tree

4 files changed

+7
-47
lines changed

4 files changed

+7
-47
lines changed

cni/plugin.go

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -161,9 +161,6 @@ func (plugin *Plugin) InitializeKeyValueStore(config *common.PluginConfig) error
161161
log.Printf("[cni] Failed to create store: %v.", err)
162162
return err
163163
}
164-
165-
// Force unlock the json store if the lock file is left on the node after reboot
166-
removeLockFileAfterReboot(plugin)
167164
}
168165

169166
// Acquire store lock.

cni/plugin_linux.go

Lines changed: 0 additions & 11 deletions
This file was deleted.

cni/plugin_windows.go

Lines changed: 0 additions & 22 deletions
This file was deleted.

store/json.go

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -176,16 +176,20 @@ func (kvs *jsonFileStore) flush() error {
176176

177177
// Lock locks the store for exclusive access.
178178
func (kvs *jsonFileStore) Lock(block bool) error {
179+
var (
180+
lockFile *os.File
181+
err error
182+
)
183+
179184
kvs.Mutex.Lock()
180185
defer kvs.Mutex.Unlock()
181186

182187
if kvs.locked {
183188
return ErrStoreLocked
184189
}
185190

186-
var lockFile *os.File
187-
var err error
188-
lockPerm := os.FileMode(0o664) + os.FileMode(os.ModeExclusive)
191+
//nolint:gomnd // 0o664 - read write mode constant
192+
lockPerm := os.FileMode(0o644) + os.FileMode(os.ModeExclusive)
189193

190194
// Try to acquire the lock file.
191195
var lockRetryCount uint
@@ -270,14 +274,6 @@ func (kvs *jsonFileStore) GetLockFileModificationTime() (time.Time, error) {
270274
kvs.Mutex.Lock()
271275
defer kvs.Mutex.Unlock()
272276

273-
// Check if the file exists.
274-
file, err := os.Open(kvs.lockFileName)
275-
if err != nil {
276-
return time.Time{}.UTC(), err
277-
}
278-
279-
defer file.Close()
280-
281277
info, err := os.Stat(kvs.lockFileName)
282278
if err != nil {
283279
log.Printf("os.stat() for file %v failed: %v", kvs.lockFileName, err)

0 commit comments

Comments
 (0)