Skip to content

Commit

Permalink
refactor: add validation to crc, user and secrets endpoints
Browse files Browse the repository at this point in the history
  • Loading branch information
Ralf Grubenmann authored and Panaetius committed Aug 7, 2024
1 parent ef11fb3 commit 58417b0
Show file tree
Hide file tree
Showing 9 changed files with 144 additions and 74 deletions.
38 changes: 34 additions & 4 deletions components/renku_data_services/crc/api.spec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -342,7 +342,7 @@ paths:
content:
"application/json":
schema:
$ref: "#/components/schemas/ResourceClassesWithId"
$ref: "#/components/schemas/ResourceClassesWithIdResponse"
"404":
description: The resource pool does not exist
content:
Expand Down Expand Up @@ -572,7 +572,7 @@ paths:
content:
"application/json":
schema:
$ref: "#/components/schemas/NodeAffinityList"
$ref: "#/components/schemas/NodeAffinityListResponse"
default:
$ref: '#/components/responses/Error'
tags:
Expand Down Expand Up @@ -994,8 +994,6 @@ components:
type: array
items:
$ref: "#/components/schemas/ResourceClass"
minItems: 1
uniqueItems: true
ResourceClassesWithId:
type: array
items:
Expand All @@ -1018,6 +1016,29 @@ components:
max_storage: 10000
id: 2
default: false
ResourceClassesWithIdResponse:
# Note: this needs to be separate from ResourceClassesWithId or it doesn't get generated
type: array
items:
$ref: "#/components/schemas/ResourceClassWithId"
uniqueItems: true
example:
- name: "resource class 1"
cpu: 1.5
memory: 2
gpu: 0
max_storage: 100
id: 1
default: true
default_storage: 10
- name: "resource class 2"
cpu: 4.5
memory: 10
gpu: 2
default_storage: 10
max_storage: 10000
id: 2
default: false
ResourceClassesPatchWithId:
type: array
items:
Expand Down Expand Up @@ -1456,6 +1477,15 @@ components:
example:
key: some-label-32
required_during_scheduling: true
NodeAffinityListResponse:
type: array
description: A list of k8s labels used for tolerations and/or node affinity
items:
$ref: "#/components/schemas/NodeAffinity"
example: [{"key": "test-label-1", "required_during_scheduling": false}]
uniqueItems: true
default: []
minItems: 0
NodeAffinityList:
type: array
description: A list of k8s labels used for tolerations and/or node affinity
Expand Down
41 changes: 39 additions & 2 deletions components/renku_data_services/crc/apispec.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# generated by datamodel-codegen:
# filename: api.spec.yaml
# timestamp: 2024-08-06T07:19:45+00:00
# timestamp: 2024-08-07T07:12:13+00:00

from __future__ import annotations

Expand Down Expand Up @@ -64,6 +64,15 @@ class NodeAffinity(BaseAPISpec):
required_during_scheduling: bool = False


class NodeAffinityListResponse(RootModel[List[NodeAffinity]]):
root: List[NodeAffinity] = Field(
[],
description="A list of k8s labels used for tolerations and/or node affinity",
example=[{"key": "test-label-1", "required_during_scheduling": False}],
min_length=0,
)


class Error(BaseAPISpec):
code: int = Field(..., example=1404, gt=0)
detail: Optional[str] = Field(
Expand Down Expand Up @@ -508,12 +517,40 @@ class ResourceClassWithIdFiltered(BaseAPISpec):
)


class ResourceClassesWithIdResponse(RootModel[List[ResourceClassWithId]]):
root: List[ResourceClassWithId] = Field(
...,
example=[
{
"name": "resource class 1",
"cpu": 1.5,
"memory": 2,
"gpu": 0,
"max_storage": 100,
"id": 1,
"default": True,
"default_storage": 10,
},
{
"name": "resource class 2",
"cpu": 4.5,
"memory": 10,
"gpu": 2,
"default_storage": 10,
"max_storage": 10000,
"id": 2,
"default": False,
},
],
)


class ResourcePool(BaseAPISpec):
model_config = ConfigDict(
extra="forbid",
)
quota: Optional[Quota] = None
classes: List[ResourceClass] = Field(..., min_length=1)
classes: List[ResourceClass]
name: str = Field(
...,
description="A name for a specific resource",
Expand Down
Loading

0 comments on commit 58417b0

Please sign in to comment.