From 3e760f0d85f43af82bcd28034e7dd4d7db196d2e Mon Sep 17 00:00:00 2001 From: Stefan Agner Date: Thu, 21 Dec 2023 22:52:25 +0100 Subject: [PATCH] Always pass explicit architecture of installed add-ons (#4786) * Pass architecture of installed add-on on update When using multi-architecture container images, the architecture of the add-on is not passed to Docker in all cases. This causes the architecture of the Supervisor container to be used, which potentially is not supported by the add-on in question. This commit passes the architecture of the add-on to Docker, so that the correct image is pulled. * Call update with architecture * Also pass architecture on add-on restore * Fix pytest --- supervisor/addons/addon.py | 8 +++++--- supervisor/docker/addon.py | 12 ++++++++++-- tests/addons/test_manager.py | 2 +- 3 files changed, 16 insertions(+), 6 deletions(-) diff --git a/supervisor/addons/addon.py b/supervisor/addons/addon.py index 1278934037d..0b123c1f336 100644 --- a/supervisor/addons/addon.py +++ b/supervisor/addons/addon.py @@ -718,7 +718,7 @@ async def update(self) -> asyncio.Task | None: store = self.addon_store.clone() try: - await self.instance.update(store.version, store.image) + await self.instance.update(store.version, store.image, arch=self.arch) except DockerError as err: raise AddonsError() from err @@ -1209,12 +1209,14 @@ def _extract_tarfile(): await self.instance.import_image(image_file) else: with suppress(DockerError): - await self.instance.install(version, restore_image) + await self.instance.install( + version, restore_image, self.arch + ) await self.instance.cleanup() elif self.instance.version != version or self.legacy: _LOGGER.info("Restore/Update of image for addon %s", self.slug) with suppress(DockerError): - await self.instance.update(version, restore_image) + await self.instance.update(version, restore_image, self.arch) self._check_ingress_port() # Restore data and config diff --git a/supervisor/docker/addon.py b/supervisor/docker/addon.py index 79aa90fa48e..1f93e64e611 100644 --- a/supervisor/docker/addon.py +++ b/supervisor/docker/addon.py @@ -602,7 +602,11 @@ async def run(self) -> None: on_condition=DockerJobError, ) async def update( - self, version: AwesomeVersion, image: str | None = None, latest: bool = False + self, + version: AwesomeVersion, + image: str | None = None, + latest: bool = False, + arch: CpuArch | None = None, ) -> None: """Update a docker image.""" image = image or self.image @@ -613,7 +617,11 @@ async def update( # Update docker image await self.install( - version, image=image, latest=latest, need_build=self.addon.latest_need_build + version, + image=image, + latest=latest, + arch=arch, + need_build=self.addon.latest_need_build, ) @Job( diff --git a/tests/addons/test_manager.py b/tests/addons/test_manager.py index 5aa657af778..fd4cea91468 100644 --- a/tests/addons/test_manager.py +++ b/tests/addons/test_manager.py @@ -68,7 +68,7 @@ async def test_image_added_removed_on_update( await coresys.addons.update(TEST_ADDON_SLUG) build.assert_not_called() install.assert_called_once_with( - AwesomeVersion("10.0.0"), "test/amd64-my-ssh-addon", False, None + AwesomeVersion("10.0.0"), "test/amd64-my-ssh-addon", False, "amd64" ) assert install_addon_ssh.need_update is False