chore: implement VolumesConstraint to only schedule on machines with required volumes

This commit is contained in:
Pavel Sviderski
2025-04-17 21:34:52 +10:00
parent 03c2681792
commit 1acb0ff110
5 changed files with 288 additions and 5 deletions
+9
View File
@@ -52,6 +52,15 @@ type ServiceSpec struct {
Volumes []VolumeSpec
}
func (s *ServiceSpec) Volume(name string) (VolumeSpec, bool) {
for _, v := range s.Volumes {
if v.Name == name {
return v, true
}
}
return VolumeSpec{}, false
}
func (s *ServiceSpec) SetDefaults() ServiceSpec {
spec := s.Clone()
+13 -3
View File
@@ -14,7 +14,7 @@ import (
const (
// VolumeTypeBind is the type for mounting a host path.
VolumeTypeBind = "bind"
// VolumeTypeVolume is the type for mounting a managed volume.
// VolumeTypeVolume is the type for mounting a named Docker volume.
VolumeTypeVolume = "volume"
// VolumeTypeTmpfs is the type for mounting a temporary file system stored in the host memory.
VolumeTypeTmpfs = "tmpfs"
@@ -42,7 +42,7 @@ type BindOptions struct {
Recursive string `json:",omitempty"`
}
// VolumeOptions represents options for a managed volume.
// VolumeOptions represents options for a named Docker volume.
type VolumeOptions struct {
// Driver specifies the volume driver and its options for volume creation.
// TODO: It seems we don't really need Driver and Labels if we only support externally managed volumes.
@@ -50,7 +50,7 @@ type VolumeOptions struct {
Driver *mount.Driver `json:",omitempty"`
// Labels are key-value metadata to apply to the volume if creating a new volume.
Labels map[string]string `json:",omitempty"`
// Name of the managed volume to use. If not specified, defaults to the VolumeSpec.Name.
// Name of the named Docker volume to use. If not specified, defaults to the VolumeSpec.Name.
Name string `json:",omitempty"`
// NoCopy prevents automatic copying of data from the container mount path to the volume.
NoCopy bool `json:",omitempty"`
@@ -58,6 +58,16 @@ type VolumeOptions struct {
SubPath string `json:",omitempty"`
}
func (v *VolumeSpec) DockerVolumeName() string {
if v.Type != VolumeTypeVolume {
return ""
}
if v.VolumeOptions != nil && v.VolumeOptions.Name != "" {
return v.VolumeOptions.Name
}
return v.Name
}
func (v *VolumeSpec) SetDefaults() VolumeSpec {
spec := v.Clone()