71
71
# As part of the startup we erase the existing '~/.bashrc' and,
72
72
# as a minimum, set a more suitable PS1 (see ch2385).
73
73
# 'conda init' then puts its stuff into the same file.
74
- _NOTEBOOK_STARTUP : str = """#!/bin/bash
74
+ _NOTEBOOK_STARTUP : str = r """#!/bin/bash
75
75
echo "PS1='\$(pwd) \$UID$ '" > ~/.bashrc
76
76
echo "umask 0002" >> ~/.bashrc
77
77
conda init
@@ -251,7 +251,7 @@ def create(spec: Dict[str, Any], name: str, namespace: str, **_: Any) -> Dict[st
251
251
# in kopf of kubernetes. For now, if the first object we create
252
252
# already exists let us assume they all do?
253
253
#
254
- # Added as a work-wround for sc-
254
+ # Added as a work-around for sc-
255
255
try :
256
256
core_api .create_namespaced_config_map (
257
257
namespace , bp_cm_body , _request_timeout = _REQUEST_TIMEOUT
@@ -263,13 +263,30 @@ def create(spec: Dict[str, Any], name: str, namespace: str, **_: Any) -> Dict[st
263
263
logging .warning (
264
264
"Got ApiException [409/Conflict] creating BP ConfigMap. Ignoring [#10]"
265
265
)
266
- return create_response
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
- )
266
+
267
+ try :
268
+ core_api .create_namespaced_config_map (
269
+ namespace , startup_cm_body , _request_timeout = _REQUEST_TIMEOUT
270
+ )
271
+ except kubernetes .client .exceptions .ApiException as ex :
272
+ if ex .status != 409 or ex .reason != "Conflict" :
273
+ raise ex
274
+ # Warn, but ignore and return a valid 'create' response now.
275
+ logging .warning (
276
+ "Got ApiException [409/Conflict] creating STARTUP ConfigMap. Ignoring [#10]"
277
+ )
278
+
279
+ try :
280
+ core_api .create_namespaced_config_map (
281
+ namespace , config_cm_body , _request_timeout = _REQUEST_TIMEOUT
282
+ )
283
+ except kubernetes .client .exceptions .ApiException as ex :
284
+ if ex .status != 409 or ex .reason != "Conflict" :
285
+ raise ex
286
+ # Warn, but ignore and return a valid 'create' response now.
287
+ logging .warning (
288
+ "Got ApiException [409/Conflict] creating CONFIG ConfigMap. Ignoring [#10]"
289
+ )
273
290
274
291
logging .info ("Created ConfigMaps" )
275
292
@@ -385,9 +402,17 @@ def create(spec: Dict[str, Any], name: str, namespace: str, **_: Any) -> Dict[st
385
402
386
403
kopf .adopt (deployment_body )
387
404
apps_api = kubernetes .client .AppsV1Api ()
388
- apps_api .create_namespaced_deployment (
389
- namespace , deployment_body , _request_timeout = _REQUEST_TIMEOUT
390
- )
405
+ try :
406
+ apps_api .create_namespaced_deployment (
407
+ namespace , deployment_body , _request_timeout = _REQUEST_TIMEOUT
408
+ )
409
+ except kubernetes .client .exceptions .ApiException as ex :
410
+ if ex .status != 409 or ex .reason != "Conflict" :
411
+ raise ex
412
+ # Warn, but ignore and return a valid 'create' response now.
413
+ logging .warning (
414
+ "Got ApiException [409/Conflict] creating CONFIG ConfigMap. Ignoring [#10]"
415
+ )
391
416
392
417
logging .info ("Created deployment" )
393
418
@@ -415,9 +440,17 @@ def create(spec: Dict[str, Any], name: str, namespace: str, **_: Any) -> Dict[st
415
440
}
416
441
417
442
kopf .adopt (service_body )
418
- core_api .create_namespaced_service (
419
- namespace , service_body , _request_timeout = _REQUEST_TIMEOUT
420
- )
443
+ try :
444
+ core_api .create_namespaced_service (
445
+ namespace , service_body , _request_timeout = _REQUEST_TIMEOUT
446
+ )
447
+ except kubernetes .client .exceptions .ApiException as ex :
448
+ if ex .status != 409 or ex .reason != "Conflict" :
449
+ raise ex
450
+ # Warn, but ignore and return a valid 'create' response now.
451
+ logging .warning (
452
+ "Got ApiException [409/Conflict] creating CONFIG ConfigMap. Ignoring [#10]"
453
+ )
421
454
422
455
logging .info ("Created service" )
423
456
@@ -466,9 +499,17 @@ def create(spec: Dict[str, Any], name: str, namespace: str, **_: Any) -> Dict[st
466
499
467
500
kopf .adopt (ingress_body )
468
501
ext_api = kubernetes .client .NetworkingV1Api ()
469
- ext_api .create_namespaced_ingress (
470
- namespace , ingress_body , _request_timeout = _REQUEST_TIMEOUT
471
- )
502
+ try :
503
+ ext_api .create_namespaced_ingress (
504
+ namespace , ingress_body , _request_timeout = _REQUEST_TIMEOUT
505
+ )
506
+ except kubernetes .client .exceptions .ApiException as ex :
507
+ if ex .status != 409 or ex .reason != "Conflict" :
508
+ raise ex
509
+ # Warn, but ignore and return a valid 'create' response now.
510
+ logging .warning (
511
+ "Got ApiException [409/Conflict] creating CONFIG ConfigMap. Ignoring [#10]"
512
+ )
472
513
473
514
logging .info ("Created ingress" )
474
515
0 commit comments