@@ -19,7 +19,6 @@ package plugin
19
19
import (
20
20
"sort"
21
21
"strings"
22
- "sync/atomic"
23
22
"testing"
24
23
"time"
25
24
@@ -37,7 +36,6 @@ import (
37
36
drapbv1alpha4 "k8s.io/kubelet/pkg/apis/dra/v1alpha4"
38
37
drapb "k8s.io/kubelet/pkg/apis/dra/v1beta1"
39
38
"k8s.io/kubernetes/test/utils/ktesting"
40
- "k8s.io/utils/ptr"
41
39
)
42
40
43
41
const (
@@ -126,18 +124,13 @@ func TestRegistrationHandler(t *testing.T) {
126
124
// Stand-alone kubelet has no connection to an
127
125
// apiserver, so faking one is optional.
128
126
var client kubernetes.Interface
129
- var deleteCollectionForDriver atomic.Pointer [string ]
130
127
if test .withClient {
128
+ expectedSliceFields := fields.Set {"spec.nodeName" : nodeName }
131
129
fakeClient := fake .NewClientset (slice )
132
130
fakeClient .AddReactor ("delete-collection" , "resourceslices" , func (action cgotesting.Action ) (bool , runtime.Object , error ) {
133
131
deleteAction := action .(cgotesting.DeleteCollectionAction )
134
132
restrictions := deleteAction .GetListRestrictions ()
135
- sliceFields := fields.Set {"spec.nodeName" : nodeName }
136
- forDriver := deleteCollectionForDriver .Load ()
137
- if forDriver != nil {
138
- sliceFields ["spec.driver" ] = * forDriver
139
- }
140
- fieldsSelector := fields .SelectorFromSet (sliceFields )
133
+ fieldsSelector := fields .SelectorFromSet (expectedSliceFields )
141
134
// The order of field requirements is random because it comes
142
135
// from a map. We need to sort.
143
136
normalize := func (selector string ) string {
@@ -152,6 +145,12 @@ func TestRegistrationHandler(t *testing.T) {
152
145
// Delete doesn't return an error if already deleted, which is what
153
146
// we need here (no error when nothing to delete).
154
147
err := fakeClient .Tracker ().Delete (resourceapi .SchemeGroupVersion .WithResource ("resourceslices" ), "" , slice .Name )
148
+
149
+ // Set expected slice fields for the next call of this reactor.
150
+ // The reactor will be called next time when resourceslices object is deleted
151
+ // by the kubelet after plugin deregistration.
152
+ expectedSliceFields = fields.Set {"spec.nodeName" : nodeName , "spec.driver" : test .pluginName }
153
+
155
154
return true , nil , err
156
155
})
157
156
client = fakeClient
@@ -211,9 +210,6 @@ func TestRegistrationHandler(t *testing.T) {
211
210
// Nop.
212
211
handler .DeRegisterPlugin (test .pluginName )
213
212
214
- // Deleted by the kubelet after deregistration, now specifically
215
- // for that plugin (checked by the fake client reactor).
216
- deleteCollectionForDriver .Store (ptr .To (test .pluginName ))
217
213
requireNoSlices ()
218
214
})
219
215
assert .Equal (t , test .endpoint , plugin .endpoint , "plugin endpoint" )
0 commit comments