mirror of
https://github.com/kata-containers/kata-containers.git
synced 2025-06-24 22:43:05 +00:00
Merge pull request #9624 from cncal/bugfix_duplicated_devices
runtime: fix duplicated devices requested to the agent
This commit is contained in:
commit
b7af00be2a
@ -6,6 +6,7 @@
|
||||
package virtcontainers
|
||||
|
||||
import (
|
||||
"context"
|
||||
b64 "encoding/base64"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
@ -34,8 +35,6 @@ import (
|
||||
"github.com/kata-containers/kata-containers/src/runtime/virtcontainers/types"
|
||||
"github.com/kata-containers/kata-containers/src/runtime/virtcontainers/utils"
|
||||
|
||||
"context"
|
||||
|
||||
ctrAnnotations "github.com/containerd/containerd/pkg/cri/annotations"
|
||||
podmanAnnotations "github.com/containers/podman/v4/pkg/annotations"
|
||||
"github.com/opencontainers/runtime-spec/specs-go"
|
||||
@ -1200,8 +1199,6 @@ func (k *kataAgent) appendVfioDevice(dev ContainerDevice, device api.Device, c *
|
||||
}
|
||||
|
||||
func (k *kataAgent) appendDevices(deviceList []*grpc.Device, c *Container) []*grpc.Device {
|
||||
var kataDevice *grpc.Device
|
||||
|
||||
for _, dev := range c.devices {
|
||||
device := c.sandbox.devManager.GetDeviceByID(dev.ID)
|
||||
if device == nil {
|
||||
@ -1213,6 +1210,8 @@ func (k *kataAgent) appendDevices(deviceList []*grpc.Device, c *Container) []*gr
|
||||
continue
|
||||
}
|
||||
|
||||
var kataDevice *grpc.Device
|
||||
|
||||
switch device.DeviceType() {
|
||||
case config.DeviceBlock:
|
||||
kataDevice = k.appendBlockDevice(dev, device, c)
|
||||
|
@ -479,16 +479,21 @@ func TestAppendDevicesEmptyContainerDeviceList(t *testing.T) {
|
||||
func TestAppendDevices(t *testing.T) {
|
||||
k := kataAgent{}
|
||||
|
||||
id := "test-append-block"
|
||||
testBlockDeviceID := "test-block-device"
|
||||
testCharacterDeviceId := "test-character-device"
|
||||
|
||||
ctrDevices := []api.Device{
|
||||
&drivers.BlockDevice{
|
||||
GenericDevice: &drivers.GenericDevice{
|
||||
ID: id,
|
||||
ID: testBlockDeviceID,
|
||||
},
|
||||
BlockDrive: &config.BlockDrive{
|
||||
PCIPath: testPCIPath,
|
||||
},
|
||||
},
|
||||
&drivers.GenericDevice{
|
||||
ID: testCharacterDeviceId,
|
||||
},
|
||||
}
|
||||
|
||||
sandboxConfig := &SandboxConfig{
|
||||
@ -503,10 +508,16 @@ func TestAppendDevices(t *testing.T) {
|
||||
config: sandboxConfig,
|
||||
},
|
||||
}
|
||||
c.devices = append(c.devices, ContainerDevice{
|
||||
ID: id,
|
||||
ContainerPath: testBlockDeviceCtrPath,
|
||||
})
|
||||
c.devices = append(
|
||||
c.devices,
|
||||
ContainerDevice{
|
||||
ID: testBlockDeviceID,
|
||||
ContainerPath: testBlockDeviceCtrPath,
|
||||
},
|
||||
ContainerDevice{
|
||||
ID: testCharacterDeviceId,
|
||||
},
|
||||
)
|
||||
|
||||
devList := []*pb.Device{}
|
||||
expected := []*pb.Device{
|
||||
|
Loading…
Reference in New Issue
Block a user