mirror of
https://github.com/psviderski/uncloud.git
synced 2026-08-26 19:13:34 +00:00
chore: do not set default volume driver to local, distinguish behaviour when it's set or not
This commit is contained in:
+13
-13
@@ -78,9 +78,6 @@ func (v *VolumeSpec) SetDefaults() VolumeSpec {
|
||||
if spec.VolumeOptions == nil {
|
||||
spec.VolumeOptions = &VolumeOptions{}
|
||||
}
|
||||
if spec.VolumeOptions.Driver == nil {
|
||||
spec.VolumeOptions.Driver = &mount.Driver{Name: VolumeDriverLocal}
|
||||
}
|
||||
if spec.VolumeOptions.Name == "" {
|
||||
spec.VolumeOptions.Name = spec.Name
|
||||
}
|
||||
@@ -117,7 +114,7 @@ func (v *VolumeSpec) Equals(other VolumeSpec) bool {
|
||||
}
|
||||
|
||||
// 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.
|
||||
// In other words, it checks if the spec could be used to mount the volume.
|
||||
func (v *VolumeSpec) MatchesDockerVolume(vol volume.Volume) bool {
|
||||
if v.Type != VolumeTypeVolume {
|
||||
return false
|
||||
@@ -128,16 +125,19 @@ func (v *VolumeSpec) MatchesDockerVolume(vol volume.Volume) bool {
|
||||
return false
|
||||
}
|
||||
|
||||
volDriver := vol.Driver
|
||||
if volDriver == "" {
|
||||
volDriver = VolumeDriverLocal
|
||||
}
|
||||
if spec.VolumeOptions.Driver.Name != volDriver {
|
||||
return false
|
||||
}
|
||||
if spec.VolumeOptions.Driver != nil {
|
||||
volDriver := vol.Driver
|
||||
if volDriver == "" {
|
||||
volDriver = VolumeDriverLocal
|
||||
}
|
||||
|
||||
if !reflect.DeepEqual(spec.VolumeOptions.Driver.Options, vol.Options) {
|
||||
return false
|
||||
if spec.VolumeOptions.Driver.Name != volDriver {
|
||||
return false
|
||||
}
|
||||
|
||||
if !reflect.DeepEqual(spec.VolumeOptions.Driver.Options, vol.Options) {
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
return true
|
||||
|
||||
@@ -186,15 +186,66 @@ func TestEvalContainerSpecChange_Volumes(t *testing.T) {
|
||||
Type: api.VolumeTypeVolume,
|
||||
VolumeOptions: &api.VolumeOptions{
|
||||
Name: "data",
|
||||
Driver: &mount.Driver{
|
||||
Name: "local",
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
expected: ContainerUpToDate,
|
||||
},
|
||||
{
|
||||
name: "change volume driver to local",
|
||||
current: api.ServiceSpec{
|
||||
Volumes: []api.VolumeSpec{
|
||||
{
|
||||
Name: "data",
|
||||
Type: api.VolumeTypeVolume,
|
||||
},
|
||||
},
|
||||
},
|
||||
new: api.ServiceSpec{
|
||||
Volumes: []api.VolumeSpec{
|
||||
{
|
||||
Name: "data",
|
||||
Type: api.VolumeTypeVolume,
|
||||
VolumeOptions: &api.VolumeOptions{
|
||||
Name: "data",
|
||||
Driver: &mount.Driver{
|
||||
Name: api.VolumeDriverLocal,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
// TODO: this doesn't really require a recreate, only a spec update would be sufficient.
|
||||
expected: ContainerNeedsRecreate,
|
||||
},
|
||||
{
|
||||
name: "change volume driver to custom",
|
||||
current: api.ServiceSpec{
|
||||
Volumes: []api.VolumeSpec{
|
||||
{
|
||||
Name: "data",
|
||||
Type: api.VolumeTypeVolume,
|
||||
},
|
||||
},
|
||||
},
|
||||
new: api.ServiceSpec{
|
||||
Volumes: []api.VolumeSpec{
|
||||
{
|
||||
Name: "data",
|
||||
Type: api.VolumeTypeVolume,
|
||||
VolumeOptions: &api.VolumeOptions{
|
||||
Name: "data",
|
||||
Driver: &mount.Driver{
|
||||
Name: "custom",
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
// TODO: this doesn't really require a recreate, only a spec update would be sufficient.
|
||||
expected: ContainerNeedsRecreate,
|
||||
},
|
||||
{
|
||||
name: "change bind option CreateHostPath",
|
||||
current: api.ServiceSpec{
|
||||
|
||||
@@ -138,6 +138,7 @@ func (s *VolumeScheduler) Schedule() (map[string][]api.VolumeSpec, error) {
|
||||
|
||||
// For each volume that exists on any machine(s) (which shouldn't be created), intersect each service's
|
||||
// eligible machines that use the volume with the machines the volume is located on.
|
||||
//
|
||||
// Service name -> list of processed volume names (quoted) to format the error message.
|
||||
quotedServiceVolumes := make(map[string][]string)
|
||||
for volumeName, volumeMachines := range s.existingVolumeMachines {
|
||||
|
||||
@@ -521,6 +521,11 @@ func TestVolumeScheduler_Schedule(t *testing.T) {
|
||||
{
|
||||
Name: "vol2",
|
||||
Type: api.VolumeTypeVolume,
|
||||
VolumeOptions: &api.VolumeOptions{
|
||||
Driver: &mount.Driver{
|
||||
Name: api.VolumeDriverLocal,
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
Name: "vol3",
|
||||
@@ -547,15 +552,17 @@ func TestVolumeScheduler_Schedule(t *testing.T) {
|
||||
{
|
||||
Name: "vol2",
|
||||
Type: api.VolumeTypeVolume,
|
||||
VolumeOptions: &api.VolumeOptions{
|
||||
Driver: &mount.Driver{
|
||||
Name: api.VolumeDriverLocal,
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
Name: "vol4-alias",
|
||||
Type: api.VolumeTypeVolume,
|
||||
VolumeOptions: &api.VolumeOptions{
|
||||
Name: "vol4",
|
||||
Driver: &mount.Driver{
|
||||
Name: api.VolumeDriverLocal,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
@@ -570,7 +577,7 @@ func TestVolumeScheduler_Schedule(t *testing.T) {
|
||||
ContainerPath: "/data2",
|
||||
},
|
||||
{
|
||||
VolumeName: "vol5",
|
||||
VolumeName: "vol5-with-driver",
|
||||
ContainerPath: "/data5",
|
||||
},
|
||||
},
|
||||
@@ -587,8 +594,14 @@ func TestVolumeScheduler_Schedule(t *testing.T) {
|
||||
},
|
||||
},
|
||||
{
|
||||
Name: "vol5",
|
||||
Name: "vol5-with-driver",
|
||||
Type: api.VolumeTypeVolume,
|
||||
VolumeOptions: &api.VolumeOptions{
|
||||
Name: "vol5",
|
||||
Driver: &mount.Driver{
|
||||
Name: api.VolumeDriverLocal,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
@@ -598,6 +611,11 @@ func TestVolumeScheduler_Schedule(t *testing.T) {
|
||||
{
|
||||
Name: "vol5",
|
||||
Type: api.VolumeTypeVolume,
|
||||
VolumeOptions: &api.VolumeOptions{
|
||||
Driver: &mount.Driver{
|
||||
Name: api.VolumeDriverLocal,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
"machine3": {
|
||||
|
||||
+12
-6
@@ -51,12 +51,18 @@ func (cli *Client) RunService(ctx context.Context, spec api.ServiceSpec) (api.Ru
|
||||
// Create the missing volumes on the scheduled machines.
|
||||
for machineID, volumes := range scheduledVolumes {
|
||||
for _, v := range volumes {
|
||||
_, err = cli.CreateVolume(ctx, machineID, volume.CreateOptions{
|
||||
Name: v.Name,
|
||||
Driver: v.VolumeOptions.Driver.Name,
|
||||
DriverOpts: v.VolumeOptions.Driver.Options,
|
||||
})
|
||||
if err != nil {
|
||||
opts := volume.CreateOptions{
|
||||
Name: v.Name,
|
||||
}
|
||||
if v.VolumeOptions != nil {
|
||||
if v.VolumeOptions.Driver != nil {
|
||||
opts.Driver = v.VolumeOptions.Driver.Name
|
||||
opts.DriverOpts = v.VolumeOptions.Driver.Options
|
||||
}
|
||||
opts.Labels = v.VolumeOptions.Labels
|
||||
}
|
||||
|
||||
if _, err = cli.CreateVolume(ctx, machineID, opts); err != nil {
|
||||
return resp, fmt.Errorf("create volume '%s': %w", v.Name, err)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user