@@ -356,84 +356,27 @@ def delete(self, *args, **kwargs):
356356
357357 def restart (self , ** kwargs ): # noqa
358358 """
359- Restart found pods by deleting them (RC / Deployment will recreate).
360- Wait until they are all drained away and RC / Deployment has gotten to a good state
359+ Restart deployments with the kubectl rollout api
361360 """
362- try :
363- # Resolve single pod name if short form (cmd-1269180282-1nyfz) is passed
364- if 'name' in kwargs and kwargs ['name' ].count ('-' ) == 2 :
365- kwargs ['name' ] = '{}-{}' .format (kwargs ['id' ], kwargs ['name' ])
366-
367- # Iterate over RCs / RSs to get total desired count if not a single item
368- desired = 1
369- if 'name' not in kwargs :
370- desired = 0
371- labels = self ._scheduler_filter (** kwargs )
372- # fetch RS (which represent Deployments)
373- controllers = self ._scheduler .rs .get (kwargs ['id' ], labels = labels ).json ()['items' ]
374- if not controllers :
375- controllers = []
376- for controller in controllers :
377- desired += controller ['spec' ]['replicas' ]
378- except KubeException :
379- # Nothing was found
380- return []
381-
361+ deployments = []
362+ if 'type' in kwargs and kwargs ['type' ] in self .structure :
363+ deployments .append (self ._get_job_id (kwargs ['type' ]))
364+ else :
365+ for scale_type , _ in self .structure .items ():
366+ deployments .append (self ._get_job_id (scale_type ))
382367 try :
383368 tasks = [
384369 functools .partial (
385- self ._scheduler .pod . delete ,
370+ self ._scheduler .deployment . restart ,
386371 self .id ,
387- pod [ 'name' ]
388- ) for pod in self . list_pods ( ** kwargs )
372+ deployment
373+ ) for deployment in deployments
389374 ]
390-
391375 apply_tasks (tasks )
392376 except Exception as e :
393- err = "warning, some pods failed to stop :\n {}" .format (str (e ))
377+ err = "warning, some pods failed to restart :\n {}" .format (str (e ))
394378 self .log (err , logging .WARNING )
395379
396- # Wait for pods to start
397- try :
398- timeout = 300 # 5 minutes
399- elapsed = 0
400- while True :
401- # timed out
402- if elapsed >= timeout :
403- raise DryccException ('timeout - 5 minutes have passed and pods are not up' )
404-
405- # restarting a single pod behaves differently, fetch the *newest* pod
406- # and hope it is the right one. Comes back sorted
407- if 'name' in kwargs :
408- del kwargs ['name' ]
409- pods = self .list_pods (** kwargs )
410- # Add in the latest name
411- if len (pods ) == 0 :
412- # if pod is not even scheduled wait for it and pass dummy kwargs
413- # to indicate restart of a single pod
414- kwargs ['name' ] = "dummy"
415- continue
416- kwargs ['name' ] = pods [0 ]['name' ]
417- pods = pods [0 ]
418-
419- actual = 0
420- for pod in self .list_pods (** kwargs ):
421- if pod ['state' ] == 'up' :
422- actual += 1
423-
424- if desired == actual :
425- break
426-
427- elapsed += 5
428- time .sleep (5 )
429- except Exception as e :
430- err = "warning, some pods failed to start:\n {}" .format (str (e ))
431- self .log (err , logging .WARNING )
432-
433- # Return the new pods
434- pods = self .list_pods (** kwargs )
435- return pods
436-
437380 def _clean_app_logs (self ):
438381 """Delete application logs stored by the logger component"""
439382 try :
0 commit comments