Skip to content

Commit

Permalink
Merge pull request #461 from lsst-sqre:tickets/DM-48576
Browse files Browse the repository at this point in the history
DM-48546: Merge handling of quota in spawner form
  • Loading branch information
rra authored Jan 24, 2025
2 parents 135b351 + 6a02750 commit 442d563
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 10 deletions.
3 changes: 3 additions & 0 deletions changelog.d/20250124_115047_rra_DM_48576.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
### Bug fixes

- Return a spawner form showing only an error rather than an HTTP failure if the user's quota does not allow them to spawn any of the configured notebook sizes.
17 changes: 7 additions & 10 deletions controller/src/controller/handlers/form.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
from ..dependencies.config import config_dependency
from ..dependencies.context import RequestContext, context_dependency
from ..dependencies.user import user_dependency
from ..exceptions import InsufficientQuotaError, PermissionDeniedError
from ..exceptions import PermissionDeniedError
from ..models.domain.gafaelfawr import GafaelfawrUser
from ..templates import templates

Expand All @@ -37,25 +37,22 @@ async def get_user_lab_form(
) -> Response:
if username != user.username:
raise PermissionDeniedError("Permission denied")
if user.quota and user.quota.notebook:
if not user.quota.notebook.spawn:
return templates.TemplateResponse(
context.request, "unavailable.html.jinja"
)
images = context.image_service.menu_images()

# Filter the list of configured lab sizes to exclude labs that are larger
# than the user's quota, if they have a quota.
# than the user's quota, if they have a quota. Also handle the case where
# the user's quota says they cannot spawn labs at all.
if user.quota and user.quota.notebook:
quota = user.quota.notebook
sizes = [
s
for s in config.lab.sizes
if s.memory_bytes <= quota.memory_bytes and s.cpu <= quota.cpu
]
if not sizes:
msg = "Insufficient quota to spawn smallest lab"
raise InsufficientQuotaError(msg)
if not sizes or not quota.spawn:
return templates.TemplateResponse(
context.request, "unavailable.html.jinja"
)
else:
sizes = config.lab.sizes

Expand Down

0 comments on commit 442d563

Please sign in to comment.