Skip to content

Commit f15a491

Browse files
committed
Fix typos in log line. Add additional code comments.
1 parent 787e783 commit f15a491

File tree

4 files changed

+18
-8
lines changed

4 files changed

+18
-8
lines changed

go.mod

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ require (
1313
github.com/google/go-cmp v0.6.0
1414
github.com/google/uuid v1.6.0
1515
github.com/googleapis/gax-go/v2 v2.12.4
16+
github.com/hashicorp/golang-lru/v2 v2.0.7
1617
github.com/kubernetes-csi/csi-proxy/client v1.1.3
1718
github.com/kubernetes-csi/csi-test/v5 v5.3.0
1819
github.com/onsi/ginkgo/v2 v2.20.1
@@ -76,7 +77,6 @@ require (
7677
github.com/grpc-ecosystem/grpc-gateway/v2 v2.16.0 // indirect
7778
github.com/hashicorp/errwrap v1.0.0 // indirect
7879
github.com/hashicorp/go-multierror v1.1.0 // indirect
79-
github.com/hashicorp/golang-lru/v2 v2.0.7 // indirect
8080
github.com/imdario/mergo v0.3.12 // indirect
8181
github.com/josharian/intern v1.0.0 // indirect
8282
github.com/json-iterator/go v1.1.12 // indirect

pkg/gce-pd-csi-driver/device_error_map.go

+6-3
Original file line numberDiff line numberDiff line change
@@ -46,14 +46,17 @@ func newDeviceErrMap(timeout time.Duration) *deviceErrMap {
4646
}
4747
}
4848

49-
// checkDeviceErrorTimeout returns true an error was encountered for the specified deviceName,
50-
// where the error happened at least `deviceInUseTimeout` seconds ago.
51-
func (devErrMap *deviceErrMap) checkDeviceErrorTimeout(deviceName string) bool {
49+
// deviceErrorExpired returns true if an error for the specified device is expired,
50+
// where the expiration is specified by `--device-in-use-timeout`
51+
func (devErrMap *deviceErrMap) deviceErrorExpired(deviceName string) bool {
5252
devErrMap.mux.Lock()
5353
defer devErrMap.mux.Unlock()
5454

5555
firstEncounteredErrTime, exists := devErrMap.cache.Get(deviceName)
5656
if !exists {
57+
// If the deviceName does not exist in the map, then this is the first time
58+
// an error was encountered for that device. We return false since it cannot be
59+
// expired yet.
5760
return false
5861
}
5962
expirationTime := firstEncounteredErrTime.Add(devErrMap.timeout)

pkg/gce-pd-csi-driver/device_error_map_test.go

+9-2
Original file line numberDiff line numberDiff line change
@@ -28,17 +28,24 @@ func TestDeviceErrorMap(t *testing.T) {
2828
// Register an error. Checking the timeout right after should return false
2929
stubCurrentTime(0)
3030
eMap.markDeviceError(dName)
31-
isTimedOut := eMap.checkDeviceErrorTimeout(dName)
31+
isTimedOut := eMap.deviceErrorExpired(dName)
3232
if isTimedOut {
3333
t.Errorf("checkDeviceErrorTimeout expected to be false if called immediately after marking an error")
3434
}
3535

3636
// Advance time. Checking the timeout should now return true
3737
stubCurrentTime(int64(timeout.Seconds()) + 1)
38-
isTimedOut = eMap.checkDeviceErrorTimeout(dName)
38+
isTimedOut = eMap.deviceErrorExpired(dName)
3939
if !isTimedOut {
4040
t.Errorf("checkDeviceErrorTimeout expected to be true after waiting for timeout")
4141
}
42+
43+
// Deleting the device and checking the timout should return false
44+
eMap.deleteDevice(dName)
45+
isTimedOut = eMap.deviceErrorExpired(dName)
46+
if isTimedOut {
47+
t.Errorf("checkDeviceErrorTimeout expected to be false after deleting device from map")
48+
}
4249
}
4350

4451
func stubCurrentTime(unixTime int64) {

pkg/gce-pd-csi-driver/node.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -475,8 +475,8 @@ func (ns *GCENodeServer) NodeUnstageVolume(ctx context.Context, req *csi.NodeUns
475475
if err := ns.confirmDeviceUnused(volumeID); err != nil {
476476
var ignoreableErr *ignoreableError
477477
if errors.As(err, &ignoreableErr) {
478-
klog.Warningf("Unabled to check if device for %s is unused. Device has been unmounted successfully. Ignoring and continuing with unstaging. (%v)", volumeID, err)
479-
} else if ns.deviceInUseErrors.checkDeviceErrorTimeout(volumeID) {
478+
klog.Warningf("Unable to check if device for %s is unused. Device has been unmounted successfully. Ignoring and continuing with unstaging. (%v)", volumeID, err)
479+
} else if ns.deviceInUseErrors.deviceErrorExpired(volumeID) {
480480
klog.Warningf("Device %s could not be released after timeout of %f seconds. NodeUnstageVolume will return success.", volumeID, ns.deviceInUseErrors.timeout.Seconds())
481481
} else {
482482
ns.deviceInUseErrors.markDeviceError(volumeID)

0 commit comments

Comments
 (0)