@@ -80,6 +80,9 @@ func collectCreateContainerResult(request *CreateContainerRequest) *result {
8080 if request .Container .Linux .Resources .Unified == nil {
8181 request .Container .Linux .Resources .Unified = map [string ]string {}
8282 }
83+ if request .Container .Linux .NetDevices == nil {
84+ request .Container .Linux .NetDevices = map [string ]* LinuxNetDevice {}
85+ }
8386
8487 return & result {
8588 request : resultRequest {
@@ -101,6 +104,7 @@ func collectCreateContainerResult(request *CreateContainerRequest) *result {
101104 HugepageLimits : []* HugepageLimit {},
102105 Unified : map [string ]string {},
103106 },
107+ NetDevices : map [string ]* LinuxNetDevice {},
104108 },
105109 },
106110 },
@@ -223,6 +227,9 @@ func (r *result) adjust(rpl *ContainerAdjustment, plugin string) error {
223227 if err := r .adjustOomScoreAdj (rpl .Linux .OomScoreAdj , plugin ); err != nil {
224228 return err
225229 }
230+ if err := r .adjustLinuxNetDevices (rpl .Linux .NetDevices , plugin ); err != nil {
231+ return err
232+ }
226233 }
227234 if err := r .adjustRlimits (rpl .Rlimits , plugin ); err != nil {
228235 return err
@@ -777,6 +784,41 @@ func (r *result) adjustRlimits(rlimits []*POSIXRlimit, plugin string) error {
777784 return nil
778785}
779786
787+ func (r * result ) adjustLinuxNetDevices (devices map [string ]* LinuxNetDevice , plugin string ) error {
788+ if len (devices ) == 0 {
789+ return nil
790+ }
791+
792+ create , id := r .request .create , r .request .create .Container .Id
793+ del := map [string ]struct {}{}
794+ for k := range devices {
795+ if key , marked := IsMarkedForRemoval (k ); marked {
796+ del [key ] = struct {}{}
797+ delete (devices , k )
798+ }
799+ }
800+
801+ for k , v := range devices {
802+ if _ , ok := del [k ]; ok {
803+ r .owners .clearLinuxNetDevice (id , k )
804+ delete (create .Container .Linux .NetDevices , k )
805+ r .reply .adjust .Linux .NetDevices [MarkForRemoval (k )] = nil
806+ }
807+ if err := r .owners .claimLinuxNetDevice (id , k , plugin ); err != nil {
808+ return err
809+ }
810+ create .Container .Linux .NetDevices [k ] = v
811+ r .reply .adjust .Linux .NetDevices [k ] = v
812+ delete (del , k )
813+ }
814+
815+ for k := range del {
816+ r .reply .adjust .Linux .NetDevices [MarkForRemoval (k )] = nil
817+ }
818+
819+ return nil
820+ }
821+
780822func (r * result ) updateResources (reply , u * ContainerUpdate , plugin string ) error {
781823 if u .Linux == nil || u .Linux .Resources == nil {
782824 return nil
@@ -1004,6 +1046,7 @@ type owners struct {
10041046 cgroupsPath string
10051047 oomScoreAdj string
10061048 rlimits map [string ]string
1049+ linuxNetDevices map [string ]string
10071050}
10081051
10091052func (ro resultOwners ) ownersFor (id string ) * owners {
@@ -1131,6 +1174,10 @@ func (ro resultOwners) claimRlimits(id, typ, plugin string) error {
11311174 return ro .ownersFor (id ).claimRlimit (typ , plugin )
11321175}
11331176
1177+ func (ro resultOwners ) claimLinuxNetDevice (id , key , plugin string ) error {
1178+ return ro .ownersFor (id ).claimLinuxNetDevice (key , plugin )
1179+ }
1180+
11341181func (o * owners ) claimAnnotation (key , plugin string ) error {
11351182 if o .annotations == nil {
11361183 o .annotations = make (map [string ]string )
@@ -1388,6 +1435,17 @@ func (o *owners) claimOomScoreAdj(plugin string) error {
13881435 return nil
13891436}
13901437
1438+ func (o * owners ) claimLinuxNetDevice (key , plugin string ) error {
1439+ if o .linuxNetDevices == nil {
1440+ o .linuxNetDevices = make (map [string ]string )
1441+ }
1442+ if other , taken := o .linuxNetDevices [key ]; taken {
1443+ return conflict (plugin , other , "linux net device" , key )
1444+ }
1445+ o .linuxNetDevices [key ] = plugin
1446+ return nil
1447+ }
1448+
13911449func (ro resultOwners ) clearAnnotation (id , key string ) {
13921450 ro .ownersFor (id ).clearAnnotation (key )
13931451}
@@ -1408,6 +1466,10 @@ func (ro resultOwners) clearArgs(id string) {
14081466 ro .ownersFor (id ).clearArgs ()
14091467}
14101468
1469+ func (ro resultOwners ) clearLinuxNetDevice (id , key string ) {
1470+ ro .ownersFor (id ).clearLinuxNetDevice (key )
1471+ }
1472+
14111473func (o * owners ) clearAnnotation (key string ) {
14121474 if o .annotations == nil {
14131475 return
@@ -1440,6 +1502,13 @@ func (o *owners) clearArgs() {
14401502 o .args = ""
14411503}
14421504
1505+ func (o * owners ) clearLinuxNetDevice (key string ) {
1506+ if o .linuxNetDevices == nil {
1507+ return
1508+ }
1509+ delete (o .linuxNetDevices , key )
1510+ }
1511+
14431512func conflict (plugin , other , subject string , qualif ... string ) error {
14441513 return fmt .Errorf ("plugins %q and %q both tried to set %s" ,
14451514 plugin , other , strings .Join (append ([]string {subject }, qualif ... ), " " ))
0 commit comments