@@ -113,6 +113,16 @@ func GetChangedHealthCheckConfiguration(cmd *cobra.Command, vals *entities.Conta
113113 return updateHealthCheckConfig
114114}
115115
116+ func GetChangedDeviceLimits (s * specgen.SpecGenerator ) * define.UpdateContainerDevicesLimits {
117+ updateDevicesLimits := define.UpdateContainerDevicesLimits {}
118+ updateDevicesLimits .SetBlkIOWeightDevice (s .WeightDevice )
119+ updateDevicesLimits .SetDeviceReadBPs (s .ThrottleReadBpsDevice )
120+ updateDevicesLimits .SetDeviceWriteBPs (s .ThrottleWriteBpsDevice )
121+ updateDevicesLimits .SetDeviceReadIOPs (s .ThrottleReadIOPSDevice )
122+ updateDevicesLimits .SetDeviceWriteIOPs (s .ThrottleWriteIOPSDevice )
123+ return & updateDevicesLimits
124+ }
125+
116126func update (cmd * cobra.Command , args []string ) error {
117127 var err error
118128 // use a specgen since this is the easiest way to hold resource info
@@ -124,33 +134,35 @@ func update(cmd *cobra.Command, args []string) error {
124134 return err
125135 }
126136
127- if updateOpts .Restart != "" {
128- policy , retries , err := util .ParseRestartPolicy (updateOpts .Restart )
129- if err != nil {
130- return err
131- }
132- s .RestartPolicy = policy
133- if policy == define .RestartPolicyOnFailure {
134- s .RestartRetries = & retries
135- }
136- }
137-
138- // we need to pass the whole specgen since throttle devices are parsed later due to cross compat.
139137 s .ResourceLimits , err = specgenutil .GetResources (s , & updateOpts )
140138 if err != nil {
141139 return err
142140 }
143141
144- healthCheckConfig := GetChangedHealthCheckConfiguration (cmd , & updateOpts )
145- if err != nil {
146- return err
142+ if s .ResourceLimits == nil {
143+ s .ResourceLimits = & specs.LinuxResources {}
147144 }
148145
146+ healthCheckConfig := GetChangedHealthCheckConfiguration (cmd , & updateOpts )
147+
149148 opts := & entities.ContainerUpdateOptions {
150149 NameOrID : strings .TrimPrefix (args [0 ], "/" ),
151- Specgen : s ,
150+ Resources : s . ResourceLimits ,
152151 ChangedHealthCheckConfiguration : & healthCheckConfig ,
152+ DevicesLimits : GetChangedDeviceLimits (s ),
153+ }
154+
155+ if cmd .Flags ().Changed ("restart" ) {
156+ policy , retries , err := util .ParseRestartPolicy (updateOpts .Restart )
157+ if err != nil {
158+ return err
159+ }
160+ opts .RestartPolicy = & policy
161+ if policy == define .RestartPolicyOnFailure {
162+ opts .RestartRetries = & retries
163+ }
153164 }
165+
154166 rep , err := registry .ContainerEngine ().ContainerUpdate (context .Background (), opts )
155167 if err != nil {
156168 return err
0 commit comments