add VolumeScheduler with one flaky test

This commit is contained in:
Pavel Sviderski
2025-04-20 11:13:30 +10:00
parent f71fc57f34
commit 948201cb6f
7 changed files with 1363 additions and 18 deletions
+12
View File
@@ -61,6 +61,18 @@ func (s *ServiceSpec) Volume(name string) (VolumeSpec, bool) {
return VolumeSpec{}, false
}
// MountedDockerVolumes returns the list of volumes of VolumeTypeVolume type that are mounted into the container.
func (s *ServiceSpec) MountedDockerVolumes() []VolumeSpec {
volumes := make(map[string]VolumeSpec)
for _, m := range s.Container.VolumeMounts {
if v, ok := s.Volume(m.VolumeName); ok && v.Type == VolumeTypeVolume {
volumes[v.Name] = v
}
}
return slices.Collect(maps.Values(volumes))
}
func (s *ServiceSpec) SetDefaults() ServiceSpec {
spec := s.Clone()
+31 -1
View File
@@ -18,6 +18,9 @@ const (
VolumeTypeVolume = "volume"
// VolumeTypeTmpfs is the type for mounting a temporary file system stored in the host memory.
VolumeTypeTmpfs = "tmpfs"
// VolumeDriverLocal is the default volume driver for local named Docker volumes.
VolumeDriverLocal = "local"
)
// VolumeSpec defines a volume mount specification. As of April 2025, the volume must be created before deploying
@@ -76,7 +79,7 @@ func (v *VolumeSpec) SetDefaults() VolumeSpec {
spec.VolumeOptions = &VolumeOptions{}
}
if spec.VolumeOptions.Driver == nil {
spec.VolumeOptions.Driver = &mount.Driver{Name: "local"}
spec.VolumeOptions.Driver = &mount.Driver{Name: VolumeDriverLocal}
}
if spec.VolumeOptions.Name == "" {
spec.VolumeOptions.Name = spec.Name
@@ -113,6 +116,33 @@ func (v *VolumeSpec) Equals(other VolumeSpec) bool {
return reflect.DeepEqual(vol, other)
}
// MatchesDockerVolume checks if this VolumeSpec is compatible with the given named Docker volume.
// In other words, it checks if the spec could be used to create the volume.
func (v *VolumeSpec) MatchesDockerVolume(vol volume.Volume) bool {
if v.Type != VolumeTypeVolume {
return false
}
spec := v.SetDefaults()
if spec.DockerVolumeName() != vol.Name {
return false
}
volDriver := vol.Driver
if volDriver == "" {
volDriver = VolumeDriverLocal
}
if spec.VolumeOptions.Driver.Name != volDriver {
return false
}
if !reflect.DeepEqual(spec.VolumeOptions.Driver.Options, vol.Options) {
return false
}
return true
}
func (v *VolumeSpec) Clone() VolumeSpec {
spec := *v