Skip to content

Commit

Permalink
Merge pull request #705 from l1b0k/feat/log
Browse files Browse the repository at this point in the history
pass ctx in cni call
  • Loading branch information
BSWANG authored Oct 21, 2024
2 parents 5e402ef + 2d1d7e9 commit 542a887
Show file tree
Hide file tree
Showing 27 changed files with 288 additions and 791 deletions.
3 changes: 0 additions & 3 deletions examples/maxpods/maxpods.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ import (
"io"
"log"

"github.com/sirupsen/logrus"

"github.com/AliyunContainerService/terway/pkg/aliyun/client"
"github.com/AliyunContainerService/terway/pkg/aliyun/credential"
"github.com/AliyunContainerService/terway/pkg/aliyun/instance"
Expand All @@ -34,7 +32,6 @@ func init() {
func main() {
flag.Parse()
log.SetOutput(io.Discard)
logrus.SetOutput(io.Discard)
ins := instance.GetInstanceMeta()

providers := []credential.Interface{
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ require (
github.com/prometheus/client_golang v1.15.1
github.com/pterm/pterm v0.12.62
github.com/samber/lo v1.39.0
github.com/sirupsen/logrus v1.9.3
github.com/spf13/cobra v1.6.1
github.com/stretchr/testify v1.9.0
github.com/vishvananda/netlink v1.2.1-beta.2
Expand Down Expand Up @@ -115,6 +114,7 @@ require (
github.com/safchain/ethtool v0.3.0 // indirect
github.com/segmentio/go-camelcase v0.0.0-20160726192923-7085f1e3c734 // indirect
github.com/segmentio/go-snakecase v1.2.0 // indirect
github.com/sirupsen/logrus v1.9.3 // indirect
github.com/spf13/pflag v1.0.5 // indirect
github.com/stretchr/objx v0.5.2 // indirect
github.com/vishvananda/netns v0.0.4 // indirect
Expand Down
64 changes: 0 additions & 64 deletions pkg/logger/log.go

This file was deleted.

3 changes: 2 additions & 1 deletion plugin/datapath/consts_linux_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@ package datapath
import (
"net"

terwayTypes "github.com/AliyunContainerService/terway/types"
"github.com/vishvananda/netlink"

terwayTypes "github.com/AliyunContainerService/terway/types"
)

var containerIPNet = &net.IPNet{
Expand Down
25 changes: 13 additions & 12 deletions plugin/datapath/exclusive_eni_linux.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package datapath

import (
"context"
"fmt"
"net"

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

func (r *ExclusiveENI) Setup(cfg *types.SetupConfig, netNS ns.NetNS) error {
func (r *ExclusiveENI) Setup(ctx context.Context, cfg *types.SetupConfig, netNS ns.NetNS) error {
// 1. move link in
nicLink, err := netlink.LinkByIndex(cfg.ENIIndex)
if err != nil {
Expand All @@ -325,7 +326,7 @@ func (r *ExclusiveENI) Setup(cfg *types.SetupConfig, netNS ns.NetNS) error {
}
defer hostNetNS.Close()

err = utils.LinkSetNsFd(nicLink, netNS)
err = utils.LinkSetNsFd(ctx, nicLink, netNS)
if err != nil {
return fmt.Errorf("error set nic %s to container, %w", nicLink.Attrs().Name, err)
}
Expand All @@ -339,7 +340,7 @@ func (r *ExclusiveENI) Setup(cfg *types.SetupConfig, netNS ns.NetNS) error {
if err1 != nil {
return err1
}
err = utils.LinkSetName(nicLink, nicName)
err = utils.LinkSetName(ctx, nicLink, nicName)
if err != nil {
return err
}
Expand All @@ -350,8 +351,8 @@ func (r *ExclusiveENI) Setup(cfg *types.SetupConfig, netNS ns.NetNS) error {
nicLink, err = netlink.LinkByName(nicLink.Attrs().Name)
}
if err == nil {
err = utils.LinkSetDown(nicLink)
return utils.LinkSetNsFd(nicLink, hostNetNS)
err = utils.LinkSetDown(ctx, nicLink)
return utils.LinkSetNsFd(ctx, nicLink, hostNetNS)
}
return err
})
Expand All @@ -366,7 +367,7 @@ func (r *ExclusiveENI) Setup(cfg *types.SetupConfig, netNS ns.NetNS) error {
}

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

// for now we only create slave link for eth0
if !cfg.DisableCreatePeer && cfg.ContainerIfName == "eth0" {
err = veth.Setup(&veth.Veth{
err = veth.Setup(ctx, &veth.Veth{
IfName: cfg.HostVETHName, // name for host ns side
PeerName: defaultVethForENI,
}, hostNetNS)
Expand All @@ -406,7 +407,7 @@ func (r *ExclusiveENI) Setup(cfg *types.SetupConfig, netNS ns.NetNS) error {
return err
}
veth1Cfg := generateVeth1Cfg(cfg, veth1, mac)
return nic.Setup(veth1, veth1Cfg)
return nic.Setup(ctx, veth1, veth1Cfg)
}
return nil
})
Expand All @@ -423,28 +424,28 @@ func (r *ExclusiveENI) Setup(cfg *types.SetupConfig, netNS ns.NetNS) error {
return fmt.Errorf("error get host veth %s, %w", cfg.HostVETHName, err)
}
hostPeerCfg := generateHostSlaveCfg(cfg, hostPeer)
err = nic.Setup(hostPeer, hostPeerCfg)
err = nic.Setup(ctx, hostPeer, hostPeerCfg)
if err != nil {
return fmt.Errorf("error set up hostpeer, %w", err)
}

return nil
}

func (r *ExclusiveENI) Check(cfg *types.CheckConfig) error {
func (r *ExclusiveENI) Check(ctx context.Context, cfg *types.CheckConfig) error {
err := cfg.NetNS.Do(func(netNS ns.NetNS) error {
link, err := netlink.LinkByName(cfg.ContainerIfName)
if err != nil {
return err
}
changed, err := utils.EnsureLinkUp(link)
changed, err := utils.EnsureLinkUp(ctx, link)
if err != nil {
return err
}
if changed {
cfg.RecordPodEvent(fmt.Sprintf("link %s set up", cfg.ContainerIfName))
}
changed, err = utils.EnsureLinkMTU(link, cfg.MTU)
changed, err = utils.EnsureLinkMTU(ctx, link, cfg.MTU)
if err != nil {
return err
}
Expand Down
5 changes: 3 additions & 2 deletions plugin/datapath/exclusive_eni_linux_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
package datapath

import (
"context"
"net"
"runtime"
"testing"
Expand Down Expand Up @@ -79,7 +80,7 @@ func TestDataPathExclusiveENI(t *testing.T) {
}

d := NewExclusiveENIDriver()
err = d.Setup(cfg, containerNS)
err = d.Setup(context.Background(), cfg, containerNS)
assert.NoError(t, err)

_ = containerNS.Do(func(netNS ns.NetNS) error {
Expand Down Expand Up @@ -162,7 +163,7 @@ func TestDataPathExclusiveENI(t *testing.T) {
err = netlink.RuleAdd(dummyRule)
assert.NoError(t, err)
// tear down
err = utils.GenericTearDown(containerNS)
err = utils.GenericTearDown(context.Background(), containerNS)
assert.NoError(t, err)

_, err = netlink.LinkByName(cfg.HostVETHName)
Expand Down
Loading

0 comments on commit 542a887

Please sign in to comment.