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

Function getUpdateOption

cmd/nerdctl/container/container_update.go:122–243  ·  view source on GitHub ↗
(cmd *cobra.Command, globalOptions types.GlobalCommandOptions)

Source from the content-addressed store, hash-verified

120}
121
122func getUpdateOption(cmd *cobra.Command, globalOptions types.GlobalCommandOptions) (updateResourceOptions, error) {
123 var options updateResourceOptions
124 cpus, err := cmd.Flags().GetFloat64("cpus")
125 if err != nil {
126 return options, err
127 }
128 cpuPeriod, err := cmd.Flags().GetUint64("cpu-period")
129 if err != nil {
130 return options, err
131 }
132 cpuQuota, err := cmd.Flags().GetInt64("cpu-quota")
133 if err != nil {
134 return options, err
135 }
136 if cpuQuota != -1 || cpuPeriod != 0 {
137 if cpus > 0.0 {
138 return options, errors.New("cpus and quota/period should be used separately")
139 }
140 }
141 if cpus > 0.0 {
142 cpuPeriod = uint64(100000)
143 cpuQuota = int64(cpus * 100000.0)
144 }
145 shares, err := cmd.Flags().GetUint64("cpu-shares")
146 if err != nil {
147 return options, err
148 }
149 memStr, err := cmd.Flags().GetString("memory")
150 if err != nil {
151 return options, err
152 }
153 memSwap, err := cmd.Flags().GetString("memory-swap")
154 if err != nil {
155 return options, err
156 }
157 var mem64 int64
158 if memStr != "" {
159 mem64, err = units.RAMInBytes(memStr)
160 if err != nil {
161 return options, fmt.Errorf("failed to parse memory bytes %q: %w", memStr, err)
162 }
163 }
164 var memSwap64 int64
165 if memSwap != "" {
166 if memSwap == "-1" {
167 memSwap64 = -1
168 } else {
169 memSwap64, err = units.RAMInBytes(memSwap)
170 if err != nil {
171 return options, fmt.Errorf("failed to parse memory-swap bytes %q: %w", memSwap, err)
172 }
173 if mem64 > 0 && memSwap64 > 0 && memSwap64 < mem64 {
174 return options, fmt.Errorf("minimum memoryswap limit should be larger than memory limit, see usage")
175 }
176 }
177 } else {
178 memSwap64 = mem64 * 2
179 }

Callers 1

updateActionFunction · 0.85

Calls 1

BlockIOWeightFunction · 0.92

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…