@@ -417,9 +417,6 @@ func (rs *ReplicaSetService) RollbackContainer(name string, spec *models.Rollbac
417417}
418418
419419func (rs * ReplicaSetService ) patchGpu (name string , spec * models.GpuPatch , info * models.EtcdContainerInfo ) (* models.EtcdContainerInfo , error ) {
420- if spec == nil {
421- return info , nil
422- }
423420 running , err := rs .containerStatusRunning (name )
424421 if err != nil {
425422 return info , errors .WithMessage (err , "services.containerStatusRunning failed" )
@@ -434,8 +431,16 @@ func (rs *ReplicaSetService) patchGpu(name string, spec *models.GpuPatch, info *
434431 return info , errors .WithMessage (err , "services.containerDeviceRequestsDeviceIDs failed" )
435432 }
436433
437- if len (uuids ) == spec .GpuCount {
438- return info , nil
434+ if spec != nil {
435+ if len (uuids ) == spec .GpuCount && (running || pause ) {
436+ return info , nil
437+ }
438+ }
439+
440+ if spec == nil {
441+ spec = & models.GpuPatch {
442+ GpuCount : len (uuids ),
443+ }
439444 }
440445
441446 if running || pause {
@@ -461,9 +466,6 @@ func (rs *ReplicaSetService) patchGpu(name string, spec *models.GpuPatch, info *
461466}
462467
463468func (rs * ReplicaSetService ) patchCpu (name string , spec * models.CpuPatch , info * models.EtcdContainerInfo ) (* models.EtcdContainerInfo , error ) {
464- if spec == nil {
465- return info , nil
466- }
467469 running , err := rs .containerStatusRunning (name )
468470 if err != nil {
469471 return info , errors .WithMessage (err , "services.containerStatusRunning failed" )
@@ -478,8 +480,16 @@ func (rs *ReplicaSetService) patchCpu(name string, spec *models.CpuPatch, info *
478480 return info , errors .WithMessage (err , "services.containerDeviceRequestsDeviceIDs failed" )
479481 }
480482
481- if len (cpuset ) == spec .CpuCount && (running || pause ) {
482- return info , nil
483+ if spec != nil {
484+ if len (cpuset ) == spec .CpuCount && (running || pause ) {
485+ return info , nil
486+ }
487+ }
488+
489+ if spec == nil {
490+ spec = & models.CpuPatch {
491+ CpuCount : len (cpuset ),
492+ }
483493 }
484494
485495 if running || pause {
0 commit comments