Skip to content

Commit eccb731

Browse files
feat(serverless): add health check spec to containers (#725)
Co-authored-by: Laure-di <62625835+Laure-di@users.noreply.github.com>
1 parent a2b54d0 commit eccb731

File tree

8 files changed

+432
-60
lines changed

8 files changed

+432
-60
lines changed

scaleway-async/scaleway_async/container/v1beta1/__init__.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@
2323
from .types import TriggerInputType
2424
from .types import TriggerStatus
2525
from .content import TRIGGER_TRANSIENT_STATUSES
26+
from .types import ContainerHealthCheckSpecHTTPProbe
27+
from .types import ContainerHealthCheckSpecTCPProbe
28+
from .types import ContainerHealthCheckSpec
2629
from .types import ContainerScalingOption
2730
from .types import SecretHashedValue
2831
from .types import TriggerMnqNatsClientConfig
@@ -100,6 +103,9 @@
100103
"TriggerInputType",
101104
"TriggerStatus",
102105
"TRIGGER_TRANSIENT_STATUSES",
106+
"ContainerHealthCheckSpecHTTPProbe",
107+
"ContainerHealthCheckSpecTCPProbe",
108+
"ContainerHealthCheckSpec",
103109
"ContainerScalingOption",
104110
"SecretHashedValue",
105111
"TriggerMnqNatsClientConfig",

scaleway-async/scaleway_async/container/v1beta1/api.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
ListTokensRequestOrderBy,
3030
ListTriggersRequestOrderBy,
3131
Container,
32+
ContainerHealthCheckSpec,
3233
ContainerScalingOption,
3334
CreateContainerRequest,
3435
CreateCronRequest,
@@ -603,6 +604,7 @@ async def create_container(
603604
sandbox: Optional[ContainerSandbox] = None,
604605
local_storage_limit: Optional[int] = None,
605606
scaling_option: Optional[ContainerScalingOption] = None,
607+
health_check: Optional[ContainerHealthCheckSpec] = None,
606608
) -> Container:
607609
"""
608610
Create a new container.
@@ -631,6 +633,7 @@ async def create_container(
631633
:param scaling_option: Possible values:
632634
- concurrent_requests_threshold: Scale depending on the number of concurrent requests being processed per container instance.
633635
- cpu_usage_threshold: Scale depending on the CPU usage of a container instance.
636+
:param health_check: Health check configuration of the container.
634637
:return: :class:`Container <Container>`
635638
636639
Usage:
@@ -671,6 +674,7 @@ async def create_container(
671674
sandbox=sandbox,
672675
local_storage_limit=local_storage_limit,
673676
scaling_option=scaling_option,
677+
health_check=health_check,
674678
),
675679
self.client,
676680
),
@@ -702,6 +706,7 @@ async def update_container(
702706
sandbox: Optional[ContainerSandbox] = None,
703707
local_storage_limit: Optional[int] = None,
704708
scaling_option: Optional[ContainerScalingOption] = None,
709+
health_check: Optional[ContainerHealthCheckSpec] = None,
705710
) -> Container:
706711
"""
707712
Update an existing container.
@@ -730,6 +735,8 @@ async def update_container(
730735
:param scaling_option: Possible values:
731736
- concurrent_requests_threshold: Scale depending on the number of concurrent requests being processed per container instance.
732737
- cpu_usage_threshold: Scale depending on the CPU usage of a container instance.
738+
:param health_check: Health check configuration of the container.
739+
733740
:return: :class:`Container <Container>`
734741
735742
Usage:
@@ -770,6 +777,7 @@ async def update_container(
770777
sandbox=sandbox,
771778
local_storage_limit=local_storage_limit,
772779
scaling_option=scaling_option,
780+
health_check=health_check,
773781
),
774782
self.client,
775783
),

scaleway-async/scaleway_async/container/v1beta1/marshalling.py

Lines changed: 142 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@
1010
resolve_one_of,
1111
)
1212
from .types import (
13+
ContainerHealthCheckSpecHTTPProbe,
14+
ContainerHealthCheckSpecTCPProbe,
15+
ContainerHealthCheckSpec,
1316
ContainerScalingOption,
1417
SecretHashedValue,
1518
Container,
@@ -45,6 +48,69 @@
4548
)
4649

4750

