pkg/deviceplugin: do not reset Envs/Annotations from previous loops

When more than one device ID is Allocate()'d to a container,
Envs/Annotations for all but the last device ID get lost because
their cresp.* maps are (re-)instantiated on each loop.

Fix it by doing that only once.

Fixes: 55f3e17

Signed-off-by: Mikko Ylinen <mikko.ylinen@intel.com>
This commit is contained in:
Mikko Ylinen 2023-02-27 09:00:11 +02:00
parent fd67c5cd6f
commit 4fa7c4cb23

View File

@ -143,6 +143,9 @@ func (srv *server) Allocate(ctx context.Context, rqt *pluginapi.AllocateRequest)
for _, crqt := range rqt.ContainerRequests { for _, crqt := range rqt.ContainerRequests {
cresp := new(pluginapi.ContainerAllocateResponse) cresp := new(pluginapi.ContainerAllocateResponse)
cresp.Envs = map[string]string{}
cresp.Annotations = map[string]string{}
for _, id := range crqt.DevicesIDs { for _, id := range crqt.DevicesIDs {
dev, ok := srv.devices[id] dev, ok := srv.devices[id]
if !ok { if !ok {
@ -161,14 +164,10 @@ func (srv *server) Allocate(ctx context.Context, rqt *pluginapi.AllocateRequest)
cresp.Mounts = append(cresp.Mounts, &dev.mounts[i]) cresp.Mounts = append(cresp.Mounts, &dev.mounts[i])
} }
cresp.Envs = map[string]string{}
for key, value := range dev.envs { for key, value := range dev.envs {
cresp.Envs[key] = value cresp.Envs[key] = value
} }
cresp.Annotations = map[string]string{}
for key, value := range dev.annotations { for key, value := range dev.annotations {
cresp.Annotations[key] = value cresp.Annotations[key] = value
} }