mirror of
https://github.com/psviderski/uncloud.git
synced 2026-08-26 11:03:34 +00:00
chore: refactor device mapping to be compliant with Compose (CDI requests)
This commit is contained in:
+13
-3
@@ -17,14 +17,24 @@ type ContainerResources struct {
|
||||
// MemoryReservation is the minimum amount of memory (in bytes) the container needs to run efficiently.
|
||||
// TODO: implement a placement constraint that checks available memory on machines.
|
||||
MemoryReservation int64
|
||||
// Device mappings for direct access to host devices
|
||||
DeviceMappings []container.DeviceMapping
|
||||
// Device reservations/requests for access to things like GPUs
|
||||
// Devices provides direct access to host devices.
|
||||
Devices []DeviceMapping
|
||||
// DeviceReservations requests for access to things like GPUs.
|
||||
DeviceReservations []container.DeviceRequest
|
||||
// Ulimits defines the resource limits for the container.
|
||||
Ulimits map[string]Ulimit
|
||||
}
|
||||
|
||||
// DeviceMapping represents a device mapping between host and container.
|
||||
type DeviceMapping struct {
|
||||
// HostPath is the path to the device on the host.
|
||||
HostPath string
|
||||
// ContainerPath is the path to the device in the container.
|
||||
ContainerPath string
|
||||
// CgroupPermissions is the cgroup permissions for the device (e.g., "rwm").
|
||||
CgroupPermissions string
|
||||
}
|
||||
|
||||
type Ulimit struct {
|
||||
Soft int64
|
||||
Hard int64
|
||||
|
||||
+2
-2
@@ -383,8 +383,8 @@ func (s *ContainerSpec) Clone() ContainerSpec {
|
||||
if s.Resources.Ulimits != nil {
|
||||
spec.Resources.Ulimits = maps.Clone(s.Resources.Ulimits)
|
||||
}
|
||||
if s.Resources.DeviceMappings != nil {
|
||||
spec.Resources.DeviceMappings = slices.Clone(s.Resources.DeviceMappings)
|
||||
if s.Resources.Devices != nil {
|
||||
spec.Resources.Devices = slices.Clone(s.Resources.Devices)
|
||||
}
|
||||
if s.Resources.DeviceReservations != nil {
|
||||
spec.Resources.DeviceReservations = slices.Clone(s.Resources.DeviceReservations)
|
||||
|
||||
@@ -232,8 +232,8 @@ func TestContainerSpec_Clone(t *testing.T) {
|
||||
CPU: 1234,
|
||||
Memory: 2345,
|
||||
MemoryReservation: 3456,
|
||||
DeviceMappings: []container.DeviceMapping{
|
||||
{PathOnHost: "/dev/sda", PathInContainer: "/dev/xvda", CgroupPermissions: "rwm"},
|
||||
Devices: []DeviceMapping{
|
||||
{HostPath: "/dev/sda", ContainerPath: "/dev/xvda", CgroupPermissions: "rwm"},
|
||||
},
|
||||
DeviceReservations: []container.DeviceRequest{
|
||||
{Count: 1, Capabilities: [][]string{{"gpu"}}, Driver: "nvidia"},
|
||||
@@ -270,7 +270,7 @@ 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.Devices[0].HostPath = stringModified
|
||||
original.Resources.DeviceReservations[0].Count = 2
|
||||
original.Resources.DeviceReservations[0].Driver = stringModified
|
||||
|
||||
@@ -293,7 +293,7 @@ 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, "/dev/sda", cloned.Resources.Devices[0].HostPath)
|
||||
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)
|
||||
|
||||
Reference in New Issue
Block a user