Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pass ctx in cni call #705

Merged
merged 1 commit into from
Oct 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@
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 @@
}
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 @@
if err1 != nil {
return err1
}
err = utils.LinkSetName(nicLink, nicName)
err = utils.LinkSetName(ctx, nicLink, nicName)

Check warning on line 343 in plugin/datapath/exclusive_eni_linux.go

View check run for this annotation

Codecov / codecov/patch

plugin/datapath/exclusive_eni_linux.go#L343

Added line #L343 was not covered by tests
if err != nil {
return err
}
Expand All @@ -350,8 +351,8 @@
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)

Check warning on line 355 in plugin/datapath/exclusive_eni_linux.go

View check run for this annotation

Codecov / codecov/patch

plugin/datapath/exclusive_eni_linux.go#L354-L355

Added lines #L354 - L355 were not covered by tests
}
return err
})
Expand All @@ -366,7 +367,7 @@
}

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 @@

// 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 @@
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 @@
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 {

Check warning on line 435 in plugin/datapath/exclusive_eni_linux.go

View check run for this annotation

Codecov / codecov/patch

plugin/datapath/exclusive_eni_linux.go#L435

Added line #L435 was not covered by tests
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)

Check warning on line 441 in plugin/datapath/exclusive_eni_linux.go

View check run for this annotation

Codecov / codecov/patch

plugin/datapath/exclusive_eni_linux.go#L441

Added line #L441 was not covered by tests
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)

Check warning on line 448 in plugin/datapath/exclusive_eni_linux.go

View check run for this annotation

Codecov / codecov/patch

plugin/datapath/exclusive_eni_linux.go#L448

Added line #L448 was not covered by tests
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
Loading