@@ -21,6 +21,7 @@ import (
21
21
"fmt"
22
22
23
23
storagev1 "k8s.io/api/storage/v1"
24
+ "k8s.io/client-go/tools/cache"
24
25
25
26
cnsvsphere "sigs.k8s.io/vsphere-csi-driver/v3/pkg/common/cns-lib/vsphere"
26
27
"sigs.k8s.io/vsphere-csi-driver/v3/pkg/csi/service/logger"
@@ -113,10 +114,21 @@ func (nodes *Nodes) csiNodeUpdate(oldObj interface{}, newObj interface{}) {
113
114
114
115
func (nodes * Nodes ) csiNodeDelete (obj interface {}) {
115
116
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
+ }
120
132
}
121
133
nodeName := csiNode .Name
122
134
err := nodes .cnsNodeManager .UnregisterNode (ctx , nodeName )
0 commit comments