Skip to content

Commit

Permalink
kraken: Add atomic install from raw body install
Browse files Browse the repository at this point in the history
* Add option to raw body installs be atomic, since they are likely to
  use private repos and require auth to install there is no point on
  keep kraken trying to fix the installation after.
  • Loading branch information
JoaoMario109 authored and patrickelectric committed Jun 12, 2024
1 parent 3dc3f9c commit eb70c04
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 3 deletions.
2 changes: 1 addition & 1 deletion core/services/kraken/api/v1/routers/extension.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
@extension_router_v1.post("/install", status_code=status.HTTP_201_CREATED)
async def install_extension(body: ExtensionSource) -> StreamingResponse:
extension = Extension(body)
return StreamingResponse(streamer(extension.install()))
return StreamingResponse(streamer(extension.install(atomic=True)))


@extension_router_v1.post("/uninstall", status_code=status.HTTP_200_OK)
Expand Down
2 changes: 1 addition & 1 deletion core/services/kraken/api/v2/routers/extension.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ async def install(body: ExtensionSource) -> StreamingResponse:
can install incompatible extensions. Make sure to check the extension source before installing it.
"""
extension = Extension(body)
return StreamingResponse(streamer(extension.install()))
return StreamingResponse(streamer(extension.install(atomic=True)))


@extension_router_v2.post("/{identifier}/install", status_code=status.HTTP_201_CREATED)
Expand Down
5 changes: 4 additions & 1 deletion core/services/kraken/extension/extension.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ async def remove(cls, container_name: str, delete_image: bool = True) -> None:
finally:
cls.unlock(container_name)

async def install(self, clear_remaining_tags: bool = True) -> AsyncGenerator[bytes, None]:
async def install(self, clear_remaining_tags: bool = True, atomic: bool = False) -> AsyncGenerator[bytes, None]:
logger.info(f"Installing extension {self.identifier}:{self.tag}")

# First we should make sure no other tag is running
Expand Down Expand Up @@ -148,6 +148,9 @@ async def install(self, clear_remaining_tags: bool = True) -> AsyncGenerator[byt
if self.digest:
await client.images.tag(tag, f"{self.source.docker}:{self.tag}")
except Exception as error:
# In case of some external installs kraken shouldn't try to install it again so we remove from settings
if atomic:
await self.uninstall()
raise ExtensionPullFailed(f"Failed to pull extension {self.identifier}:{self.tag}") from error
finally:
self.unlock(self.identifier + self.tag)
Expand Down

0 comments on commit eb70c04

Please sign in to comment.