Skip to content

Commit 3a67bc0

Browse files
committed
kubelet: add DRA plugin name to the Plugin struct
1 parent 2048b7b commit 3a67bc0

File tree

4 files changed

+17
-11
lines changed

4 files changed

+17
-11
lines changed

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ func NewDRAPluginClient(pluginName string) (*Plugin, error) {
5151
}
5252

5353
type Plugin struct {
54+
name string
5455
backgroundCtx context.Context
5556
cancel func(cause error)
5657

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

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,9 @@ func TestGRPCConnIsReused(t *testing.T) {
114114
wg := sync.WaitGroup{}
115115
m := sync.Mutex{}
116116

117+
pluginName := "dummy-plugin"
117118
p := &Plugin{
119+
name: pluginName,
118120
backgroundCtx: tCtx,
119121
endpoint: addr,
120122
clientCallTimeout: defaultClientCallTimeout,
@@ -132,15 +134,15 @@ func TestGRPCConnIsReused(t *testing.T) {
132134
}
133135

134136
// ensure the plugin we are using is registered
135-
draPlugins.add("dummy-plugin", p)
136-
defer draPlugins.delete("dummy-plugin")
137+
draPlugins.add(p)
138+
defer draPlugins.delete(pluginName)
137139

138140
// we call `NodePrepareResource` 2 times and check whether a new connection is created or the same is reused
139141
for i := 0; i < 2; i++ {
140142
wg.Add(1)
141143
go func() {
142144
defer wg.Done()
143-
client, err := NewDRAPluginClient("dummy-plugin")
145+
client, err := NewDRAPluginClient(pluginName)
144146
if err != nil {
145147
t.Error(err)
146148
return
@@ -205,7 +207,7 @@ func TestNewDRAPluginClient(t *testing.T) {
205207
{
206208
description: "plugin exists",
207209
setup: func(name string) tearDown {
208-
draPlugins.add(name, &Plugin{})
210+
draPlugins.add(&Plugin{name: name})
209211
return func() {
210212
draPlugins.delete(name)
211213
}
@@ -251,7 +253,9 @@ func TestNodeUnprepareResources(t *testing.T) {
251253
}
252254
defer teardown()
253255

256+
pluginName := "dummy-plugin"
254257
p := &Plugin{
258+
name: pluginName,
255259
backgroundCtx: tCtx,
256260
endpoint: addr,
257261
clientCallTimeout: defaultClientCallTimeout,
@@ -268,10 +272,10 @@ func TestNodeUnprepareResources(t *testing.T) {
268272
t.Fatal(err)
269273
}
270274

271-
draPlugins.add("dummy-plugin", p)
272-
defer draPlugins.delete("dummy-plugin")
275+
draPlugins.add(p)
276+
defer draPlugins.delete(pluginName)
273277

274-
client, err := NewDRAPluginClient("dummy-plugin")
278+
client, err := NewDRAPluginClient(pluginName)
275279
if err != nil {
276280
t.Fatal(err)
277281
}

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,16 +42,16 @@ func (s *pluginsStore) get(pluginName string) *Plugin {
4242

4343
// Set lets you save a DRA Plugin to the list and give it a specific name.
4444
// This method is protected by a mutex.
45-
func (s *pluginsStore) add(pluginName string, p *Plugin) (replaced bool) {
45+
func (s *pluginsStore) add(p *Plugin) (replaced bool) {
4646
s.Lock()
4747
defer s.Unlock()
4848

4949
if s.store == nil {
5050
s.store = make(map[string]*Plugin)
5151
}
5252

53-
_, exists := s.store[pluginName]
54-
s.store[pluginName] = p
53+
_, exists := s.store[p.name]
54+
s.store[p.name] = p
5555
return exists
5656
}
5757

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,7 @@ func (h *RegistrationHandler) RegisterPlugin(pluginName string, endpoint string,
160160
ctx, cancel := context.WithCancelCause(ctx)
161161

162162
pluginInstance := &Plugin{
163+
name: pluginName,
163164
backgroundCtx: ctx,
164165
cancel: cancel,
165166
conn: nil,
@@ -170,7 +171,7 @@ func (h *RegistrationHandler) RegisterPlugin(pluginName string, endpoint string,
170171

171172
// Storing endpoint of newly registered DRA Plugin into the map, where plugin name will be the key
172173
// all other DRA components will be able to get the actual socket of DRA plugins by its name.
173-
if draPlugins.add(pluginName, pluginInstance) {
174+
if draPlugins.add(pluginInstance) {
174175
logger.V(1).Info("Already registered, previous plugin was replaced")
175176
}
176177

0 commit comments

Comments
 (0)