diff --git a/pkg/eni/local.go b/pkg/eni/local.go index 6a32a68b..c1a7052b 100644 --- a/pkg/eni/local.go +++ b/pkg/eni/local.go @@ -7,6 +7,7 @@ import ( "fmt" "net/netip" "sort" + "strings" "sync" "time" @@ -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 { @@ -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)) diff --git a/pkg/factory/aliyun/aliyun.go b/pkg/factory/aliyun/aliyun.go index 945210d8..4756571e 100644 --- a/pkg/factory/aliyun/aliyun.go +++ b/pkg/factory/aliyun/aliyun.go @@ -3,6 +3,7 @@ package aliyun import ( "context" "net/netip" + "strings" "time" "github.com/google/uuid" @@ -82,7 +83,16 @@ 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 { @@ -90,16 +100,6 @@ func (a *Aliyun) CreateNetworkInterface(ipv4, ipv6 int, eniType string) (*daemon } 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) { @@ -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) diff --git a/types/daemon/types.go b/types/daemon/types.go index 3b9f8bda..c98c04cb 100644 --- a/types/daemon/types.go +++ b/types/daemon/types.go @@ -64,8 +64,6 @@ type ENI struct { VSwitchCIDR types.IPNetSet VSwitchID string - - Type string } // GetResourceID return mac address of eni