@@ -188,11 +188,7 @@ func extractConnections(args *cniArgs) error {
188
188
return nil
189
189
}
190
190
191
- func getAllocatedDevices (args * cniArgs , devicePool string )(* []string , error ){
192
- checkpoint , err := checkpoint_utils .GetCheckpoint ()
193
- if err != nil {
194
- return nil , errors .New ("failed to instantiate checkpoint object due to:" + err .Error ())
195
- }
191
+ func getAllocatedDevices (args * cniArgs , checkpoint checkpoint_utils.Checkpoint , devicePool string )(* []string , error ){
196
192
resourceMap , err := checkpoint .GetComputeDeviceMap (string (args .podUid ))
197
193
if err != nil || len (resourceMap ) == 0 {
198
194
return nil , errors .New ("failed to retrieve Pod info from checkpoint object due to:" + err .Error ())
@@ -204,6 +200,7 @@ func getAllocatedDevices(args *cniArgs, devicePool string)(*[]string, error){
204
200
}
205
201
206
202
func popDevice (devicePool string , allocatedDevices map [string ]* []string )(string , error ) {
203
+ if len (allocatedDevices ) == 0 { return "" , errors .New ("allocatedDevices is empty" ) }
207
204
devices := (* allocatedDevices [devicePool ])
208
205
if len (devices ) == 0 { return "" , errors .New ("devicePool is empty" ) }
209
206
device , devices := devices [len (devices )- 1 ], devices [:len (devices )- 1 ]
@@ -218,6 +215,11 @@ func setupNetworking(args *cniArgs) (*current.Result, error) {
218
215
}
219
216
syncher := syncher .NewSyncher (len (args .interfaces ))
220
217
allocatedDevices := make (map [string ]* []string )
218
+
219
+ checkpoint , err := checkpoint_utils .GetCheckpoint ()
220
+ if err != nil {
221
+ return nil , errors .New ("failed to instantiate checkpoint object due to:" + err .Error ())
222
+ }
221
223
var cniRes * current.Result
222
224
for nicID , nicParams := range args .interfaces {
223
225
isDelegationRequired , netInfo , err := cnidel .IsDelegationRequired (danmClient , nicParams .Network , args .nameSpace )
@@ -228,7 +230,7 @@ func setupNetworking(args *cniArgs) (*current.Result, error) {
228
230
if isDelegationRequired {
229
231
if cnidel .IsDeviceNeeded (netInfo .Spec .NetworkType ) {
230
232
if _ , ok := allocatedDevices [netInfo .Spec .Options .DevicePool ]; ! ok {
231
- allocatedDevices [netInfo .Spec .Options .DevicePool ], err = getAllocatedDevices (args , netInfo .Spec .Options .DevicePool )
233
+ allocatedDevices [netInfo .Spec .Options .DevicePool ], err = getAllocatedDevices (args , checkpoint , netInfo .Spec .Options .DevicePool )
232
234
if err != nil {
233
235
return cniRes , errors .New ("failed to get allocated devices due to:" + err .Error ())
234
236
}
0 commit comments