From 1de9dcd35cad0c9bf9d376c3fb3e8c5e995ca76d Mon Sep 17 00:00:00 2001 From: Waqar Ahmed Date: Mon, 25 Nov 2024 02:01:55 +0500 Subject: [PATCH] Handle k8s apps migration edge case (cherry picked from commit 939abe6bae2238d4a02449ce416c18d1fe436159) --- .../plugins/kubernetes_to_docker/migrate.py | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/src/middlewared/middlewared/plugins/kubernetes_to_docker/migrate.py b/src/middlewared/middlewared/plugins/kubernetes_to_docker/migrate.py index 5611a56cc9a40..5049805de2e36 100644 --- a/src/middlewared/middlewared/plugins/kubernetes_to_docker/migrate.py +++ b/src/middlewared/middlewared/plugins/kubernetes_to_docker/migrate.py @@ -187,7 +187,22 @@ def migrate(self, job, kubernetes_pool, options): app_volume_ds = get_app_parent_volume_ds_name( os.path.join(kubernetes_pool, 'ix-apps'), chart_release['release_name'] ) - for snapshot in available_snapshots: + if (app_ds := self.middleware.call_sync('zfs.dataset.query', [['id', '=', app_volume_ds]], { + 'extra': {'retrieve_properties': False} + })) and len(app_ds[0]['children']) > 0: + # If there are already ix volumes under app volume ds, it means migration had already been + # performed for this app and we don't need to do it again - it will only result in more edge + # cases - this happens when user migrated and then deleted the app but left ix-volumes and + # migrated it again + logger.debug( + 'Skipping migrating ix-volumes for %r app as app volumes dataset already has children', + chart_release['release_name'] + ) + to_clone_promote_snaps = [] + else: + to_clone_promote_snaps = available_snapshots + + for snapshot in to_clone_promote_snaps: # We will do a zfs clone and promote here destination_ds = os.path.join(app_volume_ds, snapshot.split('@')[0].split('/')[-1]) self.middleware.call_sync('zfs.snapshot.clone', {