@@ -144,20 +144,21 @@ func (np *NetworkDriver) prepareResourceClaim(ctx context.Context, claim *resour
144144 defer func () {
145145 klog .V (2 ).Infof ("PrepareResourceClaim Claim %s/%s took %v" , claim .Namespace , claim .Name , time .Since (start ))
146146 }()
147- // TODO: shared devices may allocate the same device to multiple pods, i.e. macvlan, ipvlan, ...
148- podUIDs := []types.UID {}
149- for _ , reserved := range claim .Status .ReservedFor {
150- if reserved .Resource != "pods" || reserved .APIGroup != "" {
151- klog .Infof ("Driver only supports Pods, unsupported reference %#v" , reserved )
152- continue
153- }
154- podUIDs = append (podUIDs , reserved .UID )
155- }
156- if len (podUIDs ) == 0 {
147+ if len (claim .Status .ReservedFor ) == 0 {
157148 klog .Infof ("no pods allocated to claim %s/%s" , claim .Namespace , claim .Name )
158149 return kubeletplugin.PrepareResult {}
159150 }
160151
152+ // One ResourceClaim is consumed by a single pod, regardless of whether the device is allocated in
153+ // exclusive or shared (e.g., ipvlan, macvlan) way, so we process the first and only consumer in ReservedFor.
154+ reserved := claim .Status .ReservedFor [0 ]
155+ if reserved .Resource != "pods" || reserved .APIGroup != "" {
156+ return kubeletplugin.PrepareResult {
157+ Err : fmt .Errorf ("driver only supports Pods, unsupported reference %#v" , reserved ),
158+ }
159+ }
160+ podUID := reserved .UID
161+
161162 nlHandle , err := nlwrap .NewHandle ()
162163 if err != nil {
163164 return kubeletplugin.PrepareResult {
@@ -247,12 +248,10 @@ func (np *NetworkDriver) prepareResourceClaim(ctx context.Context, claim *resour
247248 continue
248249 }
249250 deviceCfg .RDMADevice = buildRDMAConfig (rdmaDevName , charDevices )
250- for _ , uid := range podUIDs {
251- if err := np .podConfigStore .SetDeviceConfig (uid , result .Device , deviceCfg ); err != nil {
252- errorList = append (errorList , fmt .Errorf ("failed to persist device config for pod %s device %s: %v" , uid , result .Device , err ))
253- }
251+ if err := np .podConfigStore .SetDeviceConfig (podUID , result .Device , deviceCfg ); err != nil {
252+ errorList = append (errorList , fmt .Errorf ("failed to persist device config for pod %s device %s: %v" , podUID , result .Device , err ))
254253 }
255- klog .V (4 ).Infof ("IB-only claim resources for pods %v : %#v" , podUIDs , deviceCfg )
254+ klog .V (4 ).Infof ("IB-only claim resources for pod %s : %#v" , podUID , deviceCfg )
256255 continue
257256 }
258257
@@ -395,14 +394,10 @@ func (np *NetworkDriver) prepareResourceClaim(ctx context.Context, claim *resour
395394 }
396395 }
397396
398- // TODO: support for multiple pods sharing the same device
399- // we'll create the subinterface here
400- for _ , uid := range podUIDs {
401- if err := np .podConfigStore .SetDeviceConfig (uid , result .Device , deviceCfg ); err != nil {
402- errorList = append (errorList , fmt .Errorf ("failed to persist device config for pod %s device %s: %v" , uid , result .Device , err ))
403- }
397+ if err := np .podConfigStore .SetDeviceConfig (podUID , result .Device , deviceCfg ); err != nil {
398+ errorList = append (errorList , fmt .Errorf ("failed to persist device config for pod %s device %s: %v" , podUID , result .Device , err ))
404399 }
405- klog .V (4 ).Infof ("Claim Resources for pods %v : %#v" , podUIDs , deviceCfg )
400+ klog .V (4 ).Infof ("Claim Resources for pod %s : %#v" , podUID , deviceCfg )
406401 }
407402
408403 if len (errorList ) > 0 {
0 commit comments