@@ -84,25 +84,7 @@ func collectCreateContainerResult(request *CreateContainerRequest) *result {
84
84
request : resultRequest {
85
85
create : request ,
86
86
},
87
- reply : resultReply {
88
- adjust : & ContainerAdjustment {
89
- Annotations : map [string ]string {},
90
- Mounts : []* Mount {},
91
- Env : []* KeyValue {},
92
- Hooks : & Hooks {},
93
- Rlimits : []* POSIXRlimit {},
94
- CDIDevices : []* CDIDevice {},
95
- Linux : & LinuxContainerAdjustment {
96
- Devices : []* LinuxDevice {},
97
- Resources : & LinuxResources {
98
- Memory : & LinuxMemory {},
99
- Cpu : & LinuxCPU {},
100
- HugepageLimits : []* HugepageLimit {},
101
- Unified : map [string ]string {},
102
- },
103
- },
104
- },
105
- },
87
+ reply : resultReply {},
106
88
updates : map [string ]* ContainerUpdate {},
107
89
owners : resultOwners {},
108
90
}
@@ -249,6 +231,8 @@ func (r *result) adjustAnnotations(annotations map[string]string, plugin string)
249
231
return nil
250
232
}
251
233
234
+ r .initAdjustAnnotations ()
235
+
252
236
create , id := r .request .create , r .request .create .Container .Id
253
237
del := map [string ]struct {}{}
254
238
for k := range annotations {
@@ -284,6 +268,8 @@ func (r *result) adjustMounts(mounts []*Mount, plugin string) error {
284
268
return nil
285
269
}
286
270
271
+ r .initAdjustMounts ()
272
+
287
273
create , id := r .request .create , r .request .create .Container .Id
288
274
289
275
// first split removals from the rest of adjustments
@@ -349,6 +335,8 @@ func (r *result) adjustDevices(devices []*LinuxDevice, plugin string) error {
349
335
return nil
350
336
}
351
337
338
+ r .initAdjustDevices ()
339
+
352
340
create , id := r .request .create , r .request .create .Container .Id
353
341
354
342
// first split removals from the rest of adjustments
@@ -407,6 +395,8 @@ func (r *result) adjustCDIDevices(devices []*CDIDevice, plugin string) error {
407
395
return nil
408
396
}
409
397
398
+ r .initAdjustCDIDevices ()
399
+
410
400
// Notes:
411
401
// CDI devices are opaque references, typically to vendor specific
412
402
// devices. They get resolved to actual devices and potential related
@@ -437,6 +427,8 @@ func (r *result) adjustEnv(env []*KeyValue, plugin string) error {
437
427
return nil
438
428
}
439
429
430
+ r .initAdjustEnv ()
431
+
440
432
create , id := r .request .create , r .request .create .Container .Id
441
433
442
434
// first split removals from the rest of adjustments
@@ -509,6 +501,8 @@ func (r *result) adjustHooks(hooks *Hooks) error {
509
501
return nil
510
502
}
511
503
504
+ r .initAdjustHooks ()
505
+
512
506
reply := r .reply .adjust
513
507
container := r .request .create .Container
514
508
@@ -545,6 +539,8 @@ func (r *result) adjustResources(resources *LinuxResources, plugin string) error
545
539
return nil
546
540
}
547
541
542
+ r .initAdjustResources ()
543
+
548
544
create , id := r .request .create , r .request .create .Container .Id
549
545
container := create .Container .Linux .Resources
550
546
reply := r .reply .adjust .Linux .Resources
@@ -709,6 +705,8 @@ func (r *result) adjustCgroupsPath(path, plugin string) error {
709
705
return nil
710
706
}
711
707
708
+ r .initAdjustCgroupsPath ()
709
+
712
710
create , id := r .request .create , r .request .create .Container .Id
713
711
714
712
if err := r .owners .claimCgroupsPath (id , plugin ); err != nil {
@@ -726,6 +724,8 @@ func (r *result) adjustOomScoreAdj(OomScoreAdj *OptionalInt, plugin string) erro
726
724
return nil
727
725
}
728
726
727
+ r .initAdjustOomScoreAdj ()
728
+
729
729
create , id := r .request .create , r .request .create .Container .Id
730
730
731
731
if err := r .owners .claimOomScoreAdj (id , plugin ); err != nil {
@@ -739,6 +739,12 @@ func (r *result) adjustOomScoreAdj(OomScoreAdj *OptionalInt, plugin string) erro
739
739
}
740
740
741
741
func (r * result ) adjustRlimits (rlimits []* POSIXRlimit , plugin string ) error {
742
+ if len (rlimits ) == 0 {
743
+ return nil
744
+ }
745
+
746
+ r .initAdjustRlimits ()
747
+
742
748
create , id , adjust := r .request .create , r .request .create .Container .Id , r .reply .adjust
743
749
for _ , l := range rlimits {
744
750
if err := r .owners .claimRlimits (id , l .Type , plugin ); err != nil {
@@ -751,6 +757,73 @@ func (r *result) adjustRlimits(rlimits []*POSIXRlimit, plugin string) error {
751
757
return nil
752
758
}
753
759
760
+ func (r * result ) initAdjust () {
761
+ if r .reply .adjust == nil {
762
+ r .reply .adjust = & ContainerAdjustment {}
763
+ }
764
+ }
765
+
766
+ func (r * result ) initAdjustAnnotations () {
767
+ r .initAdjust ()
768
+ if r .reply .adjust .Annotations == nil {
769
+ r .reply .adjust .Annotations = map [string ]string {}
770
+ }
771
+ }
772
+
773
+ func (r * result ) initAdjustMounts () {
774
+ r .initAdjust ()
775
+ }
776
+
777
+ func (r * result ) initAdjustEnv () {
778
+ r .initAdjust ()
779
+ }
780
+
781
+ func (r * result ) initAdjustHooks () {
782
+ r .initAdjust ()
783
+ if r .reply .adjust .Hooks == nil {
784
+ r .reply .adjust .Hooks = & Hooks {}
785
+ }
786
+ }
787
+
788
+ func (r * result ) initAdjustLinux () {
789
+ r .initAdjust ()
790
+ if r .reply .adjust .Linux == nil {
791
+ r .reply .adjust .Linux = & LinuxContainerAdjustment {}
792
+ }
793
+ }
794
+
795
+ func (r * result ) initAdjustDevices () {
796
+ r .initAdjustLinux ()
797
+ }
798
+
799
+ func (r * result ) initAdjustResources () {
800
+ r .initAdjustLinux ()
801
+ if r .reply .adjust .Linux .Resources == nil {
802
+ r .reply .adjust .Linux .Resources = & LinuxResources {
803
+ Memory : & LinuxMemory {},
804
+ Cpu : & LinuxCPU {},
805
+ HugepageLimits : []* HugepageLimit {},
806
+ Unified : map [string ]string {},
807
+ }
808
+ }
809
+ }
810
+
811
+ func (r * result ) initAdjustCgroupsPath () {
812
+ r .initAdjustLinux ()
813
+ }
814
+
815
+ func (r * result ) initAdjustOomScoreAdj () {
816
+ r .initAdjustLinux ()
817
+ }
818
+
819
+ func (r * result ) initAdjustRlimits () {
820
+ r .initAdjustLinux ()
821
+ }
822
+
823
+ func (r * result ) initAdjustCDIDevices () {
824
+ r .initAdjust ()
825
+ }
826
+
754
827
func (r * result ) updateResources (reply , u * ContainerUpdate , plugin string ) error {
755
828
if u .Linux == nil || u .Linux .Resources == nil {
756
829
return nil
0 commit comments