@@ -87,26 +87,7 @@ func collectCreateContainerResult(request *CreateContainerRequest) *result {
8787 request : resultRequest {
8888 create : request ,
8989 },
90- reply : resultReply {
91- adjust : & ContainerAdjustment {
92- Annotations : map [string ]string {},
93- Mounts : []* Mount {},
94- Env : []* KeyValue {},
95- Hooks : & Hooks {},
96- Rlimits : []* POSIXRlimit {},
97- CDIDevices : []* CDIDevice {},
98- Linux : & LinuxContainerAdjustment {
99- Devices : []* LinuxDevice {},
100- Resources : & LinuxResources {
101- Memory : & LinuxMemory {},
102- Cpu : & LinuxCPU {},
103- HugepageLimits : []* HugepageLimit {},
104- Unified : map [string ]string {},
105- },
106- Namespaces : []* LinuxNamespace {},
107- },
108- },
109- },
90+ reply : resultReply {},
11091 updates : map [string ]* ContainerUpdate {},
11192 owners : api .NewOwningPlugins (),
11293 }
@@ -265,6 +246,8 @@ func (r *result) adjustAnnotations(annotations map[string]string, plugin string)
265246 return nil
266247 }
267248
249+ r .initAdjustAnnotations ()
250+
268251 create , id := r .request .create , r .request .create .Container .Id
269252 del := map [string ]struct {}{}
270253 for k := range annotations {
@@ -300,6 +283,8 @@ func (r *result) adjustMounts(mounts []*Mount, plugin string) error {
300283 return nil
301284 }
302285
286+ r .initAdjustMounts ()
287+
303288 create , id := r .request .create , r .request .create .Container .Id
304289
305290 // first split removals from the rest of adjustments
@@ -365,6 +350,8 @@ func (r *result) adjustDevices(devices []*LinuxDevice, plugin string) error {
365350 return nil
366351 }
367352
353+ r .initAdjustDevices ()
354+
368355 create , id := r .request .create , r .request .create .Container .Id
369356
370357 // first split removals from the rest of adjustments
@@ -423,6 +410,8 @@ func (r *result) adjustNamespaces(namespaces []*LinuxNamespace, plugin string) e
423410 return nil
424411 }
425412
413+ r .initAdjustNamespaces ()
414+
426415 create , id := r .request .create , r .request .create .Container .Id
427416
428417 creatensmap := map [string ]* LinuxNamespace {}
@@ -456,6 +445,8 @@ func (r *result) adjustCDIDevices(devices []*CDIDevice, plugin string) error {
456445 return nil
457446 }
458447
448+ r .initAdjustCDIDevices ()
449+
459450 // Notes:
460451 // CDI devices are opaque references, typically to vendor specific
461452 // devices. They get resolved to actual devices and potential related
@@ -486,6 +477,8 @@ func (r *result) adjustEnv(env []*KeyValue, plugin string) error {
486477 return nil
487478 }
488479
480+ r .initAdjustEnv ()
481+
489482 create , id := r .request .create , r .request .create .Container .Id
490483
491484 // first split removals from the rest of adjustments
@@ -558,6 +551,8 @@ func (r *result) adjustArgs(args []string, plugin string) error {
558551 return nil
559552 }
560553
554+ r .initAdjustArgs ()
555+
561556 create , id := r .request .create , r .request .create .Container .Id
562557
563558 if args [0 ] == "" {
@@ -580,6 +575,8 @@ func (r *result) adjustHooks(hooks *Hooks, plugin string) error {
580575 return nil
581576 }
582577
578+ r .initAdjustHooks ()
579+
583580 reply := r .reply .adjust
584581 container := r .request .create .Container
585582 claim := false
@@ -627,6 +624,8 @@ func (r *result) adjustResources(resources *LinuxResources, plugin string) error
627624 return nil
628625 }
629626
627+ r .initAdjustResources ()
628+
630629 create , id := r .request .create , r .request .create .Container .Id
631630 container := create .Container .Linux .Resources
632631 reply := r .reply .adjust .Linux .Resources
@@ -796,6 +795,8 @@ func (r *result) adjustCgroupsPath(path, plugin string) error {
796795 return nil
797796 }
798797
798+ r .initAdjustCgroupsPath ()
799+
799800 create , id := r .request .create , r .request .create .Container .Id
800801
801802 if err := r .owners .ClaimCgroupsPath (id , plugin ); err != nil {
@@ -813,6 +814,8 @@ func (r *result) adjustOomScoreAdj(OomScoreAdj *OptionalInt, plugin string) erro
813814 return nil
814815 }
815816
817+ r .initAdjustOomScoreAdj ()
818+
816819 create , id := r .request .create , r .request .create .Container .Id
817820
818821 if err := r .owners .ClaimOomScoreAdj (id , plugin ); err != nil {
@@ -830,6 +833,8 @@ func (r *result) adjustIOPriority(priority *LinuxIOPriority, plugin string) erro
830833 return nil
831834 }
832835
836+ r .initAdjustIOPriority ()
837+
833838 create , id := r .request .create , r .request .create .Container .Id
834839
835840 if err := r .owners .ClaimIOPriority (id , plugin ); err != nil {
@@ -846,6 +851,9 @@ func (r *result) adjustSeccompPolicy(adjustment *LinuxSeccomp, plugin string) er
846851 if adjustment == nil {
847852 return nil
848853 }
854+
855+ r .initAdjustSeccompPolicy ()
856+
849857 create , id := r .request .create , r .request .create .Container .Id
850858
851859 if err := r .owners .ClaimSeccompPolicy (id , plugin ); err != nil {
@@ -859,6 +867,12 @@ func (r *result) adjustSeccompPolicy(adjustment *LinuxSeccomp, plugin string) er
859867}
860868
861869func (r * result ) adjustRlimits (rlimits []* POSIXRlimit , plugin string ) error {
870+ if len (rlimits ) == 0 {
871+ return nil
872+ }
873+
874+ r .initAdjustRlimits ()
875+
862876 create , id , adjust := r .request .create , r .request .create .Container .Id , r .reply .adjust
863877 for _ , l := range rlimits {
864878 if err := r .owners .ClaimRlimit (id , l .Type , plugin ); err != nil {
@@ -871,6 +885,88 @@ func (r *result) adjustRlimits(rlimits []*POSIXRlimit, plugin string) error {
871885 return nil
872886}
873887
888+ func (r * result ) initAdjust () {
889+ if r .reply .adjust == nil {
890+ r .reply .adjust = & ContainerAdjustment {}
891+ }
892+ }
893+
894+ func (r * result ) initAdjustAnnotations () {
895+ r .initAdjust ()
896+ if r .reply .adjust .Annotations == nil {
897+ r .reply .adjust .Annotations = map [string ]string {}
898+ }
899+ }
900+
901+ func (r * result ) initAdjustMounts () {
902+ r .initAdjust ()
903+ }
904+
905+ func (r * result ) initAdjustLinux () {
906+ r .initAdjust ()
907+ if r .reply .adjust .Linux == nil {
908+ r .reply .adjust .Linux = & LinuxContainerAdjustment {}
909+ }
910+ }
911+
912+ func (r * result ) initAdjustDevices () {
913+ r .initAdjustLinux ()
914+ }
915+
916+ func (r * result ) initAdjustEnv () {
917+ r .initAdjust ()
918+ }
919+
920+ func (r * result ) initAdjustArgs () {
921+ r .initAdjust ()
922+ }
923+
924+ func (r * result ) initAdjustHooks () {
925+ r .initAdjust ()
926+ if r .reply .adjust .Hooks == nil {
927+ r .reply .adjust .Hooks = & Hooks {}
928+ }
929+ }
930+
931+ func (r * result ) initAdjustResources () {
932+ r .initAdjustLinux ()
933+ if r .reply .adjust .Linux .Resources == nil {
934+ r .reply .adjust .Linux .Resources = & LinuxResources {
935+ Memory : & LinuxMemory {},
936+ Cpu : & LinuxCPU {},
937+ Unified : map [string ]string {},
938+ }
939+ }
940+ }
941+
942+ func (r * result ) initAdjustCgroupsPath () {
943+ r .initAdjustLinux ()
944+ }
945+
946+ func (r * result ) initAdjustOomScoreAdj () {
947+ r .initAdjustLinux ()
948+ }
949+
950+ func (r * result ) initAdjustIOPriority () {
951+ r .initAdjustLinux ()
952+ }
953+
954+ func (r * result ) initAdjustSeccompPolicy () {
955+ r .initAdjustLinux ()
956+ }
957+
958+ func (r * result ) initAdjustNamespaces () {
959+ r .initAdjustLinux ()
960+ }
961+
962+ func (r * result ) initAdjustRlimits () {
963+ r .initAdjust ()
964+ }
965+
966+ func (r * result ) initAdjustCDIDevices () {
967+ r .initAdjust ()
968+ }
969+
874970func (r * result ) updateResources (reply , u * ContainerUpdate , plugin string ) error {
875971 if u .Linux == nil || u .Linux .Resources == nil {
876972 return nil
0 commit comments