1
- """A kopf handler for the Jupyter CRD.
2
- """
1
+ """A kopf handler for the Jupyter CRD."""
3
2
4
3
import logging
5
4
import random
10
9
import kubernetes
11
10
import kopf
12
11
12
+ # Configuration of underlying API requests.
13
+ #
14
+ # Request timeout (from Python Kubernetes API)
15
+ # If one number provided, it will be total request
16
+ # timeout. It can also be a pair (tuple) of
17
+ # (connection, read) timeouts.
18
+ _REQUEST_TIMEOUT = (30 , 20 )
19
+
13
20
# Some (key) default deployment variables...
14
21
_DEFAULT_IMAGE : str = "jupyter/minimal-notebook:notebook-6.3.0"
15
22
_DEFAULT_SA : str = "default"
@@ -246,7 +253,9 @@ def create(spec: Dict[str, Any], name: str, namespace: str, **_: Any) -> Dict[st
246
253
#
247
254
# Added as a work-wround for sc-
248
255
try :
249
- core_api .create_namespaced_config_map (namespace , bp_cm_body )
256
+ core_api .create_namespaced_config_map (
257
+ namespace , bp_cm_body , _request_timeout = _REQUEST_TIMEOUT
258
+ )
250
259
except kubernetes .client .exceptions .ApiException as ex :
251
260
if ex .status != 409 or ex .reason != "Conflict" :
252
261
raise ex
@@ -255,8 +264,12 @@ def create(spec: Dict[str, Any], name: str, namespace: str, **_: Any) -> Dict[st
255
264
"Got ApiException [409/Conflict] creating BP ConfigMap. Ignoring [#10]"
256
265
)
257
266
return create_response
258
- core_api .create_namespaced_config_map (namespace , startup_cm_body )
259
- core_api .create_namespaced_config_map (namespace , config_cm_body )
267
+ core_api .create_namespaced_config_map (
268
+ namespace , startup_cm_body , _request_timeout = _REQUEST_TIMEOUT
269
+ )
270
+ core_api .create_namespaced_config_map (
271
+ namespace , config_cm_body , _request_timeout = _REQUEST_TIMEOUT
272
+ )
260
273
261
274
logging .info ("Created ConfigMaps" )
262
275
@@ -372,7 +385,9 @@ def create(spec: Dict[str, Any], name: str, namespace: str, **_: Any) -> Dict[st
372
385
373
386
kopf .adopt (deployment_body )
374
387
apps_api = kubernetes .client .AppsV1Api ()
375
- apps_api .create_namespaced_deployment (namespace , deployment_body )
388
+ apps_api .create_namespaced_deployment (
389
+ namespace , deployment_body , _request_timeout = _REQUEST_TIMEOUT
390
+ )
376
391
377
392
logging .info ("Created deployment" )
378
393
@@ -400,7 +415,9 @@ def create(spec: Dict[str, Any], name: str, namespace: str, **_: Any) -> Dict[st
400
415
}
401
416
402
417
kopf .adopt (service_body )
403
- core_api .create_namespaced_service (namespace , service_body )
418
+ core_api .create_namespaced_service (
419
+ namespace , service_body , _request_timeout = _REQUEST_TIMEOUT
420
+ )
404
421
405
422
logging .info ("Created service" )
406
423
@@ -449,7 +466,9 @@ def create(spec: Dict[str, Any], name: str, namespace: str, **_: Any) -> Dict[st
449
466
450
467
kopf .adopt (ingress_body )
451
468
ext_api = kubernetes .client .NetworkingV1Api ()
452
- ext_api .create_namespaced_ingress (namespace , ingress_body )
469
+ ext_api .create_namespaced_ingress (
470
+ namespace , ingress_body , _request_timeout = _REQUEST_TIMEOUT
471
+ )
453
472
454
473
logging .info ("Created ingress" )
455
474
0 commit comments