(ctx context.Context, dockerCli command.Cli, options *updateOptions)
| 89 | } |
| 90 | |
| 91 | func runUpdate(ctx context.Context, dockerCli command.Cli, options *updateOptions) error { |
| 92 | var err error |
| 93 | |
| 94 | if options.nFlag == 0 { |
| 95 | return errors.New("you must provide one or more flags when using this command") |
| 96 | } |
| 97 | |
| 98 | var restartPolicy containertypes.RestartPolicy |
| 99 | if options.restartPolicy != "" { |
| 100 | restartPolicy, err = opts.ParseRestartPolicy(options.restartPolicy) |
| 101 | if err != nil { |
| 102 | return err |
| 103 | } |
| 104 | } |
| 105 | |
| 106 | var pidsLimit *int64 |
| 107 | if options.pidsLimit != 0 { |
| 108 | pidsLimit = &options.pidsLimit |
| 109 | } |
| 110 | |
| 111 | updateConfig := client.ContainerUpdateOptions{ |
| 112 | Resources: &containertypes.Resources{ |
| 113 | BlkioWeight: options.blkioWeight, |
| 114 | CpusetCpus: options.cpusetCpus, |
| 115 | CpusetMems: options.cpusetMems, |
| 116 | CPUShares: options.cpuShares, |
| 117 | Memory: options.memory.Value(), |
| 118 | MemoryReservation: options.memoryReservation.Value(), |
| 119 | MemorySwap: options.memorySwap.Value(), |
| 120 | CPUPeriod: options.cpuPeriod, |
| 121 | CPUQuota: options.cpuQuota, |
| 122 | CPURealtimePeriod: options.cpuRealtimePeriod, |
| 123 | CPURealtimeRuntime: options.cpuRealtimeRuntime, |
| 124 | NanoCPUs: options.cpus.Value(), |
| 125 | PidsLimit: pidsLimit, |
| 126 | }, |
| 127 | RestartPolicy: &restartPolicy, |
| 128 | } |
| 129 | |
| 130 | var ( |
| 131 | warns []string |
| 132 | errs []error |
| 133 | ) |
| 134 | for _, ctr := range options.containers { |
| 135 | r, err := dockerCli.Client().ContainerUpdate(ctx, ctr, updateConfig) |
| 136 | if err != nil { |
| 137 | errs = append(errs, err) |
| 138 | } else { |
| 139 | _, _ = fmt.Fprintln(dockerCli.Out(), ctr) |
| 140 | } |
| 141 | warns = append(warns, r.Warnings...) |
| 142 | } |
| 143 | if len(warns) > 0 { |
| 144 | _, _ = fmt.Fprintln(dockerCli.Out(), strings.Join(warns, "\n")) |
| 145 | } |
| 146 | return errors.Join(errs...) |
| 147 | } |
no test coverage detected
searching dependent graphs…