Skip to content

Commit b0a6da0

Browse files
Ralf GrubenmannPanaetius
authored andcommitted
refactor: add validation to crc, user and secrets endpoints
1 parent 278aedc commit b0a6da0

File tree

9 files changed

+144
-74
lines changed

9 files changed

+144
-74
lines changed

components/renku_data_services/crc/api.spec.yaml

Lines changed: 34 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -342,7 +342,7 @@ paths:
342342
content:
343343
"application/json":
344344
schema:
345-
$ref: "#/components/schemas/ResourceClassesWithId"
345+
$ref: "#/components/schemas/ResourceClassesWithIdResponse"
346346
"404":
347347
description: The resource pool does not exist
348348
content:
@@ -572,7 +572,7 @@ paths:
572572
content:
573573
"application/json":
574574
schema:
575-
$ref: "#/components/schemas/NodeAffinityList"
575+
$ref: "#/components/schemas/NodeAffinityListResponse"
576576
default:
577577
$ref: '#/components/responses/Error'
578578
tags:
@@ -994,8 +994,6 @@ components:
994994
type: array
995995
items:
996996
$ref: "#/components/schemas/ResourceClass"
997-
minItems: 1
998-
uniqueItems: true
999997
ResourceClassesWithId:
1000998
type: array
1001999
items:
@@ -1018,6 +1016,29 @@ components:
10181016
max_storage: 10000
10191017
id: 2
10201018
default: false
1019+
ResourceClassesWithIdResponse:
1020+
# Note: this needs to be separate from ResourceClassesWithId or it doesn't get generated
1021+
type: array
1022+
items:
1023+
$ref: "#/components/schemas/ResourceClassWithId"
1024+
uniqueItems: true
1025+
example:
1026+
- name: "resource class 1"
1027+
cpu: 1.5
1028+
memory: 2
1029+
gpu: 0
1030+
max_storage: 100
1031+
id: 1
1032+
default: true
1033+
default_storage: 10
1034+
- name: "resource class 2"
1035+
cpu: 4.5
1036+
memory: 10
1037+
gpu: 2
1038+
default_storage: 10
1039+
max_storage: 10000
1040+
id: 2
1041+
default: false
10211042
ResourceClassesPatchWithId:
10221043
type: array
10231044
items:
@@ -1456,6 +1477,15 @@ components:
14561477
example:
14571478
key: some-label-32
14581479
required_during_scheduling: true
1480+
NodeAffinityListResponse:
1481+
type: array
1482+
description: A list of k8s labels used for tolerations and/or node affinity
1483+
items:
1484+
$ref: "#/components/schemas/NodeAffinity"
1485+
example: [{"key": "test-label-1", "required_during_scheduling": false}]
1486+
uniqueItems: true
1487+
default: []
1488+
minItems: 0
14591489
NodeAffinityList:
14601490
type: array
14611491
description: A list of k8s labels used for tolerations and/or node affinity

components/renku_data_services/crc/apispec.py

Lines changed: 39 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# generated by datamodel-codegen:
22
# filename: api.spec.yaml
3-
# timestamp: 2024-08-06T07:19:45+00:00
3+
# timestamp: 2024-08-07T07:12:13+00:00
44

55
from __future__ import annotations
66

@@ -64,6 +64,15 @@ class NodeAffinity(BaseAPISpec):
6464
required_during_scheduling: bool = False
6565

6666

67+
class NodeAffinityListResponse(RootModel[List[NodeAffinity]]):
68+
root: List[NodeAffinity] = Field(
69+
[],
70+
description="A list of k8s labels used for tolerations and/or node affinity",
71+
example=[{"key": "test-label-1", "required_during_scheduling": False}],
72+
min_length=0,
73+
)
74+
75+
6776
class Error(BaseAPISpec):
6877
code: int = Field(..., example=1404, gt=0)
6978
detail: Optional[str] = Field(
@@ -508,12 +517,40 @@ class ResourceClassWithIdFiltered(BaseAPISpec):
508517
)
509518

510519

520+
class ResourceClassesWithIdResponse(RootModel[List[ResourceClassWithId]]):
521+
root: List[ResourceClassWithId] = Field(
522+
...,
523+
example=[
524+
{
525+
"name": "resource class 1",
526+
"cpu": 1.5,
527+
"memory": 2,
528+
"gpu": 0,
529+
"max_storage": 100,
530+
"id": 1,
531+
"default": True,
532+
"default_storage": 10,
533+
},
534+
{
535+
"name": "resource class 2",
536+
"cpu": 4.5,
537+
"memory": 10,
538+
"gpu": 2,
539+
"default_storage": 10,
540+
"max_storage": 10000,
541+
"id": 2,
542+
"default": False,
543+
},
544+
],
545+
)
546+
547+
511548
class ResourcePool(BaseAPISpec):
512549
model_config = ConfigDict(
513550
extra="forbid",
514551
)
515552
quota: Optional[Quota] = None
516-
classes: List[ResourceClass] = Field(..., min_length=1)
553+
classes: List[ResourceClass]
517554
name: str = Field(
518555
...,
519556
description="A name for a specific resource",

0 commit comments

Comments
 (0)