mirror of
https://github.com/psviderski/uncloud.git
synced 2026-08-27 19:43:34 +00:00
feat: Add support for compose devices mappings (#250)
* feat: Add support for compose `devices` mappings https://docs.docker.com/reference/compose-file/services/#devices ``` services: foo: devices: - "/dev/ttyUSB0:/dev/ttyUSB0" - "/dev/sda:/dev/xvda:rwm" ``` * Lint fix
This commit is contained in:
@@ -4,6 +4,7 @@ import (
|
||||
"os"
|
||||
"testing"
|
||||
|
||||
"github.com/docker/docker/api/types/container"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
@@ -231,6 +232,12 @@ func TestContainerSpec_Clone(t *testing.T) {
|
||||
CPU: 1234,
|
||||
Memory: 2345,
|
||||
MemoryReservation: 3456,
|
||||
DeviceMappings: []container.DeviceMapping{
|
||||
{PathOnHost: "/dev/sda", PathInContainer: "/dev/xvda", CgroupPermissions: "rwm"},
|
||||
},
|
||||
DeviceReservations: []container.DeviceRequest{
|
||||
{Count: 1, Capabilities: [][]string{{"gpu"}}, Driver: "nvidia"},
|
||||
},
|
||||
},
|
||||
Sysctls: map[string]string{
|
||||
"net.ipv4.ip_forward": "1",
|
||||
@@ -263,6 +270,9 @@ func TestContainerSpec_Clone(t *testing.T) {
|
||||
original.ConfigMounts[0].ContainerPath = stringModified
|
||||
*original.ConfigMounts[0].Mode = 0o755 // Modify the Mode pointer value
|
||||
original.Sysctls["net.ipv4.ip_forward"] = stringModified
|
||||
original.Resources.DeviceMappings[0].PathOnHost = stringModified
|
||||
original.Resources.DeviceReservations[0].Count = 2
|
||||
original.Resources.DeviceReservations[0].Driver = stringModified
|
||||
|
||||
assert.False(t, original.Equals(cloned))
|
||||
// Assert cloned values are unchanged
|
||||
@@ -283,6 +293,9 @@ func TestContainerSpec_Clone(t *testing.T) {
|
||||
assert.Equal(t, int64(1234), cloned.Resources.CPU)
|
||||
assert.Equal(t, int64(2345), cloned.Resources.Memory)
|
||||
assert.Equal(t, int64(3456), cloned.Resources.MemoryReservation)
|
||||
assert.Equal(t, "/dev/sda", cloned.Resources.DeviceMappings[0].PathOnHost)
|
||||
assert.Equal(t, 1, cloned.Resources.DeviceReservations[0].Count)
|
||||
assert.Equal(t, "nvidia", cloned.Resources.DeviceReservations[0].Driver)
|
||||
assert.Equal(t, "1000:1000", cloned.User)
|
||||
assert.Equal(t, "/data", cloned.Volumes[0])
|
||||
assert.Equal(t, "/data", cloned.VolumeMounts[0].ContainerPath)
|
||||
|
||||
Reference in New Issue
Block a user