| 240 | } |
| 241 | |
| 242 | func (r *resourceOptions) ToResourceRequirements(flags *pflag.FlagSet) (*swarm.ResourceRequirements, error) { |
| 243 | generic, err := ParseGenericResources(r.resGenericResources) |
| 244 | if err != nil { |
| 245 | return nil, err |
| 246 | } |
| 247 | |
| 248 | resreq := &swarm.ResourceRequirements{ |
| 249 | Limits: &swarm.Limit{ |
| 250 | NanoCPUs: r.limitCPU.Value(), |
| 251 | MemoryBytes: r.limitMemBytes.Value(), |
| 252 | Pids: r.limitPids, |
| 253 | }, |
| 254 | Reservations: &swarm.Resources{ |
| 255 | NanoCPUs: r.resCPU.Value(), |
| 256 | MemoryBytes: r.resMemBytes.Value(), |
| 257 | GenericResources: generic, |
| 258 | }, |
| 259 | } |
| 260 | |
| 261 | // SwapBytes and MemorySwappiness are *int64 (pointers), so we need to have |
| 262 | // a variable we can take a pointer to. Additionally, we need to ensure |
| 263 | // that these values are only set if they are set as options. |
| 264 | if flags.Changed(flagSwapBytes) { |
| 265 | swapBytes := r.swapBytes.Value() |
| 266 | resreq.SwapBytes = &swapBytes |
| 267 | } |
| 268 | if flags.Changed(flagMemSwappiness) { |
| 269 | resreq.MemorySwappiness = &r.memSwappiness |
| 270 | } |
| 271 | |
| 272 | return resreq, nil |
| 273 | } |
| 274 | |
| 275 | type restartPolicyOptions struct { |
| 276 | condition string |