Skip to content

Commit 3f192af

Browse files
authored
Handle DeletedFinalStateUnknown in csiNodeDelete (#3490)
1 parent 5c3d342 commit 3f192af

File tree

1 file changed

+16
-4
lines changed

1 file changed

+16
-4
lines changed

pkg/common/cns-lib/node/nodes.go

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import (
2121
"fmt"
2222

2323
storagev1 "k8s.io/api/storage/v1"
24+
"k8s.io/client-go/tools/cache"
2425

2526
cnsvsphere "sigs.k8s.io/vsphere-csi-driver/v3/pkg/common/cns-lib/vsphere"
2627
"sigs.k8s.io/vsphere-csi-driver/v3/pkg/csi/service/logger"
@@ -113,10 +114,21 @@ func (nodes *Nodes) csiNodeUpdate(oldObj interface{}, newObj interface{}) {
113114

114115
func (nodes *Nodes) csiNodeDelete(obj interface{}) {
115116
ctx, log := logger.GetNewContextWithLogger()
116-
csiNode, ok := obj.(*storagev1.CSINode)
117-
if csiNode == nil || !ok {
118-
log.Warnf("csiNodeDelete: unrecognized object %+v", obj)
119-
return
117+
var csiNode *storagev1.CSINode
118+
var ok bool
119+
// Try direct type assertion first
120+
if csiNode, ok = obj.(*storagev1.CSINode); !ok {
121+
// Might be a tombstone if object is not found in the cache
122+
tombstone, ok := obj.(cache.DeletedFinalStateUnknown)
123+
if !ok {
124+
log.Warnf("csiNodeDelete: unrecognized object %#v", obj)
125+
return
126+
}
127+
// Try extracting CSINode from tombstone
128+
if csiNode, ok = tombstone.Obj.(*storagev1.CSINode); !ok {
129+
log.Warnf("csiNodeDelete: tombstone contained object that is not a CSINode: %#v", tombstone.Obj)
130+
return
131+
}
120132
}
121133
nodeName := csiNode.Name
122134
err := nodes.cnsNodeManager.UnregisterNode(ctx, nodeName)

0 commit comments

Comments
 (0)