MCPcopy Create free account
hub / github.com/containerd/nerdctl / updateContainer

Function updateContainer

cmd/nerdctl/container/container_update.go:245–380  ·  view source on GitHub ↗
(ctx context.Context, client *containerd.Client, id string, opts updateResourceOptions, cmd *cobra.Command)

Source from the content-addressed store, hash-verified

243}
244
245func updateContainer(ctx context.Context, client *containerd.Client, id string, opts updateResourceOptions, cmd *cobra.Command) (retErr error) {
246 container, err := client.LoadContainer(ctx, id)
247 if err != nil {
248 return err
249 }
250 cStatus := formatter.ContainerStatus(ctx, container)
251 if cStatus == "pausing" {
252 return fmt.Errorf("container %q is in pausing state", id)
253 }
254 spec, err := container.Spec(ctx)
255 if err != nil {
256 return err
257 }
258
259 oldSpec, err := copySpec(spec)
260 if err != nil {
261 return err
262 }
263 if runtime.GOOS == "linux" {
264 if spec.Linux == nil {
265 spec.Linux = &runtimespec.Linux{}
266 }
267 if spec.Linux.Resources == nil {
268 spec.Linux.Resources = &runtimespec.LinuxResources{}
269 }
270 if cmd.Flags().Changed("blkio-weight") {
271 if spec.Linux.Resources.BlockIO == nil {
272 spec.Linux.Resources.BlockIO = &runtimespec.LinuxBlockIO{}
273 }
274 if spec.Linux.Resources.BlockIO.Weight != &opts.BlkioWeight {
275 spec.Linux.Resources.BlockIO.Weight = &opts.BlkioWeight
276 }
277 }
278 if cmd.Flags().Changed("cpu-shares") || cmd.Flags().Changed("cpu-quota") || cmd.Flags().Changed("cpu-period") || cmd.Flags().Changed("cpus") || cmd.Flags().Changed("cpuset-mems") || cmd.Flags().Changed("cpuset-cpus") {
279 if spec.Linux.Resources.CPU == nil {
280 spec.Linux.Resources.CPU = &runtimespec.LinuxCPU{}
281 }
282 }
283 if cmd.Flags().Changed("cpu-shares") {
284 if spec.Linux.Resources.CPU.Shares != &opts.CPUShares {
285 spec.Linux.Resources.CPU.Shares = &opts.CPUShares
286 }
287 }
288 if cmd.Flags().Changed("cpu-quota") {
289 if spec.Linux.Resources.CPU.Quota != &opts.CPUQuota {
290 spec.Linux.Resources.CPU.Quota = &opts.CPUQuota
291 }
292 }
293 if cmd.Flags().Changed("cpu-period") {
294 if spec.Linux.Resources.CPU.Period != &opts.CPUPeriod {
295 spec.Linux.Resources.CPU.Period = &opts.CPUPeriod
296 }
297 }
298 if cmd.Flags().Changed("cpus") {
299 if spec.Linux.Resources.CPU.Cpus != opts.CpusetCpus {
300 spec.Linux.Resources.CPU.Cpus = opts.CpusetCpus
301 }
302 }

Callers 1

updateActionFunction · 0.85

Calls 5

ContainerStatusFunction · 0.92
copySpecFunction · 0.85
updateContainerSpecFunction · 0.85
WithTimeoutMethod · 0.65
UpdateMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…