feat(labels): support service and container labels, update labels and cpu/memory in-place

This commit is contained in:
Pasha Sviderski
2026-11-02 14:57:33 +10:00
parent b214d23f21
commit 81f30aac26
30 changed files with 1727 additions and 286 deletions
+33
View File
@@ -1,7 +1,11 @@
package api
import (
"errors"
"github.com/docker/docker/api/types/container"
"github.com/google/go-cmp/cmp"
"github.com/google/go-cmp/cmp/cmpopts"
)
const (
@@ -27,6 +31,35 @@ type ContainerResources struct {
Ulimits map[string]Ulimit
}
// Equals returns true if the resources are equal, treating nil and empty slices and maps as equal.
func (r ContainerResources) Equals(other ContainerResources) bool {
return cmp.Equal(r, other, cmpopts.EquateEmpty())
}
// ValidateUpdateInPlace returns an error explaining why a container created with these resources can't be updated
// to the new resources without recreating it. It returns nil if the container can be updated in place.
// Docker can only change the CPU and memory limits of an existing container and can't remove a limit once it's set.
func (r ContainerResources) ValidateUpdateInPlace(new ContainerResources) error {
// Docker treats zero values as unchanged when updating a container.
if r.CPU != 0 && new.CPU == 0 {
return errors.New("CPU limit can't be removed")
}
if r.Memory != 0 && new.Memory == 0 {
return errors.New("memory limit can't be removed")
}
if r.MemoryReservation != 0 && new.MemoryReservation == 0 {
return errors.New("memory reservation can't be removed")
}
r.CPU = new.CPU
r.Memory = new.Memory
r.MemoryReservation = new.MemoryReservation
if !r.Equals(new) {
return errors.New("only CPU and memory limits can be changed")
}
return nil
}
// DeviceMapping represents a device mapping between host and container.
type DeviceMapping struct {
// HostPath is the path to the device on the host.