@@ -485,10 +485,12 @@ def events(self, pod):
485485 'involvedObject.namespace' : pod ['metadata' ]['namespace' ],
486486 'involvedObject.uid' : pod ['metadata' ]['uid' ]
487487 }
488- events = self .ns .events (pod ['metadata' ]['namespace' ], fields = fields ).json ()
488+ events = self .ns .events (pod ['metadata' ]['namespace' ], fields = fields ).json ()['items' ]
489+ if not events :
490+ events = []
489491 # make sure that events are sorted
490- events [ 'items' ] .sort (key = lambda x : x ['lastTimestamp' ])
491- return events [ 'items' ]
492+ events .sort (key = lambda x : x ['lastTimestamp' ])
493+ return events
492494
493495 def _handle_pod_errors (self , pod , reason , message ):
494496 """
@@ -568,8 +570,10 @@ def _handle_pending_pods(self, namespace, labels):
568570 or throws errors as needed
569571 """
570572 timeout = 0
571- pods = self .get (namespace , labels = labels ).json ()
572- for pod in pods ['items' ]:
573+ pods = self .get (namespace , labels = labels ).json ()['items' ]
574+ if not pods :
575+ pods = []
576+ for pod in pods :
573577 # only care about pods that are not starting or in the starting phases
574578 if pod ['status' ]['phase' ] not in ['Pending' , 'ContainerCreating' ]:
575579 continue
@@ -612,14 +616,16 @@ def wait_until_terminated(self, namespace, labels, current, desired):
612616 delta = current - desired
613617 self .log (namespace , "waiting for {} pods to be terminated ({}s timeout)" .format (delta , timeout )) # noqa
614618 for waited in range (timeout ):
615- pods = self .get (namespace , labels = labels ).json ()
616- count = len (pods ['items' ])
619+ pods = self .get (namespace , labels = labels ).json ()['items' ]
620+ if not pods :
621+ pods = []
622+ count = len (pods )
617623
618624 # see if any pods are past their terminationGracePeriodsSeconds (as in stuck)
619625 # seems to be a problem in k8s around that:
620626 # https://github.com/kubernetes/kubernetes/search?q=terminating&type=Issues
621627 # these will be eventually GC'ed by k8s, ignoring them for now
622- for pod in pods [ 'items' ] :
628+ for pod in pods :
623629 # remove pod if it is passed the graceful termination period
624630 if self .deleted (pod ):
625631 count -= 1
@@ -655,8 +661,10 @@ def wait_until_ready(self, namespace, containers, labels, desired, timeout): #
655661 self .log (namespace , 'Increasing timeout by {}s to allow a pull image operation to finish for pods' .format (additional_timeout )) # noqa
656662
657663 count = 0 # ready pods
658- pods = self .get (namespace , labels = labels ).json ()
659- for pod in pods ['items' ]:
664+ pods = self .get (namespace , labels = labels ).json ()['items' ]
665+ if not pods :
666+ pods = []
667+ for pod in pods :
660668 # now that state is running time to see if probes are passing
661669 if self .ready (pod ):
662670 count += 1
@@ -691,8 +699,10 @@ def _handle_not_ready_pods(self, namespace, labels):
691699 Detects if any pod is in the Running phase but not Ready and handles
692700 any potential issues around that mainly failed healthcheks
693701 """
694- pods = self .get (namespace , labels = labels ).json ()
695- for pod in pods ['items' ]:
702+ pods = self .get (namespace , labels = labels ).json ()['items' ]
703+ if not pods :
704+ pods = []
705+ for pod in pods :
696706 # only care about pods that are in running phase
697707 if pod ['status' ]['phase' ] != 'Running' :
698708 continue
0 commit comments