Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add check for free space in kraken prior to install new extension #2445

Merged
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 8 additions & 0 deletions core/services/kraken/kraken.py
Expand Up @@ -346,5 +346,13 @@ async def load_stats(self) -> Dict[str, Any]:
}
return result

def has_enough_disk_space(self, path: str = "/", required_mb: int = 2**10) -> bool:
try:
free_space = psutil.disk_usage(path).free
# Right now only check if there is 1GB of free space as a hardcoded value
return bool(free_space > required_mb * 2**20)
except FileNotFoundError:
return False

async def stop(self) -> None:
self.should_run = False
5 changes: 5 additions & 0 deletions core/services/kraken/main.py
Expand Up @@ -78,6 +78,11 @@ async def install_extension(extension: Extension) -> Any:
status_code=status.HTTP_400_BAD_REQUEST,
detail="Invalid extension description",
)
if not kraken.has_enough_disk_space():
raise HTTPException(
status_code=status.HTTP_507_INSUFFICIENT_STORAGE,
detail="Not enough disk space to install the extension",
)
return StreamingResponse(kraken.install_extension(extension))


Expand Down