@@ -487,47 +487,44 @@ func (w *executor) loadContainerProbe(probe *model.ContainerProbe) *model.Contai
487487}
488488
489489func (w * executor ) runContainers (ctx context.Context , containers ... model.ContainerDefinition ) error {
490+ group := sync .NewGroup (0 )
491+
490492 for item := range containers {
491493 // fix: Implicit memory aliasing in for loop
492494 c := containers [item ]
493- updatePolicyMode := model .UpdatePolicyModeRestart
494- if ! GetForceUpdate (ctx ) && c .UpdatePolicy != nil && c .UpdatePolicy .OnNoChange != "" {
495- updatePolicyMode = c .UpdatePolicy .OnNoChange
496- }
497- mc := toRuntimeContainer (& c , model .RestartPolicyAlways )
498- switch updatePolicyMode {
499- case model .UpdatePolicyModeSkip :
500- can , err := canSkipRestart (ctx , w .runtime , mc )
501- if err != nil {
502- return err
495+ group .Go (func () error {
496+ updatePolicyMode := model .UpdatePolicyModeRestart
497+ if ! GetForceUpdate (ctx ) && c .UpdatePolicy != nil && c .UpdatePolicy .OnNoChange != "" {
498+ updatePolicyMode = c .UpdatePolicy .OnNoChange
503499 }
504- if can {
505- w .Infof ("update container %s and skip restart" , c .Name )
506- err = w .runtime .UpdateContainer (ctx , mc , & client.ContainerUpdateOptions {})
500+ mc := toRuntimeContainer (& c , model .RestartPolicyAlways )
501+ switch updatePolicyMode {
502+ case model .UpdatePolicyModeSkip :
503+ can , err := canSkipRestart (ctx , w .runtime , mc )
507504 if err != nil {
508505 return err
509506 }
510- continue
511- }
512- fallthrough
513- case model .UpdatePolicyModeRestart :
514- if err := w .doContainerPreRestart (ctx , c ); err != nil {
515- return fmt .Errorf ("pre-restart container %s: %w" , c .Name , err )
516- }
517- if _ , err := w .runtime .GetContainer (ctx , c .Name ); err == nil || ! errdefs .IsNotFound (err ) {
518- w .Infof ("remove container %s from containerd" , c .Name )
519- _ = w .runtime .RemoveContainer (ctx , c .Name )
520- }
521- w .Infof ("start and run container %s" , c .Name )
522- err := w .runtime .CreateContainer (ctx , mc , false )
523- if err != nil {
524- return err
507+ if can {
508+ w .Infof ("update container %s and skip restart" , c .Name )
509+ return w .runtime .UpdateContainer (ctx , mc , & client.ContainerUpdateOptions {})
510+ }
511+ fallthrough
512+ case model .UpdatePolicyModeRestart :
513+ if err := w .doContainerPreRestart (ctx , c ); err != nil {
514+ return fmt .Errorf ("pre-restart container %s: %w" , c .Name , err )
515+ }
516+ if _ , err := w .runtime .GetContainer (ctx , c .Name ); err == nil || ! errdefs .IsNotFound (err ) {
517+ w .Infof ("remove container %s from containerd" , c .Name )
518+ _ = w .runtime .RemoveContainer (ctx , c .Name )
519+ }
520+ w .Infof ("start and run container %s" , c .Name )
521+ return w .runtime .CreateContainer (ctx , mc , false )
522+ default :
523+ return fmt .Errorf ("unknown update policy mode: %s" , updatePolicyMode )
525524 }
526- default :
527- return fmt .Errorf ("unknown update policy mode: %s" , updatePolicyMode )
528- }
525+ })
529526 }
530- return nil
527+ return group . WaitResult ()
531528}
532529
533530func (w * executor ) removeAllInNamespace (ctx context.Context ) error {
0 commit comments