51+
def unmarshal_ContainerHealthCheckSpecHTTPProbe(
52+
data: Any,
53+
) -> ContainerHealthCheckSpecHTTPProbe:
54+
if not isinstance(data, dict):
55+
raise TypeError(
56+
"Unmarshalling the type 'ContainerHealthCheckSpecHTTPProbe' failed as data isn't a dictionary."
57+
)
58+
59+
args: Dict[str, Any] = {}
60+
61+
field = data.get("path", None)
62+
if field is not None:
63+
args["path"] = field
64+
65+
return ContainerHealthCheckSpecHTTPProbe(**args)
66+
67+
68+
def unmarshal_ContainerHealthCheckSpecTCPProbe(
69+
data: Any,
70+
) -> ContainerHealthCheckSpecTCPProbe:
71+
if not isinstance(data, dict):
72+
raise TypeError(
73+
"Unmarshalling the type 'ContainerHealthCheckSpecTCPProbe' failed as data isn't a dictionary."
74+
)
75+
76+
args: Dict[str, Any] = {}
77+
78+
return ContainerHealthCheckSpecTCPProbe(**args)
79+
80+
81+
def unmarshal_ContainerHealthCheckSpec(data: Any) -> ContainerHealthCheckSpec:
82+
if not isinstance(data, dict):
83+
raise TypeError(
84+
"Unmarshalling the type 'ContainerHealthCheckSpec' failed as data isn't a dictionary."
85+
)
86+
87+
args: Dict[str, Any] = {}
88+
89+
field = data.get("failure_threshold", None)
90+
if field is not None:
91+
args["failure_threshold"] = field
92+
93+
field = data.get("http", None)
94+
if field is not None:
95+
args["http"] = unmarshal_ContainerHealthCheckSpecHTTPProbe(field)
96+
else:
97+
args["http"] = None
98+
99+
field = data.get("tcp", None)
100+
if field is not None:
101+
args["tcp"] = unmarshal_ContainerHealthCheckSpecTCPProbe(field)
102+
else:
103+
args["tcp"] = None
104+
105+
field = data.get("interval", None)
106+
if field is not None:
107+
args["interval"] = field
108+
else:
109+
args["interval"] = None
110+
111+
return ContainerHealthCheckSpec(**args)
112+
113+
48114
def unmarshal_ContainerScalingOption(data: Any) -> ContainerScalingOption:
49115
if not isinstance(data, dict):
50116
raise TypeError(
@@ -139,22 +205,6 @@ def unmarshal_Container(data: Any) -> Container:
139205
if field is not None:
140206
args["registry_image"] = field
141207

142-
field = data.get("max_concurrency", None)
143-
if field is not None:
144-
args["max_concurrency"] = field
145-
146-
field = data.get("domain_name", None)
147-
if field is not None:
148-
args["domain_name"] = field
149-
150-
field = data.get("protocol", None)
151-
if field is not None:
152-
args["protocol"] = field
153-
154-
field = data.get("port", None)
155-
if field is not None:
156-
args["port"] = field
157-
158208
field = data.get("timeout", None)
159209
if field is not None:
160210
args["timeout"] = field
@@ -173,6 +223,22 @@ def unmarshal_Container(data: Any) -> Container:
173223
else:
174224
args["description"] = None
175225

226+
field = data.get("max_concurrency", None)
227+
if field is not None:
228+
args["max_concurrency"] = field
229+
230+
field = data.get("domain_name", None)
231+
if field is not None:
232+
args["domain_name"] = field
233+
234+
field = data.get("protocol", None)
235+
if field is not None:
236+
args["protocol"] = field
237+
238+
field = data.get("port", None)
239+
if field is not None:
240+
args["port"] = field
241+
176242
field = data.get("secret_environment_variables", None)
177243
if field is not None:
178244
args["secret_environment_variables"] = (
@@ -203,6 +269,12 @@ def unmarshal_Container(data: Any) -> Container:
203269
else:
204270
args["scaling_option"] = None
205271

272+
field = data.get("health_check", None)
273+
if field is not None:
274+
args["health_check"] = unmarshal_ContainerHealthCheckSpec(field)
275+
else:
276+
args["health_check"] = None
277+
206278
field = data.get("created_at", None)
207279
if field is not None:
208280
args["created_at"] = parser.isoparse(field) if isinstance(field, str) else field
@@ -696,6 +768,50 @@ def unmarshal_ListTriggersResponse(data: Any) -> ListTriggersResponse:
696768
return ListTriggersResponse(**args)
697769

698770

771+
def marshal_ContainerHealthCheckSpecHTTPProbe(
772+
request: ContainerHealthCheckSpecHTTPProbe,
773+
defaults: ProfileDefaults,
774+
) -> Dict[str, Any]:
775+
output: Dict[str, Any] = {}
776+
777+
if request.path is not None:
778+
output["path"] = request.path
779+
780+
return output
781+
782+
783+
def marshal_ContainerHealthCheckSpecTCPProbe(
784+
request: ContainerHealthCheckSpecTCPProbe,
785+
defaults: ProfileDefaults,
786+
) -> Dict[str, Any]:
787+
output: Dict[str, Any] = {}
788+
789+
return output
790+
791+
792+
def marshal_ContainerHealthCheckSpec(
793+
request: ContainerHealthCheckSpec,
794+
defaults: ProfileDefaults,
795+
) -> Dict[str, Any]:
796+
output: Dict[str, Any] = {}
797+
output.update(
798+
resolve_one_of(
799+
[
800+
OneOfPossibility("http", request.http),
801+
OneOfPossibility("tcp", request.tcp),
802+
]
803+
),
804+
)
805+
806+
if request.failure_threshold is not None:
807+
output["failure_threshold"] = request.failure_threshold
808+
809+
if request.interval is not None:
810+
output["interval"] = request.interval
811+
812+
return output
813+
814+
699815
def marshal_ContainerScalingOption(
700816
request: ContainerScalingOption,
701817
defaults: ProfileDefaults,
@@ -799,6 +915,11 @@ def marshal_CreateContainerRequest(
799915
request.scaling_option, defaults
800916
)
801917

918+
if request.health_check is not None:
919+
output["health_check"] = marshal_ContainerHealthCheckSpec(
920+
request.health_check, defaults
921+
)
922+
802923
return output
803924

804925

@@ -1043,6 +1164,11 @@ def marshal_UpdateContainerRequest(
10431164
request.scaling_option, defaults
10441165
)
10451166

1167+
if request.health_check is not None:
1168+
output["health_check"] = marshal_ContainerHealthCheckSpec(
1169+
request.health_check, defaults
1170+
)
1171+
10461172
return output
10471173

10481174

0 commit comments

Comments
 (0)