1
1
package datapath
2
2
3
3
import (
4
+ "context"
4
5
"fmt"
5
6
"net"
6
7
@@ -313,7 +314,7 @@ func generateHostSlaveCfg(cfg *types.SetupConfig, link netlink.Link) *nic.Conf {
313
314
return contCfg
314
315
}
315
316
316
- func (r * ExclusiveENI ) Setup (cfg * types.SetupConfig , netNS ns.NetNS ) error {
317
+ func (r * ExclusiveENI ) Setup (ctx context. Context , cfg * types.SetupConfig , netNS ns.NetNS ) error {
317
318
// 1. move link in
318
319
nicLink , err := netlink .LinkByIndex (cfg .ENIIndex )
319
320
if err != nil {
@@ -325,7 +326,7 @@ func (r *ExclusiveENI) Setup(cfg *types.SetupConfig, netNS ns.NetNS) error {
325
326
}
326
327
defer hostNetNS .Close ()
327
328
328
- err = utils .LinkSetNsFd (nicLink , netNS )
329
+ err = utils .LinkSetNsFd (ctx , nicLink , netNS )
329
330
if err != nil {
330
331
return fmt .Errorf ("error set nic %s to container, %w" , nicLink .Attrs ().Name , err )
331
332
}
@@ -339,7 +340,7 @@ func (r *ExclusiveENI) Setup(cfg *types.SetupConfig, netNS ns.NetNS) error {
339
340
if err1 != nil {
340
341
return err1
341
342
}
342
- err = utils .LinkSetName (nicLink , nicName )
343
+ err = utils .LinkSetName (ctx , nicLink , nicName )
343
344
if err != nil {
344
345
return err
345
346
}
@@ -350,8 +351,8 @@ func (r *ExclusiveENI) Setup(cfg *types.SetupConfig, netNS ns.NetNS) error {
350
351
nicLink , err = netlink .LinkByName (nicLink .Attrs ().Name )
351
352
}
352
353
if err == nil {
353
- err = utils .LinkSetDown (nicLink )
354
- return utils .LinkSetNsFd (nicLink , hostNetNS )
354
+ err = utils .LinkSetDown (ctx , nicLink )
355
+ return utils .LinkSetNsFd (ctx , nicLink , hostNetNS )
355
356
}
356
357
return err
357
358
})
@@ -366,7 +367,7 @@ func (r *ExclusiveENI) Setup(cfg *types.SetupConfig, netNS ns.NetNS) error {
366
367
}
367
368
368
369
contCfg := generateContCfgForExclusiveENI (cfg , contLink )
369
- err = nic .Setup (contLink , contCfg )
370
+ err = nic .Setup (ctx , contLink , contCfg )
370
371
if err != nil {
371
372
return err
372
373
}
@@ -380,7 +381,7 @@ func (r *ExclusiveENI) Setup(cfg *types.SetupConfig, netNS ns.NetNS) error {
380
381
381
382
// for now we only create slave link for eth0
382
383
if ! cfg .DisableCreatePeer && cfg .ContainerIfName == "eth0" {
383
- err = veth .Setup (& veth.Veth {
384
+ err = veth .Setup (ctx , & veth.Veth {
384
385
IfName : cfg .HostVETHName , // name for host ns side
385
386
PeerName : defaultVethForENI ,
386
387
}, hostNetNS )
@@ -406,7 +407,7 @@ func (r *ExclusiveENI) Setup(cfg *types.SetupConfig, netNS ns.NetNS) error {
406
407
return err
407
408
}
408
409
veth1Cfg := generateVeth1Cfg (cfg , veth1 , mac )
409
- return nic .Setup (veth1 , veth1Cfg )
410
+ return nic .Setup (ctx , veth1 , veth1Cfg )
410
411
}
411
412
return nil
412
413
})
@@ -423,28 +424,28 @@ func (r *ExclusiveENI) Setup(cfg *types.SetupConfig, netNS ns.NetNS) error {
423
424
return fmt .Errorf ("error get host veth %s, %w" , cfg .HostVETHName , err )
424
425
}
425
426
hostPeerCfg := generateHostSlaveCfg (cfg , hostPeer )
426
- err = nic .Setup (hostPeer , hostPeerCfg )
427
+ err = nic .Setup (ctx , hostPeer , hostPeerCfg )
427
428
if err != nil {
428
429
return fmt .Errorf ("error set up hostpeer, %w" , err )
429
430
}
430
431
431
432
return nil
432
433
}
433
434
434
- func (r * ExclusiveENI ) Check (cfg * types.CheckConfig ) error {
435
+ func (r * ExclusiveENI ) Check (ctx context. Context , cfg * types.CheckConfig ) error {
435
436
err := cfg .NetNS .Do (func (netNS ns.NetNS ) error {
436
437
link , err := netlink .LinkByName (cfg .ContainerIfName )
437
438
if err != nil {
438
439
return err
439
440
}
440
- changed , err := utils .EnsureLinkUp (link )
441
+ changed , err := utils .EnsureLinkUp (ctx , link )
441
442
if err != nil {
442
443
return err
443
444
}
444
445
if changed {
445
446
cfg .RecordPodEvent (fmt .Sprintf ("link %s set up" , cfg .ContainerIfName ))
446
447
}
447
- changed , err = utils .EnsureLinkMTU (link , cfg .MTU )
448
+ changed , err = utils .EnsureLinkMTU (ctx , link , cfg .MTU )
448
449
if err != nil {
449
450
return err
450
451
}
0 commit comments