Skip to content

Commit

Permalink
gh-681: no need to check and return error if no existing loxilb-eni
Browse files Browse the repository at this point in the history
  • Loading branch information
TrekkieCoder committed May 28, 2024
1 parent 4b74f90 commit 0c1bb56
Showing 1 changed file with 25 additions and 26 deletions.
51 changes: 25 additions & 26 deletions pkg/loxinet/utils_aws.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ func AWSPrepVIPNetwork() error {
ctx, cancel := context.WithTimeout(context.Background(), time.Duration(time.Second*30))
defer cancel()

subnets := []string{}
filterStr := "tag:loxiType"
output, err := ec2Client.DescribeNetworkInterfaces(ctx, &ec2.DescribeNetworkInterfacesInput{
Filters: []types.Filter{
Expand All @@ -122,35 +123,33 @@ func AWSPrepVIPNetwork() error {
})
if err != nil {
tk.LogIt(tk.LogError, "no loxiType intf found\n")
return err
}

subnets := []string{}
for _, intf := range output.NetworkInterfaces {
subnets = append(subnets, *intf.SubnetId)
if intf.Attachment != nil {
force := true
_, err := ec2Client.DetachNetworkInterface(ctx, &ec2.DetachNetworkInterfaceInput{AttachmentId: intf.Attachment.AttachmentId, Force: &force})
if err != nil {
tk.LogIt(tk.LogError, "failed to detach intf (%s):%s\n", *intf.NetworkInterfaceId, err)
return err
} else {
for _, intf := range output.NetworkInterfaces {
subnets = append(subnets, *intf.SubnetId)
if intf.Attachment != nil {
force := true
_, err := ec2Client.DetachNetworkInterface(ctx, &ec2.DetachNetworkInterfaceInput{AttachmentId: intf.Attachment.AttachmentId, Force: &force})
if err != nil {
tk.LogIt(tk.LogError, "failed to detach intf (%s):%s\n", *intf.NetworkInterfaceId, err)
return err
}
}
}
loop := 20
for loop > 0 {
ctx2, cancel2 := context.WithTimeout(context.Background(), time.Duration(time.Second*10))
_, err2 := ec2Client.DeleteNetworkInterface(ctx2, &ec2.DeleteNetworkInterfaceInput{NetworkInterfaceId: intf.NetworkInterfaceId})
cancel2()
if err2 != nil {
tk.LogIt(tk.LogError, "failed to delete intf (%s):%s\n", *intf.NetworkInterfaceId, err2)
time.Sleep(2 * time.Second)
loop--
if loop <= 0 {
return err2
loop := 20
for loop > 0 {
ctx2, cancel2 := context.WithTimeout(context.Background(), time.Duration(time.Second*10))
_, err2 := ec2Client.DeleteNetworkInterface(ctx2, &ec2.DeleteNetworkInterfaceInput{NetworkInterfaceId: intf.NetworkInterfaceId})
cancel2()
if err2 != nil {
tk.LogIt(tk.LogError, "failed to delete intf (%s):%s\n", *intf.NetworkInterfaceId, err2)
time.Sleep(2 * time.Second)
loop--
if loop <= 0 {
return err2
}
continue
}
continue
break
}
break
}
}

Expand Down

0 comments on commit 0c1bb56

Please sign in to comment.