-
Notifications
You must be signed in to change notification settings - Fork 159
Force timeout nodeunstagevolume #1918
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
Merged
pwschuurman
merged 6 commits into
kubernetes-sigs:master
from
davis-haba:force-timeout-nodeunstagevolume
Feb 11, 2025
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
d0479f6
Add logic to force release volume in NodeUnstageVolume if it has not …
davis-haba bd634b8
Make deviceInUseErrors atomic. Make deviceInUseTimeout a CLI flag
davis-haba fa19cb0
Add flag to enable deviceInUseTimeout. Pass args through NodeServer c…
davis-haba 569e29e
Use LRU for deviceInUse map. Disable device in use checks entirely if…
davis-haba 787e783
Set expiration for keys in deviceInUse cache. Add unit test.
davis-haba f15a491
Fix typos in log line. Add additional code comments.
davis-haba File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
/* | ||
Copyright 2018 The Kubernetes Authors. | ||
|
||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
package gceGCEDriver | ||
|
||
import ( | ||
"sync" | ||
"time" | ||
|
||
"github.com/hashicorp/golang-lru/v2/expirable" | ||
"k8s.io/klog/v2" | ||
) | ||
|
||
// maxDeviceCacheSize specifies the maximum number if in-use devices to cache. | ||
// 256 was selected since it is twice the number of max PDs per VM (128) | ||
const maxDeviceCacheSize = 256 | ||
|
||
// currentTime is used to stub time.Now in unit tests | ||
var currentTime = time.Now | ||
|
||
// deviceErrMap is an atomic data datastructure for recording deviceInUseError times | ||
// for specified devices | ||
type deviceErrMap struct { | ||
timeout time.Duration | ||
mux sync.Mutex | ||
cache *expirable.LRU[string, time.Time] | ||
} | ||
|
||
func newDeviceErrMap(timeout time.Duration) *deviceErrMap { | ||
c := expirable.NewLRU[string, time.Time](maxDeviceCacheSize, nil, timeout*2) | ||
|
||
return &deviceErrMap{ | ||
cache: c, | ||
timeout: timeout, | ||
} | ||
} | ||
|
||
// deviceErrorExpired returns true if an error for the specified device is expired, | ||
// where the expiration is specified by `--device-in-use-timeout` | ||
func (devErrMap *deviceErrMap) deviceErrorExpired(deviceName string) bool { | ||
devErrMap.mux.Lock() | ||
defer devErrMap.mux.Unlock() | ||
|
||
firstEncounteredErrTime, exists := devErrMap.cache.Get(deviceName) | ||
if !exists { | ||
davis-haba marked this conversation as resolved.
Show resolved
Hide resolved
|
||
// If the deviceName does not exist in the map, then this is the first time | ||
// an error was encountered for that device. We return false since it cannot be | ||
// expired yet. | ||
return false | ||
} | ||
expirationTime := firstEncounteredErrTime.Add(devErrMap.timeout) | ||
return currentTime().After(expirationTime) | ||
} | ||
|
||
// markDeviceError updates the internal `cache` map to denote an error was encounted | ||
// for the specified deviceName at the current time. If an error had previously been recorded, the | ||
// time will not be updated. | ||
func (devErrMap *deviceErrMap) markDeviceError(deviceName string) { | ||
devErrMap.mux.Lock() | ||
defer devErrMap.mux.Unlock() | ||
|
||
// If an earlier error has already been recorded, do not overwrite it | ||
if _, exists := devErrMap.cache.Get(deviceName); !exists { | ||
now := currentTime() | ||
klog.V(4).Infof("Recording in-use error for device %s at time %s", deviceName, now) | ||
devErrMap.cache.Add(deviceName, now) | ||
} | ||
} | ||
|
||
// deleteDevice removes a specified device name from the map | ||
func (devErrMap *deviceErrMap) deleteDevice(deviceName string) { | ||
devErrMap.mux.Lock() | ||
defer devErrMap.mux.Unlock() | ||
devErrMap.cache.Remove(deviceName) | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
/* | ||
Copyright 2018 The Kubernetes Authors. | ||
|
||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
package gceGCEDriver | ||
|
||
import ( | ||
"testing" | ||
"time" | ||
) | ||
|
||
func TestDeviceErrorMap(t *testing.T) { | ||
timeout := time.Second * 10 | ||
dName := "fake-device" | ||
eMap := newDeviceErrMap(timeout) | ||
defer func() { currentTime = time.Now }() | ||
|
||
// Register an error. Checking the timeout right after should return false | ||
stubCurrentTime(0) | ||
eMap.markDeviceError(dName) | ||
isTimedOut := eMap.deviceErrorExpired(dName) | ||
if isTimedOut { | ||
t.Errorf("checkDeviceErrorTimeout expected to be false if called immediately after marking an error") | ||
} | ||
|
||
// Advance time. Checking the timeout should now return true | ||
stubCurrentTime(int64(timeout.Seconds()) + 1) | ||
isTimedOut = eMap.deviceErrorExpired(dName) | ||
if !isTimedOut { | ||
t.Errorf("checkDeviceErrorTimeout expected to be true after waiting for timeout") | ||
} | ||
|
||
// Deleting the device and checking the timout should return false | ||
eMap.deleteDevice(dName) | ||
isTimedOut = eMap.deviceErrorExpired(dName) | ||
if isTimedOut { | ||
t.Errorf("checkDeviceErrorTimeout expected to be false after deleting device from map") | ||
} | ||
} | ||
|
||
func stubCurrentTime(unixTime int64) { | ||
currentTime = func() time.Time { | ||
return time.Unix(unixTime, 0) | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.