Skip to content

Commit

Permalink
Merge pull request #576 from l1b0k/fix/enitype
Browse files Browse the repository at this point in the history
fix: eni type check
  • Loading branch information
BSWANG authored Feb 28, 2024
2 parents ecdd975 + 61b7b37 commit 8ddf95f
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 16 deletions.
5 changes: 3 additions & 2 deletions pkg/eni/local.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"fmt"
"net/netip"
"sort"
"strings"
"sync"
"time"

Expand Down Expand Up @@ -195,7 +196,7 @@ func (l *Local) load(podResources []daemon.PodResources) error {
return err
}

logf.Log.Info("load eni", "eni", l.eni.ID, "mac", l.eni.MAC, "ipv4", ipv4, "ipv6", ipv6)
logf.Log.Info("load eni", "eni", l.eni.ID, "type", l.eniType, "mac", l.eni.MAC, "ipv4", ipv4, "ipv6", ipv6)

primary, err := netip.ParseAddr(l.eni.PrimaryIP.IPv4.String())
if err != nil {
Expand Down Expand Up @@ -690,7 +691,7 @@ func (l *Local) Dispose(n int) int {

// 1. check if can dispose the eni
if n >= max(len(l.ipv4), len(l.ipv6)) {
if l.eni.Type != "trunk" && len(l.ipv4.InUse()) == 0 && len(l.ipv6.InUse()) == 0 {
if strings.ToLower(l.eniType) != "trunk" && !l.eni.Trunk && len(l.ipv4.InUse()) == 0 && len(l.ipv6.InUse()) == 0 {
log.Info("dispose eni")
l.status = statusDeleting
return max(len(l.ipv4), len(l.ipv6))
Expand Down
25 changes: 13 additions & 12 deletions pkg/factory/aliyun/aliyun.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package aliyun
import (
"context"
"net/netip"
"strings"
"time"

"github.com/google/uuid"
Expand Down Expand Up @@ -82,24 +83,23 @@ func (a *Aliyun) CreateNetworkInterface(ipv4, ipv6 int, eniType string) (*daemon
// 1. create eni
var eni *client.NetworkInterface
var vswID string

var (
trunk bool
erdma bool
)
if strings.ToLower(eniType) == "trunk" {
trunk = true
}
if strings.ToLower(eniType) == "erdma" {
erdma = true
}
err := wait.ExponentialBackoffWithContext(a.ctx, backoff.Backoff(backoff.ENICreate), func(ctx context.Context) (bool, error) {
vsw, innerErr := a.vsw.GetOne(ctx, a.openAPI, a.zoneID, a.vSwitchOptions)
if innerErr != nil {
return false, innerErr
}
vswID = vsw.ID

var (
trunk bool
erdma bool
)
if eniType == "trunk" {
trunk = true
}
if eniType == "erdma" {
erdma = true
}
eni, innerErr = a.openAPI.CreateNetworkInterface(ctx, trunk, erdma, vswID, a.securityGroupIDs, a.resourceGroupID, ipv4, ipv6, a.eniTags)
if innerErr != nil {
if apiErr.ErrAssert(apiErr.ErrForbidden, innerErr) {
Expand All @@ -126,7 +126,8 @@ func (a *Aliyun) CreateNetworkInterface(ipv4, ipv6 int, eniType string) (*daemon
ID: eni.NetworkInterfaceID,
MAC: eni.MacAddress,
VSwitchID: eni.VSwitchID,
Type: eni.Type,
Trunk: trunk,
ERdma: erdma,
}

r.PrimaryIP.SetIP(eni.PrivateIPAddress)
Expand Down
2 changes: 0 additions & 2 deletions types/daemon/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,6 @@ type ENI struct {
VSwitchCIDR types.IPNetSet

VSwitchID string

Type string
}

// GetResourceID return mac address of eni
Expand Down

0 comments on commit 8ddf95f

Please sign in to comment.