mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-04 09:49:50 +00:00
kubelet: add DRA plugin name to the Plugin struct
This commit is contained in:
parent
2048b7b8fd
commit
3a67bc0def
@ -51,6 +51,7 @@ func NewDRAPluginClient(pluginName string) (*Plugin, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type Plugin struct {
|
type Plugin struct {
|
||||||
|
name string
|
||||||
backgroundCtx context.Context
|
backgroundCtx context.Context
|
||||||
cancel func(cause error)
|
cancel func(cause error)
|
||||||
|
|
||||||
|
@ -114,7 +114,9 @@ func TestGRPCConnIsReused(t *testing.T) {
|
|||||||
wg := sync.WaitGroup{}
|
wg := sync.WaitGroup{}
|
||||||
m := sync.Mutex{}
|
m := sync.Mutex{}
|
||||||
|
|
||||||
|
pluginName := "dummy-plugin"
|
||||||
p := &Plugin{
|
p := &Plugin{
|
||||||
|
name: pluginName,
|
||||||
backgroundCtx: tCtx,
|
backgroundCtx: tCtx,
|
||||||
endpoint: addr,
|
endpoint: addr,
|
||||||
clientCallTimeout: defaultClientCallTimeout,
|
clientCallTimeout: defaultClientCallTimeout,
|
||||||
@ -132,15 +134,15 @@ func TestGRPCConnIsReused(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// ensure the plugin we are using is registered
|
// ensure the plugin we are using is registered
|
||||||
draPlugins.add("dummy-plugin", p)
|
draPlugins.add(p)
|
||||||
defer draPlugins.delete("dummy-plugin")
|
defer draPlugins.delete(pluginName)
|
||||||
|
|
||||||
// we call `NodePrepareResource` 2 times and check whether a new connection is created or the same is reused
|
// we call `NodePrepareResource` 2 times and check whether a new connection is created or the same is reused
|
||||||
for i := 0; i < 2; i++ {
|
for i := 0; i < 2; i++ {
|
||||||
wg.Add(1)
|
wg.Add(1)
|
||||||
go func() {
|
go func() {
|
||||||
defer wg.Done()
|
defer wg.Done()
|
||||||
client, err := NewDRAPluginClient("dummy-plugin")
|
client, err := NewDRAPluginClient(pluginName)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Error(err)
|
t.Error(err)
|
||||||
return
|
return
|
||||||
@ -205,7 +207,7 @@ func TestNewDRAPluginClient(t *testing.T) {
|
|||||||
{
|
{
|
||||||
description: "plugin exists",
|
description: "plugin exists",
|
||||||
setup: func(name string) tearDown {
|
setup: func(name string) tearDown {
|
||||||
draPlugins.add(name, &Plugin{})
|
draPlugins.add(&Plugin{name: name})
|
||||||
return func() {
|
return func() {
|
||||||
draPlugins.delete(name)
|
draPlugins.delete(name)
|
||||||
}
|
}
|
||||||
@ -251,7 +253,9 @@ func TestNodeUnprepareResources(t *testing.T) {
|
|||||||
}
|
}
|
||||||
defer teardown()
|
defer teardown()
|
||||||
|
|
||||||
|
pluginName := "dummy-plugin"
|
||||||
p := &Plugin{
|
p := &Plugin{
|
||||||
|
name: pluginName,
|
||||||
backgroundCtx: tCtx,
|
backgroundCtx: tCtx,
|
||||||
endpoint: addr,
|
endpoint: addr,
|
||||||
clientCallTimeout: defaultClientCallTimeout,
|
clientCallTimeout: defaultClientCallTimeout,
|
||||||
@ -268,10 +272,10 @@ func TestNodeUnprepareResources(t *testing.T) {
|
|||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
draPlugins.add("dummy-plugin", p)
|
draPlugins.add(p)
|
||||||
defer draPlugins.delete("dummy-plugin")
|
defer draPlugins.delete(pluginName)
|
||||||
|
|
||||||
client, err := NewDRAPluginClient("dummy-plugin")
|
client, err := NewDRAPluginClient(pluginName)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
@ -42,7 +42,7 @@ func (s *pluginsStore) get(pluginName string) *Plugin {
|
|||||||
|
|
||||||
// Set lets you save a DRA Plugin to the list and give it a specific name.
|
// Set lets you save a DRA Plugin to the list and give it a specific name.
|
||||||
// This method is protected by a mutex.
|
// This method is protected by a mutex.
|
||||||
func (s *pluginsStore) add(pluginName string, p *Plugin) (replaced bool) {
|
func (s *pluginsStore) add(p *Plugin) (replaced bool) {
|
||||||
s.Lock()
|
s.Lock()
|
||||||
defer s.Unlock()
|
defer s.Unlock()
|
||||||
|
|
||||||
@ -50,8 +50,8 @@ func (s *pluginsStore) add(pluginName string, p *Plugin) (replaced bool) {
|
|||||||
s.store = make(map[string]*Plugin)
|
s.store = make(map[string]*Plugin)
|
||||||
}
|
}
|
||||||
|
|
||||||
_, exists := s.store[pluginName]
|
_, exists := s.store[p.name]
|
||||||
s.store[pluginName] = p
|
s.store[p.name] = p
|
||||||
return exists
|
return exists
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -160,6 +160,7 @@ func (h *RegistrationHandler) RegisterPlugin(pluginName string, endpoint string,
|
|||||||
ctx, cancel := context.WithCancelCause(ctx)
|
ctx, cancel := context.WithCancelCause(ctx)
|
||||||
|
|
||||||
pluginInstance := &Plugin{
|
pluginInstance := &Plugin{
|
||||||
|
name: pluginName,
|
||||||
backgroundCtx: ctx,
|
backgroundCtx: ctx,
|
||||||
cancel: cancel,
|
cancel: cancel,
|
||||||
conn: nil,
|
conn: nil,
|
||||||
@ -170,7 +171,7 @@ func (h *RegistrationHandler) RegisterPlugin(pluginName string, endpoint string,
|
|||||||
|
|
||||||
// Storing endpoint of newly registered DRA Plugin into the map, where plugin name will be the key
|
// Storing endpoint of newly registered DRA Plugin into the map, where plugin name will be the key
|
||||||
// all other DRA components will be able to get the actual socket of DRA plugins by its name.
|
// all other DRA components will be able to get the actual socket of DRA plugins by its name.
|
||||||
if draPlugins.add(pluginName, pluginInstance) {
|
if draPlugins.add(pluginInstance) {
|
||||||
logger.V(1).Info("Already registered, previous plugin was replaced")
|
logger.V(1).Info("Already registered, previous plugin was replaced")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user