99 "time"
1010
1111 apiErr "github.com/AliyunContainerService/terway/pkg/aliyun/errors"
12+ "github.com/AliyunContainerService/terway/pkg/backoff"
1213 "github.com/AliyunContainerService/terway/pkg/ip"
1314 "github.com/AliyunContainerService/terway/pkg/ipam"
1415 "github.com/AliyunContainerService/terway/pkg/logger"
@@ -87,7 +88,7 @@ func (e *Impl) AllocateENI(ctx context.Context, vSwitch string, securityGroups [
8788 }()
8889
8990 var innerErr error
90- err = wait .ExponentialBackoffWithContext (ctx , ENIOpBackoff , func () (bool , error ) {
91+ err = wait .ExponentialBackoffWithContext (ctx , backoff . Backoff ( backoff . WaitENIStatus ) , func () (bool , error ) {
9192 innerErr = e .AttachNetworkInterface (ctx , resp .NetworkInterfaceId , instanceID , "" )
9293 if innerErr != nil {
9394 return false , nil
@@ -105,8 +106,8 @@ func (e *Impl) AllocateENI(ctx context.Context, vSwitch string, securityGroups [
105106
106107 start := time .Now ()
107108 // bind status is async api, sleep for first bind status inspect
108- time .Sleep (eniStateBackoff .Duration )
109- eniStatus , err := e .WaitForNetworkInterface (ctx , resp .NetworkInterfaceId , ENIStatusInUse , eniStateBackoff , false )
109+ time .Sleep (backoff . Backoff ( backoff . WaitENIStatus ) .Duration )
110+ eniStatus , err := e .WaitForNetworkInterface (ctx , resp .NetworkInterfaceId , ENIStatusInUse , backoff . Backoff ( backoff . WaitENIStatus ) , false )
110111 metric .OpenAPILatency .WithLabelValues ("WaitForNetworkInterfaceBind/" + string (ENIStatusInUse ), fmt .Sprint (err != nil )).Observe (metric .MsSince (start ))
111112
112113 if err != nil {
@@ -115,8 +116,7 @@ func (e *Impl) AllocateENI(ctx context.Context, vSwitch string, securityGroups [
115116
116117 var eni * types.ENI
117118 // backoff get eni config
118- err = wait .ExponentialBackoffWithContext (ctx ,
119- eniStateBackoff ,
119+ err = wait .ExponentialBackoffWithContext (ctx , backoff .Backoff (backoff .WaitENIStatus ),
120120 func () (done bool , err error ) {
121121 l , ok := GetLimit (GetInstanceMeta ().InstanceType )
122122 if ! ok {
@@ -147,8 +147,7 @@ func (e *Impl) FreeENI(ctx context.Context, eniID, instanceID string) error {
147147
148148func (e * Impl ) destroyInterface (ctx context.Context , eniID , instanceID , trunkENIID string ) error {
149149 var innerErr error
150- err := wait .ExponentialBackoffWithContext (ctx ,
151- eniReleaseBackoff ,
150+ err := wait .ExponentialBackoffWithContext (ctx , backoff .Backoff (backoff .ENIRelease ),
152151 func () (done bool , err error ) {
153152 innerErr = e .DetachNetworkInterface (ctx , eniID , instanceID , trunkENIID )
154153 if innerErr != nil {
@@ -163,11 +162,10 @@ func (e *Impl) destroyInterface(ctx context.Context, eniID, instanceID, trunkENI
163162 tracing .DisposeResourceFailed , fmtErr )
164163 }
165164
166- time .Sleep (eniStateBackoff .Duration )
165+ time .Sleep (backoff . Backoff ( backoff . WaitENIStatus ) .Duration )
167166
168167 // backoff delete network interface
169- err = wait .ExponentialBackoffWithContext (ctx ,
170- eniReleaseBackoff ,
168+ err = wait .ExponentialBackoffWithContext (ctx , backoff .Backoff (backoff .ENIOps ),
171169 func () (done bool , err error ) {
172170 innerErr = e .DeleteNetworkInterface (context .Background (), eniID )
173171 if innerErr != nil {
@@ -272,7 +270,7 @@ func (e *Impl) AssignNIPsForENI(ctx context.Context, eniID, mac string, count in
272270
273271 if e .ipFamily .IPv4 {
274272 var innerErr error
275- err = wait .ExponentialBackoffWithContext (ctx , ENIOpBackoff , func () (bool , error ) {
273+ err = wait .ExponentialBackoffWithContext (ctx , backoff . Backoff ( backoff . ENIOps ) , func () (bool , error ) {
276274 ipv4s , innerErr = e .AssignPrivateIPAddress (ctx , eniID , count )
277275 if innerErr != nil {
278276 if apiErr .ErrAssert (apiErr .InvalidVSwitchIDIPNotEnough , innerErr ) {
@@ -291,8 +289,7 @@ func (e *Impl) AssignNIPsForENI(ctx context.Context, eniID, mac string, count in
291289 wg .Add (1 )
292290 go func () {
293291 defer wg .Done ()
294- v4Err = wait .ExponentialBackoffWithContext (ctx ,
295- MetadataAssignPrivateIPBackoff ,
292+ v4Err = wait .ExponentialBackoffWithContext (ctx , backoff .Backoff (backoff .MetaAssignPrivateIP ),
296293 func () (done bool , err error ) {
297294 remoteIPs , err := e .metadata .GetENIPrivateAddressesByMAC (mac )
298295 if err != nil {
@@ -309,7 +306,7 @@ func (e *Impl) AssignNIPsForENI(ctx context.Context, eniID, mac string, count in
309306
310307 if e .ipFamily .IPv6 {
311308 var innerErr error
312- err = wait .ExponentialBackoffWithContext (ctx , ENIOpBackoff , func () (bool , error ) {
309+ err = wait .ExponentialBackoffWithContext (ctx , backoff . Backoff ( backoff . ENIOps ) , func () (bool , error ) {
313310 ipv6s , innerErr = e .AssignIpv6Addresses (ctx , eniID , count )
314311 if innerErr != nil {
315312 if apiErr .ErrAssert (apiErr .InvalidVSwitchIDIPNotEnough , innerErr ) {
@@ -328,8 +325,7 @@ func (e *Impl) AssignNIPsForENI(ctx context.Context, eniID, mac string, count in
328325 wg .Add (1 )
329326 go func () {
330327 defer wg .Done ()
331- v6Err = wait .ExponentialBackoffWithContext (ctx ,
332- MetadataAssignPrivateIPBackoff ,
328+ v6Err = wait .ExponentialBackoffWithContext (ctx , backoff .Backoff (backoff .MetaAssignPrivateIP ),
333329 func () (done bool , err error ) {
334330 remoteIPs , err := e .metadata .GetENIPrivateIPv6AddressesByMAC (mac )
335331 if err != nil {
@@ -365,7 +361,7 @@ func (e *Impl) unAssignIPsForENIUnSafe(ctx context.Context, eniID, mac string, i
365361 if len (ipv4s ) > 0 {
366362 var innerErr error
367363
368- err := wait .ExponentialBackoffWithContext (ctx , ENIOpBackoff , func () (bool , error ) {
364+ err := wait .ExponentialBackoffWithContext (ctx , backoff . Backoff ( backoff . ENIOps ) , func () (bool , error ) {
369365 innerErr = e .UnAssignPrivateIPAddresses (ctx , eniID , ipv4s )
370366 if innerErr != nil {
371367 return false , nil
@@ -380,7 +376,7 @@ func (e *Impl) unAssignIPsForENIUnSafe(ctx context.Context, eniID, mac string, i
380376 if len (ipv6s ) > 0 {
381377 var innerErr error
382378
383- err := wait .ExponentialBackoffWithContext (ctx , ENIOpBackoff , func () (bool , error ) {
379+ err := wait .ExponentialBackoffWithContext (ctx , backoff . Backoff ( backoff . ENIOps ) , func () (bool , error ) {
384380 innerErr = e .UnAssignIpv6Addresses (ctx , eniID , ipv6s )
385381 if innerErr != nil {
386382 return false , nil
@@ -402,12 +398,11 @@ func (e *Impl) unAssignIPsForENIUnSafe(ctx context.Context, eniID, mac string, i
402398 start := time .Now ()
403399
404400 // unassignPrivateIpAddresses is async api, sleep for first ip addr inspect
405- time .Sleep (MetadataUnAssignPrivateIPBackoff .Duration )
401+ time .Sleep (backoff . Backoff ( backoff . MetaUnAssignPrivateIP ) .Duration )
406402 // backoff get interface addresses
407403 var innerErr error
408404
409- err := wait .ExponentialBackoffWithContext (ctx ,
410- MetadataUnAssignPrivateIPBackoff ,
405+ err := wait .ExponentialBackoffWithContext (ctx , backoff .Backoff (backoff .MetaUnAssignPrivateIP ),
411406 func () (done bool , err error ) {
412407 if len (ipv4s ) > 0 {
413408 remoteIPs , err := e .metadata .GetENIPrivateAddressesByMAC (mac )
0 commit comments