@@ -525,6 +525,12 @@ def run(self, namespace, name, image, entrypoint, command, **kwargs):
525525 if waited == timeout :
526526 raise KubeException ('Timed out (20 mins) while running' )
527527
528+ # check if it is possible to get logs
529+ state = self .pod_state (self .get_pod (namespace , name ).json ())
530+ # States below up do not have logs
531+ if state < PodState .up :
532+ return exit_code , 'Could not get logs. Pod is in state {}' .format (str (state ))
533+
528534 # grab log information
529535 log = self ._pod_log (namespace , name )
530536 log .encoding = 'utf-8' # defaults to "ISO-8859-1" otherwise...
@@ -698,8 +704,9 @@ def pod_state(self, pod):
698704 'Unknown' : PodState .error ,
699705 }
700706
701- # being in a Pending state can mean different things, introspecting app container first
702- if pod ['status' ]['phase' ] == 'Pending' :
707+ # being in a Pending/ContainerCreating state can mean different things
708+ # introspecting app container first
709+ if pod ['status' ]['phase' ] in ['Pending' , 'ContainerCreating' ]:
703710 pod_state , _ = self ._pod_pending_status (pod )
704711 # being in a running state can mean a pod is starting, actually running or terminating
705712 elif pod ['status' ]['phase' ] == 'Running' :
@@ -942,7 +949,7 @@ def _wait_until_pods_are_ready(self, namespace, containers, labels, desired, tim
942949 pods = self .get_pods (namespace , labels = labels ).json ()
943950 for pod in pods ['items' ]:
944951 # Get more information on why a pod is pending
945- if pod ['status' ]['phase' ] == 'Pending' :
952+ if pod ['status' ]['phase' ] in [ 'Pending' , 'ContainerCreating' ] :
946953 reason , message = self ._pod_pending_status (pod )
947954 # If pulling an image is taking long then increase the timeout
948955 timeout += self ._handle_pod_long_image_pulling (pod , reason )
@@ -1723,7 +1730,7 @@ def _wait_until_deployment_is_ready(self, namespace, name, **kwargs):
17231730 pods = self .get_pods (namespace , labels = labels ).json ()
17241731 for pod in pods ['items' ]:
17251732 # Get more information on why a pod is pending
1726- if pod ['status' ]['phase' ] == 'Pending' :
1733+ if pod ['status' ]['phase' ] in [ 'Pending' , 'ContainerCreating' ] :
17271734 reason , message = self ._pod_pending_status (pod )
17281735 # If pulling an image is taking long then increase the timeout
17291736 timeout += self ._handle_pod_long_image_pulling (pod , reason )
0 commit comments