forked from AliyunContainerService/pouch
-
Notifications
You must be signed in to change notification settings - Fork 0
/
resources.go
664 lines (471 loc) · 16.5 KB
/
resources.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
// Code generated by go-swagger; DO NOT EDIT.
package types
// This file was generated by the swagger tool.
// Editing this file might prove futile when you re-run the swagger generate command
import (
"strconv"
strfmt "github.com/go-openapi/strfmt"
"github.com/go-openapi/errors"
"github.com/go-openapi/swag"
"github.com/go-openapi/validate"
)
// Resources A container's resources (cgroups config, ulimits, etc)
// swagger:model Resources
type Resources struct {
// Limit read rate (bytes per second) from a device, in the form `[{"Path": "device_path", "Rate": rate}]`.
//
BlkioDeviceReadBps []*ThrottleDevice `json:"BlkioDeviceReadBps"`
// Limit read rate (IO per second) from a device, in the form `[{"Path": "device_path", "Rate": rate}]`.
//
BlkioDeviceReadIOps []*ThrottleDevice `json:"BlkioDeviceReadIOps"`
// Limit write rate (bytes per second) to a device, in the form `[{"Path": "device_path", "Rate": rate}]`.
//
BlkioDeviceWriteBps []*ThrottleDevice `json:"BlkioDeviceWriteBps"`
// Limit write rate (IO per second) to a device, in the form `[{"Path": "device_path", "Rate": rate}]`.
//
BlkioDeviceWriteIOps []*ThrottleDevice `json:"BlkioDeviceWriteIOps"`
// Block IO weight (relative weight), need CFQ IO Scheduler enable.
// Maximum: 1000
// Minimum: 0
BlkioWeight uint16 `json:"BlkioWeight,omitempty"`
// Block IO weight (relative device weight) in the form `[{"Path": "device_path", "Weight": weight}]`.
//
BlkioWeightDevice []*WeightDevice `json:"BlkioWeightDevice"`
// Path to `cgroups` under which the container's `cgroup` is created. If the path is not absolute, the path is considered to be relative to the `cgroups` path of the init process. Cgroups are created if they do not already exist.
CgroupParent string `json:"CgroupParent,omitempty"`
// The number of usable CPUs (Windows only).
// On Windows Server containers, the processor resource controls are mutually exclusive. The order of precedence is `CPUCount` first, then `CPUShares`, and `CPUPercent` last.
//
CPUCount int64 `json:"CpuCount,omitempty"`
// The usable percentage of the available CPUs (Windows only).
// On Windows Server containers, the processor resource controls are mutually exclusive. The order of precedence is `CPUCount` first, then `CPUShares`, and `CPUPercent` last.
//
CPUPercent int64 `json:"CpuPercent,omitempty"`
// CPU CFS (Completely Fair Scheduler) period.
// The length of a CPU period in microseconds.
//
// Maximum: 1e+06
// Minimum: 1000
CPUPeriod int64 `json:"CpuPeriod,omitempty"`
// CPU CFS (Completely Fair Scheduler) quota.
// Microseconds of CPU time that the container can get in a CPU period."
//
// Minimum: 1000
CPUQuota int64 `json:"CpuQuota,omitempty"`
// The length of a CPU real-time period in microseconds. Set to 0 to allocate no time allocated to real-time tasks.
CPURealtimePeriod int64 `json:"CpuRealtimePeriod,omitempty"`
// The length of a CPU real-time runtime in microseconds. Set to 0 to allocate no time allocated to real-time tasks.
CPURealtimeRuntime int64 `json:"CpuRealtimeRuntime,omitempty"`
// An integer value representing this container's relative CPU weight versus other containers.
CPUShares int64 `json:"CpuShares,omitempty"`
// CPUs in which to allow execution (e.g., `0-3`, `0,1`)
CpusetCpus string `json:"CpusetCpus,omitempty"`
// Memory nodes (MEMs) in which to allow execution (0-3, 0,1). Only effective on NUMA systems.
CpusetMems string `json:"CpusetMems,omitempty"`
// a list of cgroup rules to apply to the container
DeviceCgroupRules []string `json:"DeviceCgroupRules"`
// A list of devices to add to the container.
Devices []*DeviceMapping `json:"Devices"`
// Maximum IO in bytes per second for the container system drive (Windows only)
IOMaximumBandwidth uint64 `json:"IOMaximumBandwidth,omitempty"`
// Maximum IOps for the container system drive (Windows only)
IOMaximumIOps uint64 `json:"IOMaximumIOps,omitempty"`
// IntelRdtL3Cbm specifies settings for Intel RDT/CAT group that the container is placed into to limit the resources (e.g., L3 cache) the container has available.
IntelRdtL3Cbm string `json:"IntelRdtL3Cbm,omitempty"`
// Kernel memory limit in bytes.
KernelMemory int64 `json:"KernelMemory,omitempty"`
// Memory limit in bytes.
Memory int64 `json:"Memory,omitempty"`
// MemoryExtra is an integer value representing this container's memory high water mark percentage.
// The range is in [0, 100].
//
// Maximum: 100
// Minimum: 0
MemoryExtra *int64 `json:"MemoryExtra,omitempty"`
// MemoryForceEmptyCtl represents whether to reclaim the page cache when deleting cgroup.
// Maximum: 1
// Minimum: 0
MemoryForceEmptyCtl int64 `json:"MemoryForceEmptyCtl,omitempty"`
// Memory soft limit in bytes.
MemoryReservation int64 `json:"MemoryReservation,omitempty"`
// Total memory limit (memory + swap). Set as `-1` to enable unlimited swap.
MemorySwap int64 `json:"MemorySwap,omitempty"`
// Tune a container's memory swappiness behavior. Accepts an integer between 0 and 100.
// Maximum: 100
// Minimum: -1
MemorySwappiness *int64 `json:"MemorySwappiness,omitempty"`
// MemoryWmarkRatio is an integer value representing this container's memory low water mark percentage.
// The value of memory low water mark is memory.limit_in_bytes * MemoryWmarkRatio. The range is in [0, 100].
//
// Maximum: 100
// Minimum: 0
MemoryWmarkRatio *int64 `json:"MemoryWmarkRatio,omitempty"`
// CPU quota in units of 10<sup>-9</sup> CPUs.
NanoCpus int64 `json:"NanoCPUs,omitempty"`
// Disable OOM Killer for the container.
OomKillDisable *bool `json:"OomKillDisable,omitempty"`
// Tune a container's pids limit. Set -1 for unlimited. Only on Linux 4.4 does this parameter support.
//
PidsLimit int64 `json:"PidsLimit,omitempty"`
// ScheLatSwitch enables scheduler latency count in cpuacct
// Maximum: 1
// Minimum: 0
ScheLatSwitch int64 `json:"ScheLatSwitch,omitempty"`
// A list of resource limits to set in the container. For example: `{"Name": "nofile", "Soft": 1024, "Hard": 2048}`"
//
Ulimits []*Ulimit `json:"Ulimits"`
}
/* polymorph Resources BlkioDeviceReadBps false */
/* polymorph Resources BlkioDeviceReadIOps false */
/* polymorph Resources BlkioDeviceWriteBps false */
/* polymorph Resources BlkioDeviceWriteIOps false */
/* polymorph Resources BlkioWeight false */
/* polymorph Resources BlkioWeightDevice false */
/* polymorph Resources CgroupParent false */
/* polymorph Resources CpuCount false */
/* polymorph Resources CpuPercent false */
/* polymorph Resources CpuPeriod false */
/* polymorph Resources CpuQuota false */
/* polymorph Resources CpuRealtimePeriod false */
/* polymorph Resources CpuRealtimeRuntime false */
/* polymorph Resources CpuShares false */
/* polymorph Resources CpusetCpus false */
/* polymorph Resources CpusetMems false */
/* polymorph Resources DeviceCgroupRules false */
/* polymorph Resources Devices false */
/* polymorph Resources IOMaximumBandwidth false */
/* polymorph Resources IOMaximumIOps false */
/* polymorph Resources IntelRdtL3Cbm false */
/* polymorph Resources KernelMemory false */
/* polymorph Resources Memory false */
/* polymorph Resources MemoryExtra false */
/* polymorph Resources MemoryForceEmptyCtl false */
/* polymorph Resources MemoryReservation false */
/* polymorph Resources MemorySwap false */
/* polymorph Resources MemorySwappiness false */
/* polymorph Resources MemoryWmarkRatio false */
/* polymorph Resources NanoCPUs false */
/* polymorph Resources OomKillDisable false */
/* polymorph Resources PidsLimit false */
/* polymorph Resources ScheLatSwitch false */
/* polymorph Resources Ulimits false */
// Validate validates this resources
func (m *Resources) Validate(formats strfmt.Registry) error {
var res []error
if err := m.validateBlkioDeviceReadBps(formats); err != nil {
// prop
res = append(res, err)
}
if err := m.validateBlkioDeviceReadIOps(formats); err != nil {
// prop
res = append(res, err)
}
if err := m.validateBlkioDeviceWriteBps(formats); err != nil {
// prop
res = append(res, err)
}
if err := m.validateBlkioDeviceWriteIOps(formats); err != nil {
// prop
res = append(res, err)
}
if err := m.validateBlkioWeight(formats); err != nil {
// prop
res = append(res, err)
}
if err := m.validateBlkioWeightDevice(formats); err != nil {
// prop
res = append(res, err)
}
if err := m.validateCPUPeriod(formats); err != nil {
// prop
res = append(res, err)
}
if err := m.validateCPUQuota(formats); err != nil {
// prop
res = append(res, err)
}
if err := m.validateDeviceCgroupRules(formats); err != nil {
// prop
res = append(res, err)
}
if err := m.validateDevices(formats); err != nil {
// prop
res = append(res, err)
}
if err := m.validateMemoryExtra(formats); err != nil {
// prop
res = append(res, err)
}
if err := m.validateMemoryForceEmptyCtl(formats); err != nil {
// prop
res = append(res, err)
}
if err := m.validateMemorySwappiness(formats); err != nil {
// prop
res = append(res, err)
}
if err := m.validateMemoryWmarkRatio(formats); err != nil {
// prop
res = append(res, err)
}
if err := m.validateScheLatSwitch(formats); err != nil {
// prop
res = append(res, err)
}
if err := m.validateUlimits(formats); err != nil {
// prop
res = append(res, err)
}
if len(res) > 0 {
return errors.CompositeValidationError(res...)
}
return nil
}
func (m *Resources) validateBlkioDeviceReadBps(formats strfmt.Registry) error {
if swag.IsZero(m.BlkioDeviceReadBps) { // not required
return nil
}
for i := 0; i < len(m.BlkioDeviceReadBps); i++ {
if swag.IsZero(m.BlkioDeviceReadBps[i]) { // not required
continue
}
if m.BlkioDeviceReadBps[i] != nil {
if err := m.BlkioDeviceReadBps[i].Validate(formats); err != nil {
if ve, ok := err.(*errors.Validation); ok {
return ve.ValidateName("BlkioDeviceReadBps" + "." + strconv.Itoa(i))
}
return err
}
}
}
return nil
}
func (m *Resources) validateBlkioDeviceReadIOps(formats strfmt.Registry) error {
if swag.IsZero(m.BlkioDeviceReadIOps) { // not required
return nil
}
for i := 0; i < len(m.BlkioDeviceReadIOps); i++ {
if swag.IsZero(m.BlkioDeviceReadIOps[i]) { // not required
continue
}
if m.BlkioDeviceReadIOps[i] != nil {
if err := m.BlkioDeviceReadIOps[i].Validate(formats); err != nil {
if ve, ok := err.(*errors.Validation); ok {
return ve.ValidateName("BlkioDeviceReadIOps" + "." + strconv.Itoa(i))
}
return err
}
}
}
return nil
}
func (m *Resources) validateBlkioDeviceWriteBps(formats strfmt.Registry) error {
if swag.IsZero(m.BlkioDeviceWriteBps) { // not required
return nil
}
for i := 0; i < len(m.BlkioDeviceWriteBps); i++ {
if swag.IsZero(m.BlkioDeviceWriteBps[i]) { // not required
continue
}
if m.BlkioDeviceWriteBps[i] != nil {
if err := m.BlkioDeviceWriteBps[i].Validate(formats); err != nil {
if ve, ok := err.(*errors.Validation); ok {
return ve.ValidateName("BlkioDeviceWriteBps" + "." + strconv.Itoa(i))
}
return err
}
}
}
return nil
}
func (m *Resources) validateBlkioDeviceWriteIOps(formats strfmt.Registry) error {
if swag.IsZero(m.BlkioDeviceWriteIOps) { // not required
return nil
}
for i := 0; i < len(m.BlkioDeviceWriteIOps); i++ {
if swag.IsZero(m.BlkioDeviceWriteIOps[i]) { // not required
continue
}
if m.BlkioDeviceWriteIOps[i] != nil {
if err := m.BlkioDeviceWriteIOps[i].Validate(formats); err != nil {
if ve, ok := err.(*errors.Validation); ok {
return ve.ValidateName("BlkioDeviceWriteIOps" + "." + strconv.Itoa(i))
}
return err
}
}
}
return nil
}
func (m *Resources) validateBlkioWeight(formats strfmt.Registry) error {
if swag.IsZero(m.BlkioWeight) { // not required
return nil
}
if err := validate.MinimumInt("BlkioWeight", "body", int64(m.BlkioWeight), 0, false); err != nil {
return err
}
if err := validate.MaximumInt("BlkioWeight", "body", int64(m.BlkioWeight), 1000, false); err != nil {
return err
}
return nil
}
func (m *Resources) validateBlkioWeightDevice(formats strfmt.Registry) error {
if swag.IsZero(m.BlkioWeightDevice) { // not required
return nil
}
for i := 0; i < len(m.BlkioWeightDevice); i++ {
if swag.IsZero(m.BlkioWeightDevice[i]) { // not required
continue
}
if m.BlkioWeightDevice[i] != nil {
if err := m.BlkioWeightDevice[i].Validate(formats); err != nil {
if ve, ok := err.(*errors.Validation); ok {
return ve.ValidateName("BlkioWeightDevice" + "." + strconv.Itoa(i))
}
return err
}
}
}
return nil
}
func (m *Resources) validateCPUPeriod(formats strfmt.Registry) error {
if swag.IsZero(m.CPUPeriod) { // not required
return nil
}
if err := validate.MinimumInt("CpuPeriod", "body", int64(m.CPUPeriod), 1000, false); err != nil {
return err
}
if err := validate.MaximumInt("CpuPeriod", "body", int64(m.CPUPeriod), 1e+06, false); err != nil {
return err
}
return nil
}
func (m *Resources) validateCPUQuota(formats strfmt.Registry) error {
if swag.IsZero(m.CPUQuota) { // not required
return nil
}
if err := validate.MinimumInt("CpuQuota", "body", int64(m.CPUQuota), 1000, false); err != nil {
return err
}
return nil
}
func (m *Resources) validateDeviceCgroupRules(formats strfmt.Registry) error {
if swag.IsZero(m.DeviceCgroupRules) { // not required
return nil
}
return nil
}
func (m *Resources) validateDevices(formats strfmt.Registry) error {
if swag.IsZero(m.Devices) { // not required
return nil
}
for i := 0; i < len(m.Devices); i++ {
if swag.IsZero(m.Devices[i]) { // not required
continue
}
if m.Devices[i] != nil {
if err := m.Devices[i].Validate(formats); err != nil {
if ve, ok := err.(*errors.Validation); ok {
return ve.ValidateName("Devices" + "." + strconv.Itoa(i))
}
return err
}
}
}
return nil
}
func (m *Resources) validateMemoryExtra(formats strfmt.Registry) error {
if swag.IsZero(m.MemoryExtra) { // not required
return nil
}
if err := validate.MinimumInt("MemoryExtra", "body", int64(*m.MemoryExtra), 0, false); err != nil {
return err
}
if err := validate.MaximumInt("MemoryExtra", "body", int64(*m.MemoryExtra), 100, false); err != nil {
return err
}
return nil
}
func (m *Resources) validateMemoryForceEmptyCtl(formats strfmt.Registry) error {
if swag.IsZero(m.MemoryForceEmptyCtl) { // not required
return nil
}
if err := validate.MinimumInt("MemoryForceEmptyCtl", "body", int64(m.MemoryForceEmptyCtl), 0, false); err != nil {
return err
}
if err := validate.MaximumInt("MemoryForceEmptyCtl", "body", int64(m.MemoryForceEmptyCtl), 1, false); err != nil {
return err
}
return nil
}
func (m *Resources) validateMemorySwappiness(formats strfmt.Registry) error {
if swag.IsZero(m.MemorySwappiness) { // not required
return nil
}
if err := validate.MinimumInt("MemorySwappiness", "body", int64(*m.MemorySwappiness), -1, false); err != nil {
return err
}
if err := validate.MaximumInt("MemorySwappiness", "body", int64(*m.MemorySwappiness), 100, false); err != nil {
return err
}
return nil
}
func (m *Resources) validateMemoryWmarkRatio(formats strfmt.Registry) error {
if swag.IsZero(m.MemoryWmarkRatio) { // not required
return nil
}
if err := validate.MinimumInt("MemoryWmarkRatio", "body", int64(*m.MemoryWmarkRatio), 0, false); err != nil {
return err
}
if err := validate.MaximumInt("MemoryWmarkRatio", "body", int64(*m.MemoryWmarkRatio), 100, false); err != nil {
return err
}
return nil
}
func (m *Resources) validateScheLatSwitch(formats strfmt.Registry) error {
if swag.IsZero(m.ScheLatSwitch) { // not required
return nil
}
if err := validate.MinimumInt("ScheLatSwitch", "body", int64(m.ScheLatSwitch), 0, false); err != nil {
return err
}
if err := validate.MaximumInt("ScheLatSwitch", "body", int64(m.ScheLatSwitch), 1, false); err != nil {
return err
}
return nil
}
func (m *Resources) validateUlimits(formats strfmt.Registry) error {
if swag.IsZero(m.Ulimits) { // not required
return nil
}
for i := 0; i < len(m.Ulimits); i++ {
if swag.IsZero(m.Ulimits[i]) { // not required
continue
}
if m.Ulimits[i] != nil {
if err := m.Ulimits[i].Validate(formats); err != nil {
if ve, ok := err.(*errors.Validation); ok {
return ve.ValidateName("Ulimits" + "." + strconv.Itoa(i))
}
return err
}
}
}
return nil
}
// MarshalBinary interface implementation
func (m *Resources) MarshalBinary() ([]byte, error) {
if m == nil {
return nil, nil
}
return swag.WriteJSON(m)
}
// UnmarshalBinary interface implementation
func (m *Resources) UnmarshalBinary(b []byte) error {
var res Resources
if err := swag.ReadJSON(b, &res); err != nil {
return err
}
*m = res
return nil
}