Skip to content

Commit

Permalink
validate the eni status to inUse
Browse files Browse the repository at this point in the history
resent eni attach behave changed, it will fail and  rollback to Available , so check is necessary

Signed-off-by: l1b0k <[email protected]>
  • Loading branch information
l1b0k committed Dec 12, 2024
1 parent a030031 commit a2f09ef
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions pkg/factory/aliyun/aliyun.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package aliyun

import (
"context"
"fmt"
"net/netip"
"strings"
"time"
Expand Down Expand Up @@ -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
}

Expand Down

0 comments on commit a2f09ef

Please sign in to comment.