1- """A kopf handler for the DataManagerJob CRD.
2- """
1+ """A kopf handler for the DataManagerJob CRD."""
32
43import os
54import shlex
109import kopf
1110import kubernetes
1211
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+
1320# Pod pre-delete delay (seconds).
1421# A fixed period of time the 'job_event' method waits
1522# after deciding to delete the Pod before actually deleting it.
@@ -273,8 +280,11 @@ def create(name, namespace, spec, **_):
273280
274281 kopf .adopt (configmap_dmk )
275282 try :
276- core_api .create_namespaced_config_map (namespace , configmap_dmk )
283+ core_api .create_namespaced_config_map (
284+ namespace , configmap_dmk , _request_timeout = _REQUEST_TIMEOUT
285+ )
277286 except kubernetes .client .exceptions .ApiException as ex :
287+ logging .warning ("Got ApiException creating DMK ConfigMap (%s)" , ex )
278288 # Whatever has happened treat it as a 'PermanentError',
279289 # thus preventing the operator from constantly re-trying.
280290 raise kopf .PermanentError (f"ApiException ({ ex .status } )" )
@@ -305,8 +315,11 @@ def create(name, namespace, spec, **_):
305315
306316 kopf .adopt (configmap_file )
307317 try :
308- core_api .create_namespaced_config_map (namespace , configmap_file )
318+ core_api .create_namespaced_config_map (
319+ namespace , configmap_file , _request_timeout = _REQUEST_TIMEOUT
320+ )
309321 except kubernetes .client .exceptions .ApiException as ex :
322+ logging .warning ("Got ApiException creating File ConfigMap (%s)" , ex )
310323 # Whatever has happened treat it as a 'PermanentError',
311324 # thus preventing the operator from constantly re-trying.
312325 raise kopf .PermanentError (f"ApiException ({ ex .status } )" )
@@ -462,8 +475,11 @@ def create(name, namespace, spec, **_):
462475 kopf .adopt (pod )
463476 api : kubernetes .client .CoreV1Api = kubernetes .client .CoreV1Api ()
464477 try :
465- api .create_namespaced_pod (body = pod , namespace = namespace )
478+ api .create_namespaced_pod (
479+ body = pod , namespace = namespace , _request_timeout = _REQUEST_TIMEOUT
480+ )
466481 except kubernetes .client .exceptions .ApiException as ex :
482+ logging .warning ("Got ApiException creating Pod (%s)" , ex )
467483 # Whatever has happened treat it as a 'PermanentError',
468484 # thus preventing the operator from constantly re-trying.
469485 raise kopf .PermanentError (f"ApiException ({ ex .status } )" )
@@ -523,7 +539,9 @@ def job_event(event, **_):
523539
524540 core_api : kubernetes .client .CoreV1Api = kubernetes .client .CoreV1Api ()
525541 try :
526- core_api .delete_namespaced_pod (pod_name , pod_namespace )
542+ core_api .delete_namespaced_pod (
543+ pod_name , pod_namespace , _request_timeout = _REQUEST_TIMEOUT
544+ )
527545 except kubernetes .client .exceptions .ApiException as ex :
528546 logging .warning (
529547 'ApiException (%s) deleting Pod "%s" (%s)' ,
@@ -539,7 +557,9 @@ def job_event(event, **_):
539557 logging .info ('Deleting ConfigMap "%s"...' , cm_name )
540558 core_api : kubernetes .client .CoreV1Api = kubernetes .client .CoreV1Api ()
541559 try :
542- core_api .delete_namespaced_config_map (cm_name , pod_namespace )
560+ core_api .delete_namespaced_config_map (
561+ cm_name , pod_namespace , _request_timeout = _REQUEST_TIMEOUT
562+ )
543563 except kubernetes .client .exceptions .ApiException as ex :
544564 logging .warning (
545565 'ApiException (%s) deleting ConfigMap "%s" (%s)' ,
0 commit comments