From a2f09ef25413789a3f6ec1f8713fde210220f735 Mon Sep 17 00:00:00 2001 From: l1b0k Date: Thu, 12 Dec 2024 11:59:39 +0800 Subject: [PATCH] validate the eni status to inUse resent eni attach behave changed, it will fail and rollback to Available , so check is necessary Signed-off-by: l1b0k --- pkg/factory/aliyun/aliyun.go | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) 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 }