Skip to content

Commit 542a887

Browse files
authored
Merge pull request #705 from l1b0k/feat/log
pass ctx in cni call
2 parents 5e402ef + 2d1d7e9 commit 542a887

27 files changed

+288
-791
lines changed

examples/maxpods/maxpods.go

-3
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@ import (
66
"io"
77
"log"
88

9-
"github.com/sirupsen/logrus"
10-
119
"github.com/AliyunContainerService/terway/pkg/aliyun/client"
1210
"github.com/AliyunContainerService/terway/pkg/aliyun/credential"
1311
"github.com/AliyunContainerService/terway/pkg/aliyun/instance"
@@ -34,7 +32,6 @@ func init() {
3432
func main() {
3533
flag.Parse()
3634
log.SetOutput(io.Discard)
37-
logrus.SetOutput(io.Discard)
3835
ins := instance.GetInstanceMeta()
3936

4037
providers := []credential.Interface{

go.mod

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ require (
2424
github.com/prometheus/client_golang v1.15.1
2525
github.com/pterm/pterm v0.12.62
2626
github.com/samber/lo v1.39.0
27-
github.com/sirupsen/logrus v1.9.3
2827
github.com/spf13/cobra v1.6.1
2928
github.com/stretchr/testify v1.9.0
3029
github.com/vishvananda/netlink v1.2.1-beta.2
@@ -115,6 +114,7 @@ require (
115114
github.com/safchain/ethtool v0.3.0 // indirect
116115
github.com/segmentio/go-camelcase v0.0.0-20160726192923-7085f1e3c734 // indirect
117116
github.com/segmentio/go-snakecase v1.2.0 // indirect
117+
github.com/sirupsen/logrus v1.9.3 // indirect
118118
github.com/spf13/pflag v1.0.5 // indirect
119119
github.com/stretchr/objx v0.5.2 // indirect
120120
github.com/vishvananda/netns v0.0.4 // indirect

pkg/logger/log.go

-64
This file was deleted.

plugin/datapath/consts_linux_test.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,9 @@ package datapath
55
import (
66
"net"
77

8-
terwayTypes "github.com/AliyunContainerService/terway/types"
98
"github.com/vishvananda/netlink"
9+
10+
terwayTypes "github.com/AliyunContainerService/terway/types"
1011
)
1112

1213
var containerIPNet = &net.IPNet{

plugin/datapath/exclusive_eni_linux.go

+13-12
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package datapath
22

33
import (
4+
"context"
45
"fmt"
56
"net"
67

@@ -313,7 +314,7 @@ func generateHostSlaveCfg(cfg *types.SetupConfig, link netlink.Link) *nic.Conf {
313314
return contCfg
314315
}
315316

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 {
317318
// 1. move link in
318319
nicLink, err := netlink.LinkByIndex(cfg.ENIIndex)
319320
if err != nil {
@@ -325,7 +326,7 @@ func (r *ExclusiveENI) Setup(cfg *types.SetupConfig, netNS ns.NetNS) error {
325326
}
326327
defer hostNetNS.Close()
327328

328-
err = utils.LinkSetNsFd(nicLink, netNS)
329+
err = utils.LinkSetNsFd(ctx, nicLink, netNS)
329330
if err != nil {
330331
return fmt.Errorf("error set nic %s to container, %w", nicLink.Attrs().Name, err)
331332
}
@@ -339,7 +340,7 @@ func (r *ExclusiveENI) Setup(cfg *types.SetupConfig, netNS ns.NetNS) error {
339340
if err1 != nil {
340341
return err1
341342
}
342-
err = utils.LinkSetName(nicLink, nicName)
343+
err = utils.LinkSetName(ctx, nicLink, nicName)
343344
if err != nil {
344345
return err
345346
}
@@ -350,8 +351,8 @@ func (r *ExclusiveENI) Setup(cfg *types.SetupConfig, netNS ns.NetNS) error {
350351
nicLink, err = netlink.LinkByName(nicLink.Attrs().Name)
351352
}
352353
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)
355356
}
356357
return err
357358
})
@@ -366,7 +367,7 @@ func (r *ExclusiveENI) Setup(cfg *types.SetupConfig, netNS ns.NetNS) error {
366367
}
367368

368369
contCfg := generateContCfgForExclusiveENI(cfg, contLink)
369-
err = nic.Setup(contLink, contCfg)
370+
err = nic.Setup(ctx, contLink, contCfg)
370371
if err != nil {
371372
return err
372373
}
@@ -380,7 +381,7 @@ func (r *ExclusiveENI) Setup(cfg *types.SetupConfig, netNS ns.NetNS) error {
380381

381382
// for now we only create slave link for eth0
382383
if !cfg.DisableCreatePeer && cfg.ContainerIfName == "eth0" {
383-
err = veth.Setup(&veth.Veth{
384+
err = veth.Setup(ctx, &veth.Veth{
384385
IfName: cfg.HostVETHName, // name for host ns side
385386
PeerName: defaultVethForENI,
386387
}, hostNetNS)
@@ -406,7 +407,7 @@ func (r *ExclusiveENI) Setup(cfg *types.SetupConfig, netNS ns.NetNS) error {
406407
return err
407408
}
408409
veth1Cfg := generateVeth1Cfg(cfg, veth1, mac)
409-
return nic.Setup(veth1, veth1Cfg)
410+
return nic.Setup(ctx, veth1, veth1Cfg)
410411
}
411412
return nil
412413
})
@@ -423,28 +424,28 @@ func (r *ExclusiveENI) Setup(cfg *types.SetupConfig, netNS ns.NetNS) error {
423424
return fmt.Errorf("error get host veth %s, %w", cfg.HostVETHName, err)
424425
}
425426
hostPeerCfg := generateHostSlaveCfg(cfg, hostPeer)
426-
err = nic.Setup(hostPeer, hostPeerCfg)
427+
err = nic.Setup(ctx, hostPeer, hostPeerCfg)
427428
if err != nil {
428429
return fmt.Errorf("error set up hostpeer, %w", err)
429430
}
430431

431432
return nil
432433
}
433434

434-
func (r *ExclusiveENI) Check(cfg *types.CheckConfig) error {
435+
func (r *ExclusiveENI) Check(ctx context.Context, cfg *types.CheckConfig) error {
435436
err := cfg.NetNS.Do(func(netNS ns.NetNS) error {
436437
link, err := netlink.LinkByName(cfg.ContainerIfName)
437438
if err != nil {
438439
return err
439440
}
440-
changed, err := utils.EnsureLinkUp(link)
441+
changed, err := utils.EnsureLinkUp(ctx, link)
441442
if err != nil {
442443
return err
443444
}
444445
if changed {
445446
cfg.RecordPodEvent(fmt.Sprintf("link %s set up", cfg.ContainerIfName))
446447
}
447-
changed, err = utils.EnsureLinkMTU(link, cfg.MTU)
448+
changed, err = utils.EnsureLinkMTU(ctx, link, cfg.MTU)
448449
if err != nil {
449450
return err
450451
}

plugin/datapath/exclusive_eni_linux_test.go

+3-2
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
package datapath
44

55
import (
6+
"context"
67
"net"
78
"runtime"
89
"testing"
@@ -79,7 +80,7 @@ func TestDataPathExclusiveENI(t *testing.T) {
7980
}
8081

8182
d := NewExclusiveENIDriver()
82-
err = d.Setup(cfg, containerNS)
83+
err = d.Setup(context.Background(), cfg, containerNS)
8384
assert.NoError(t, err)
8485

8586
_ = containerNS.Do(func(netNS ns.NetNS) error {
@@ -162,7 +163,7 @@ func TestDataPathExclusiveENI(t *testing.T) {
162163
err = netlink.RuleAdd(dummyRule)
163164
assert.NoError(t, err)
164165
// tear down
165-
err = utils.GenericTearDown(containerNS)
166+
err = utils.GenericTearDown(context.Background(), containerNS)
166167
assert.NoError(t, err)
167168

168169
_, err = netlink.LinkByName(cfg.HostVETHName)

0 commit comments

Comments
 (0)