Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 25 additions & 6 deletions internal/target/incus.go
Original file line number Diff line number Diff line change
Expand Up @@ -634,7 +634,8 @@ func (t *InternalIncusTarget) SetupVM(ctx context.Context, instDef migration.Ins

tgtClient := t.incusClient.UseTarget(instInfo.Location)
defaultDiskDef := map[string]string{
"type": "disk",
"type": "disk",
"dependent": "true",
}

// Create volumes for the remaining disks.
Expand Down Expand Up @@ -729,12 +730,30 @@ func (t *InternalIncusTarget) CleanupVM(ctx context.Context, name string, requir
return fmt.Errorf("Failed to wait for delete operation for instance %q: %w", name, err)
}

tgtClient := t.incusClient.UseTarget(instInfo.Location)
volsByPool := map[string]map[string]bool{}
for _, dev := range instInfo.Devices {
if dev["type"] == "disk" && dev["user.migration_source"] != "" && dev["source"] != "" {
err := tgtClient.DeleteStoragePoolVolume(dev["pool"], "custom", dev["source"])
if err != nil {
return fmt.Errorf("Failed to delete instance %q storage volume %q on pool %q: %w", name, dev["source"], dev["pool"], err)
if dev["type"] == "disk" && dev["user.migration_source"] != "" && dev["source"] != "" && dev["pool"] != "" {
if volsByPool[dev["pool"]] == nil {
volsByPool[dev["pool"]] = map[string]bool{}
}

volsByPool[dev["pool"]][dev["source"]] = true
}
}

tgtClient := t.incusClient.UseTarget(instInfo.Location)
for pool, volsByName := range volsByPool {
volNames, err := tgtClient.GetStoragePoolVolumeNames(pool)
if err != nil {
return fmt.Errorf("Failed to find %q volumes for instance %q: %w", pool, name, err)
}

for _, vol := range volNames {
if volsByName[vol] {
err := tgtClient.DeleteStoragePoolVolume(pool, "custom", vol)
if err != nil {
return fmt.Errorf("Failed to delete instance %q storage volume %q on pool %q: %w", name, vol, pool, err)
}
}
}
}
Expand Down
5 changes: 4 additions & 1 deletion ui/src/components/InstanceOverrides.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,10 @@ const InstanceOverrides: FC = () => {
values.distribution != instance?.distribution
? values.distribution
: "",
distribution_version: values.distribution_version,
distribution_version:
values.distribution_version != instance?.distribution_version
? values.distribution_version
: "",
started_after_migration: values.started_after_migration == "true",
stopped_after_migration: values.stopped_after_migration == "true",
};
Expand Down
Loading