diff --git a/pkg/factory/aliyun/aliyun.go b/pkg/factory/aliyun/aliyun.go index 0da1ada4..e777a6f4 100644 --- a/pkg/factory/aliyun/aliyun.go +++ b/pkg/factory/aliyun/aliyun.go @@ -2,6 +2,7 @@ package aliyun import ( "context" + "fmt" "net/netip" "strings" "time" @@ -242,6 +243,31 @@ func (a *Aliyun) CreateNetworkInterface(ipv4, ipv6 int, eniType string) (*daemon r.GatewayIP.SetIP(gw.String()) } + var innerErr error + // we check openAPI at last to ensure the eni is at InUse status + err = wait.ExponentialBackoffWithContext(a.ctx, backoff.Backoff(backoff.ENICreate), func(ctx context.Context) (done bool, err error) { + var eniSet []*client.NetworkInterface + eniSet, innerErr = a.openAPI.DescribeNetworkInterface(ctx, "", []string{r.ID}, "", "", "", nil) + if innerErr != nil { + return false, nil + } + if len(eniSet) != 1 { + innerErr = fmt.Errorf("can not found eni %s, resp %#v", r.ID, eniSet) + return false, nil + } + if eniSet[0].Status != client.ENIStatusInUse { + innerErr = fmt.Errorf("eni %s at %s", r.ID, eniSet[0].Status) + return false, nil + } + return true, nil + }) + if err != nil { + if innerErr != nil { + err = innerErr + } + return r, v4Set, v6Set, err + } + return r, v4Set, v6Set, nil }