@@ -490,6 +490,144 @@ func (g *Generator) SetProcessOOMScoreAdj(adj int) {
490490 g .spec .Process .OOMScoreAdj = & adj
491491}
492492
493+ // SetLinuxResourcesBlockIOLeafWeight sets g.spec.Linux.Resources.BlockIO.LeafWeight.
494+ func (g * Generator ) SetLinuxResourcesBlockIOLeafWeight (weight uint16 ) {
495+ g .initSpecLinuxResourcesBlockIO ()
496+ g .spec .Linux .Resources .BlockIO .LeafWeight = & weight
497+ }
498+
499+ // AddLinuxResourcesBlockIOLeafWeightDevice adds or sets g.spec.Linux.Resources.BlockIO.WeightDevice.LeafWeight.
500+ func (g * Generator ) AddLinuxResourcesBlockIOLeafWeightDevice (major int64 , minor int64 , weight uint16 ) {
501+ g .initSpecLinuxResourcesBlockIO ()
502+ for i , weightDevice := range g .spec .Linux .Resources .BlockIO .WeightDevice {
503+ if weightDevice .Major == major && weightDevice .Minor == minor {
504+ g .spec .Linux .Resources .BlockIO .WeightDevice [i ].LeafWeight = & weight
505+ return
506+ }
507+ }
508+ weightDevice := new (rspec.LinuxWeightDevice )
509+ weightDevice .Major = major
510+ weightDevice .Minor = minor
511+ weightDevice .LeafWeight = & weight
512+ g .spec .Linux .Resources .BlockIO .WeightDevice = append (g .spec .Linux .Resources .BlockIO .WeightDevice , * weightDevice )
513+ }
514+
515+ // DropLinuxResourcesBlockIOLeafWeightDevice drops a item form g.spec.Linux.Resources.BlockIO.WeightDevice.LeafWeight
516+ func (g * Generator ) DropLinuxResourcesBlockIOLeafWeightDevice (major int64 , minor int64 ) {
517+ g .initSpecLinuxResourcesBlockIO ()
518+ for i , weightDevice := range g .spec .Linux .Resources .BlockIO .WeightDevice {
519+ if weightDevice .Major == major && weightDevice .Minor == minor {
520+ if weightDevice .Weight != nil {
521+ newWeightDevice := new (rspec.LinuxWeightDevice )
522+ newWeightDevice .Major = major
523+ newWeightDevice .Minor = minor
524+ newWeightDevice .Weight = weightDevice .Weight
525+ g .spec .Linux .Resources .BlockIO .WeightDevice [i ] = * newWeightDevice
526+ } else {
527+ g .spec .Linux .Resources .BlockIO .WeightDevice = append (g .spec .Linux .Resources .BlockIO .WeightDevice [:i ], g .spec .Linux .Resources .BlockIO .WeightDevice [i + 1 :]... )
528+ }
529+ return
530+ }
531+ }
532+ }
533+
534+ // SetLinuxResourcesBlockIOWeight sets g.spec.Linux.Resources.BlockIO.Weight.
535+ func (g * Generator ) SetLinuxResourcesBlockIOWeight (weight uint16 ) {
536+ g .initSpecLinuxResourcesBlockIO ()
537+ g .spec .Linux .Resources .BlockIO .Weight = & weight
538+ }
539+
540+ // AddLinuxResourcesBlockIOWeightDevice adds or sets g.spec.Linux.Resources.BlockIO.WeightDevice.Weight.
541+ func (g * Generator ) AddLinuxResourcesBlockIOWeightDevice (major int64 , minor int64 , weight uint16 ) {
542+ g .initSpecLinuxResourcesBlockIO ()
543+ for i , weightDevice := range g .spec .Linux .Resources .BlockIO .WeightDevice {
544+ if weightDevice .Major == major && weightDevice .Minor == minor {
545+ g .spec .Linux .Resources .BlockIO .WeightDevice [i ].Weight = & weight
546+ return
547+ }
548+ }
549+ weightDevice := new (rspec.LinuxWeightDevice )
550+ weightDevice .Major = major
551+ weightDevice .Minor = minor
552+ weightDevice .Weight = & weight
553+ g .spec .Linux .Resources .BlockIO .WeightDevice = append (g .spec .Linux .Resources .BlockIO .WeightDevice , * weightDevice )
554+ }
555+
556+ // DropLinuxResourcesBlockIOWeightDevice drops a item form g.spec.Linux.Resources.BlockIO.WeightDevice.Weight
557+ func (g * Generator ) DropLinuxResourcesBlockIOWeightDevice (major int64 , minor int64 ) {
558+ g .initSpecLinuxResourcesBlockIO ()
559+ for i , weightDevice := range g .spec .Linux .Resources .BlockIO .WeightDevice {
560+ if weightDevice .Major == major && weightDevice .Minor == minor {
561+ if weightDevice .LeafWeight != nil {
562+ newWeightDevice := new (rspec.LinuxWeightDevice )
563+ newWeightDevice .Major = major
564+ newWeightDevice .Minor = minor
565+ newWeightDevice .LeafWeight = weightDevice .LeafWeight
566+ g .spec .Linux .Resources .BlockIO .WeightDevice [i ] = * newWeightDevice
567+ } else {
568+ g .spec .Linux .Resources .BlockIO .WeightDevice = append (g .spec .Linux .Resources .BlockIO .WeightDevice [:i ], g .spec .Linux .Resources .BlockIO .WeightDevice [i + 1 :]... )
569+ }
570+ return
571+ }
572+ }
573+ }
574+
575+ // AddLinuxResourcesBlockIOThrottleReadBpsDevice adds or sets g.spec.Linux.Resources.BlockIO.ThrottleReadBpsDevice.
576+ func (g * Generator ) AddLinuxResourcesBlockIOThrottleReadBpsDevice (major int64 , minor int64 , rate uint64 ) {
577+ g .initSpecLinuxResourcesBlockIO ()
578+ throttleDevices := addOrReplaceBlockIOThrottleDevice (g .spec .Linux .Resources .BlockIO .ThrottleReadBpsDevice , major , minor , rate )
579+ g .spec .Linux .Resources .BlockIO .ThrottleReadBpsDevice = throttleDevices
580+ }
581+
582+ // DropLinuxResourcesBlockIOThrottleReadBpsDevice drops a item from g.spec.Linux.Resources.BlockIO.ThrottleReadBpsDevice.
583+ func (g * Generator ) DropLinuxResourcesBlockIOThrottleReadBpsDevice (major int64 , minor int64 ) {
584+ g .initSpecLinuxResourcesBlockIO ()
585+ throttleDevices := dropBlockIOThrottleDevice (g .spec .Linux .Resources .BlockIO .ThrottleReadBpsDevice , major , minor )
586+ g .spec .Linux .Resources .BlockIO .ThrottleReadBpsDevice = throttleDevices
587+ }
588+
589+ // AddLinuxResourcesBlockIOThrottleReadIOPSDevice adds or sets g.spec.Linux.Resources.BlockIO.ThrottleReadIOPSDevice.
590+ func (g * Generator ) AddLinuxResourcesBlockIOThrottleReadIOPSDevice (major int64 , minor int64 , rate uint64 ) {
591+ g .initSpecLinuxResourcesBlockIO ()
592+ throttleDevices := addOrReplaceBlockIOThrottleDevice (g .spec .Linux .Resources .BlockIO .ThrottleReadIOPSDevice , major , minor , rate )
593+ g .spec .Linux .Resources .BlockIO .ThrottleReadIOPSDevice = throttleDevices
594+ }
595+
596+ // DropLinuxResourcesBlockIOThrottleReadIOPSDevice drops a item from g.spec.Linux.Resources.BlockIO.ThrottleReadIOPSDevice.
597+ func (g * Generator ) DropLinuxResourcesBlockIOThrottleReadIOPSDevice (major int64 , minor int64 ) {
598+ g .initSpecLinuxResourcesBlockIO ()
599+ throttleDevices := dropBlockIOThrottleDevice (g .spec .Linux .Resources .BlockIO .ThrottleReadIOPSDevice , major , minor )
600+ g .spec .Linux .Resources .BlockIO .ThrottleReadIOPSDevice = throttleDevices
601+ }
602+
603+ // AddLinuxResourcesBlockIOThrottleWriteBpsDevice adds or sets g.spec.Linux.Resources.BlockIO.ThrottleWriteBpsDevice.
604+ func (g * Generator ) AddLinuxResourcesBlockIOThrottleWriteBpsDevice (major int64 , minor int64 , rate uint64 ) {
605+ g .initSpecLinuxResourcesBlockIO ()
606+ throttleDevices := addOrReplaceBlockIOThrottleDevice (g .spec .Linux .Resources .BlockIO .ThrottleWriteBpsDevice , major , minor , rate )
607+ g .spec .Linux .Resources .BlockIO .ThrottleWriteBpsDevice = throttleDevices
608+ }
609+
610+ // DropLinuxResourcesBlockIOThrottleWriteBpsDevice drops a item from g.spec.Linux.Resources.BlockIO.ThrottleWriteBpsDevice.
611+ func (g * Generator ) DropLinuxResourcesBlockIOThrottleWriteBpsDevice (major int64 , minor int64 ) {
612+ g .initSpecLinuxResourcesBlockIO ()
613+ throttleDevices := dropBlockIOThrottleDevice (g .spec .Linux .Resources .BlockIO .ThrottleWriteBpsDevice , major , minor )
614+ g .spec .Linux .Resources .BlockIO .ThrottleWriteBpsDevice = throttleDevices
615+ }
616+
617+ // AddLinuxResourcesBlockIOThrottleWriteIOPSDevice adds or sets g.spec.Linux.Resources.BlockIO.ThrottleWriteIOPSDevice.
618+ func (g * Generator ) AddLinuxResourcesBlockIOThrottleWriteIOPSDevice (major int64 , minor int64 , rate uint64 ) {
619+ g .initSpecLinuxResourcesBlockIO ()
620+ throttleDevices := addOrReplaceBlockIOThrottleDevice (g .spec .Linux .Resources .BlockIO .ThrottleWriteIOPSDevice , major , minor , rate )
621+ g .spec .Linux .Resources .BlockIO .ThrottleWriteIOPSDevice = throttleDevices
622+ }
623+
624+ // DropLinuxResourcesBlockIOThrottleWriteIOPSDevice drops a item from g.spec.Linux.Resources.BlockIO.ThrottleWriteIOPSDevice.
625+ func (g * Generator ) DropLinuxResourcesBlockIOThrottleWriteIOPSDevice (major int64 , minor int64 ) {
626+ g .initSpecLinuxResourcesBlockIO ()
627+ throttleDevices := dropBlockIOThrottleDevice (g .spec .Linux .Resources .BlockIO .ThrottleWriteIOPSDevice , major , minor )
628+ g .spec .Linux .Resources .BlockIO .ThrottleWriteIOPSDevice = throttleDevices
629+ }
630+
493631// SetLinuxResourcesCPUShares sets g.spec.Linux.Resources.CPU.Shares.
494632func (g * Generator ) SetLinuxResourcesCPUShares (shares uint64 ) {
495633 g .initSpecLinuxResourcesCPU ()
@@ -1124,3 +1262,32 @@ func (g *Generator) AddLinuxReadonlyPaths(path string) {
11241262 g .initSpecLinux ()
11251263 g .spec .Linux .ReadonlyPaths = append (g .spec .Linux .ReadonlyPaths , path )
11261264}
1265+
1266+ func addOrReplaceBlockIOThrottleDevice (tmpList []rspec.LinuxThrottleDevice , major int64 , minor int64 , rate uint64 ) []rspec.LinuxThrottleDevice {
1267+ throttleDevices := tmpList
1268+ for i , throttleDevice := range throttleDevices {
1269+ if throttleDevice .Major == major && throttleDevice .Minor == minor {
1270+ throttleDevices [i ].Rate = rate
1271+ return throttleDevices
1272+ }
1273+ }
1274+ throttleDevice := new (rspec.LinuxThrottleDevice )
1275+ throttleDevice .Major = major
1276+ throttleDevice .Minor = minor
1277+ throttleDevice .Rate = rate
1278+ throttleDevices = append (throttleDevices , * throttleDevice )
1279+
1280+ return throttleDevices
1281+ }
1282+
1283+ func dropBlockIOThrottleDevice (tmpList []rspec.LinuxThrottleDevice , major int64 , minor int64 ) []rspec.LinuxThrottleDevice {
1284+ throttleDevices := tmpList
1285+ for i , throttleDevice := range throttleDevices {
1286+ if throttleDevice .Major == major && throttleDevice .Minor == minor {
1287+ throttleDevices = append (throttleDevices [:i ], throttleDevices [i + 1 :]... )
1288+ return throttleDevices
1289+ }
1290+ }
1291+
1292+ return throttleDevices
1293+ }
0 commit comments