diff options
author | Christian Poessinger <christian@poessinger.com> | 2022-12-24 22:52:37 +0100 |
---|---|---|
committer | Christian Poessinger <christian@poessinger.com> | 2022-12-24 22:55:59 +0100 |
commit | f3956a5358a713a6309dac24816d3ce59329ae06 (patch) | |
tree | 9f02966257d8906b4394ca892e30505854ee3a03 | |
parent | 6fe49566313f9c144f167eef4f018743236c182f (diff) | |
download | vyos-1x-f3956a5358a713a6309dac24816d3ce59329ae06.tar.gz vyos-1x-f3956a5358a713a6309dac24816d3ce59329ae06.zip |
container: T4870: remove manual user interaction during storage migration
Commit 60c80df4 ("container: T4870: bump package version 0 -> 1 for filesystem
change") introduced a fundamental change in the container storage driver that
required a manual migration step from the user to not loose any data.
This commit removes the manual user interaction and temporary exports the
container images and re-imports them after the filesystem got changed. The only
things that get lost are orphaned container images no longer referenced by the
CLI - thats an adequate trade-off as those images can always be re-added to the
system.
-rwxr-xr-x | src/migration-scripts/container/0-to-1 | 47 |
1 files changed, 45 insertions, 2 deletions
diff --git a/src/migration-scripts/container/0-to-1 b/src/migration-scripts/container/0-to-1 index 96ed6edee..d0461389b 100755 --- a/src/migration-scripts/container/0-to-1 +++ b/src/migration-scripts/container/0-to-1 @@ -17,18 +17,61 @@ # T4870: change underlaying container filesystem from vfs to overlay import os -import sys import shutil +import sys from vyos.configtree import ConfigTree +from vyos.util import call if (len(sys.argv) < 1): print("Must specify file name!") sys.exit(1) -# We actually need no filename as this is a filesystem operation +file_name = sys.argv[1] + +with open(file_name, 'r') as f: + config_file = f.read() + +base = ['container', 'name'] +config = ConfigTree(config_file) + +# Check if containers exist and we need to perform image manipulation +if config.exists(base): + for container in config.list_nodes(base): + # Stop any given container first + call(f'systemctl stop vyos-container-{container}.service') + # Export container image for later re-import to new filesystem. We store + # the backup on a real disk as a tmpfs (like /tmp) could probably lack + # memory if a host has too many containers stored. + image_name = config.return_value(base + [container, 'image']) + call(f'podman image save --quiet --output /root/{container}.tar --format oci-archive {image_name}') + +# No need to adjust the strage driver online (this is only used for testing and +# debugging on a live system) - it is already overlay2 when the migration script +# is run during system update. But the specified driver in the image is actually +# overwritten by the still present VFS filesystem on disk. Thus podman still +# thinks it uses VFS until we delete the libpod directory under: +# /usr/lib/live/mount/persistence/container/storage +#call('sed -i "s/vfs/overlay2/g" /etc/containers/storage.conf /usr/share/vyos/templates/container/storage.conf.j2') + base_path = '/usr/lib/live/mount/persistence/container/storage' for dir in ['libpod', 'vfs', 'vfs-containers', 'vfs-images', 'vfs-layers']: if os.path.exists(f'{base_path}/{dir}'): shutil.rmtree(f'{base_path}/{dir}') +# Now all remaining information about VFS is gone and we operate in overlayfs2 +# filesystem mode. Time to re-import the images. +if config.exists(base): + for container in config.list_nodes(base): + # Export container image for later re-import to new filesystem + image_name = config.return_value(base + [container, 'image']) + image_path = f'/root/{container}.tar' + call(f'podman image load --quiet --input {image_path}') + + # Start any given container first + call(f'systemctl start vyos-container-{container}.service') + + # Delete temporary container image + if os.path.exists(image_path): + os.unlink(image_path) + |