@@ -318,6 +318,10 @@ class ShimClient:
318318 # `/api/shutdown`
319319 _SHUTDOWN_MIN_SHIM_VERSION = (0 , 20 , 1 )
320320
321+ # Whether it is safe to restart the shim while at least one task is still running
322+ # (not terminated). Other task statuses are not restart-safe regardless of the shim version
323+ _RESTART_SAFE_RUNNING_STATUS_MIN_SHIM_VERSION = (0 , 21 , 3 )
324+
321325 _shim_version_string : str
322326 _shim_version_tuple : Optional ["_Version" ]
323327 _api_version : int
@@ -358,36 +362,16 @@ def is_api_v2_supported(self) -> bool:
358362 return self ._api_version == 2
359363
360364 def is_instance_health_supported (self ) -> bool :
361- if not self ._negotiated :
362- self ._negotiate ()
363- return (
364- self ._shim_version_tuple is None
365- or self ._shim_version_tuple >= self ._INSTANCE_HEALTH_MIN_SHIM_VERSION
366- )
365+ return self ._check_min_version (self ._INSTANCE_HEALTH_MIN_SHIM_VERSION )
367366
368367 def is_instance_info_supported (self ) -> bool :
369- if not self ._negotiated :
370- self ._negotiate ()
371- return (
372- self ._shim_version_tuple is None
373- or self ._shim_version_tuple >= self ._INSTANCE_INFO_MIN_SHIM_VERSION
374- )
368+ return self ._check_min_version (self ._INSTANCE_INFO_MIN_SHIM_VERSION )
375369
376370 def are_components_supported (self ) -> bool :
377- if not self ._negotiated :
378- self ._negotiate ()
379- return (
380- self ._shim_version_tuple is None
381- or self ._shim_version_tuple >= self ._COMPONENTS_MIN_SHIM_VERSION
382- )
371+ return self ._check_min_version (self ._COMPONENTS_MIN_SHIM_VERSION )
383372
384373 def is_shutdown_supported (self ) -> bool :
385- if not self ._negotiated :
386- self ._negotiate ()
387- return (
388- self ._shim_version_tuple is None
389- or self ._shim_version_tuple >= self ._SHUTDOWN_MIN_SHIM_VERSION
390- )
374+ return self ._check_min_version (self ._SHUTDOWN_MIN_SHIM_VERSION )
391375
392376 @overload
393377 def healthcheck (self ) -> Optional [HealthcheckResponse ]: ...
@@ -670,12 +654,15 @@ def _negotiate(self, healthcheck_response: Optional[requests.Response] = None) -
670654 self ._api_version = api_version
671655 self ._negotiated = True
672656
657+ def _check_min_version (self , min_version : "_Version" ) -> bool :
658+ current_version = self .get_version_tuple ()
659+ return current_version is None or current_version >= min_version
660+
673661 def _get_restart_safe_task_statuses (self ) -> list [TaskStatus ]:
674- # TODO: Rework shim's DockerRunner.Run() so that it does not wait for container termination
675- # (this at least requires replacing .waitContainer() with periodic polling of container
676- # statuses and moving some cleanup defer calls to .Terminate() and/or .Remove()) and add
677- # TaskStatus.RUNNING to the list of restart-safe task statuses for supported shim versions.
678- return [TaskStatus .TERMINATED ]
662+ statuses = [TaskStatus .TERMINATED ]
663+ if self ._check_min_version (self ._RESTART_SAFE_RUNNING_STATUS_MIN_SHIM_VERSION ):
664+ statuses .append (TaskStatus .RUNNING )
665+ return statuses
679666
680667
681668def _make_session_and_base_url (
0 commit comments