From 0c1bb562da8a93ef7d6b64219b5e4c56f953463d Mon Sep 17 00:00:00 2001 From: Trekkie Coder Date: Tue, 28 May 2024 20:29:55 +0900 Subject: [PATCH] gh-681: no need to check and return error if no existing loxilb-eni --- pkg/loxinet/utils_aws.go | 51 ++++++++++++++++++++-------------------- 1 file changed, 25 insertions(+), 26 deletions(-) diff --git a/pkg/loxinet/utils_aws.go b/pkg/loxinet/utils_aws.go index 85a53e29..d0126a67 100644 --- a/pkg/loxinet/utils_aws.go +++ b/pkg/loxinet/utils_aws.go @@ -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{ @@ -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 } }