Skip to content

Commit 72d7486

Browse files
authored
Merge pull request kubernetes#129114 from bart0sh/PR167-fix-DRA-registration-test
kubelet: fix DRA registration test
2 parents 0634e21 + 804f8c7 commit 72d7486

File tree

1 file changed

+8
-12
lines changed

1 file changed

+8
-12
lines changed

pkg/kubelet/cm/dra/plugin/registration_test.go

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ package plugin
1919
import (
2020
"sort"
2121
"strings"
22-
"sync/atomic"
2322
"testing"
2423
"time"
2524

@@ -37,7 +36,6 @@ import (
3736
drapbv1alpha4 "k8s.io/kubelet/pkg/apis/dra/v1alpha4"
3837
drapb "k8s.io/kubelet/pkg/apis/dra/v1beta1"
3938
"k8s.io/kubernetes/test/utils/ktesting"
40-
"k8s.io/utils/ptr"
4139
)
4240

4341
const (
@@ -126,18 +124,13 @@ func TestRegistrationHandler(t *testing.T) {
126124
// Stand-alone kubelet has no connection to an
127125
// apiserver, so faking one is optional.
128126
var client kubernetes.Interface
129-
var deleteCollectionForDriver atomic.Pointer[string]
130127
if test.withClient {
128+
expectedSliceFields := fields.Set{"spec.nodeName": nodeName}
131129
fakeClient := fake.NewClientset(slice)
132130
fakeClient.AddReactor("delete-collection", "resourceslices", func(action cgotesting.Action) (bool, runtime.Object, error) {
133131
deleteAction := action.(cgotesting.DeleteCollectionAction)
134132
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)
141134
// The order of field requirements is random because it comes
142135
// from a map. We need to sort.
143136
normalize := func(selector string) string {
@@ -152,6 +145,12 @@ func TestRegistrationHandler(t *testing.T) {
152145
// Delete doesn't return an error if already deleted, which is what
153146
// we need here (no error when nothing to delete).
154147
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+
155154
return true, nil, err
156155
})
157156
client = fakeClient
@@ -211,9 +210,6 @@ func TestRegistrationHandler(t *testing.T) {
211210
// Nop.
212211
handler.DeRegisterPlugin(test.pluginName)
213212

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))
217213
requireNoSlices()
218214
})
219215
assert.Equal(t, test.endpoint, plugin.endpoint, "plugin endpoint")

0 commit comments

Comments
 (0)