Skip to content

fix(BA-1520): Restrict setting ResourceLimit below the resource label (WIP) #4841

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

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions src/ai/backend/common/exception.py
Original file line number Diff line number Diff line change
Expand Up @@ -477,3 +477,16 @@ def error_code(cls) -> ErrorCode:
operation=ErrorOperation.AUTH,
error_detail=ErrorDetail.FORBIDDEN,
)


class InvalidResourceLimit(BackendAIError, web.HTTPForbidden):
error_type = "https://api.backend.ai/probs/invalid-resource-limit"
error_title = "Resource Limit Value Invalid"

@classmethod
def error_code(cls) -> ErrorCode:
return ErrorCode(
domain=ErrorDomain.IMAGE,
operation=ErrorOperation.UPDATE,
error_detail=ErrorDetail.INVALID_PARAMETERS,
)
15 changes: 14 additions & 1 deletion src/ai/backend/manager/services/image/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import sqlalchemy as sa

from ai.backend.common.dto.manager.rpc_request import PurgeImagesReq
from ai.backend.common.exception import UnknownImageReference
from ai.backend.common.exception import InvalidResourceLimit, UnknownImageReference
from ai.backend.common.types import AgentId, ImageAlias
from ai.backend.common.utils import join_non_empty
from ai.backend.logging.utils import BraceStyleAdapter
Expand Down Expand Up @@ -172,6 +172,19 @@
except UnknownImageReference:
raise ModifyImageActionUnknownImageReferenceError
to_update = props.fields_to_update()
resource_labels = image_row.get_resources_from_labels()

for label_key, resource_label in resource_labels.items():
min_in_label = resource_label.get("min", None)
min_to_update = (
to_update.get("_resources", {}).get(label_key, {}).get("min", None)
)

# TODO: Consider slot types

Check notice

Code scanning / devskim

A "TODO" or similar was left in source code, possibly indicating incomplete functionality Note

Suspicious comment
if min_in_label and min_to_update:
if min_to_update < min_in_label:
raise InvalidResourceLimit()

for key, value in to_update.items():
setattr(image_row, key, value)
except (ValueError, sa.exc.DBAPIError):
Expand Down
Loading