Skip to content

Commit a6e4cd7

Browse files
authored
fix: check trunkENI attached status if it already exists before adding to cache (#289)
* chore: bump gomega and update developer guide * fix: check trunkENI attached status if it already exists before adding to cache
1 parent 3dda523 commit a6e4cd7

File tree

9 files changed

+191
-150
lines changed

9 files changed

+191
-150
lines changed

DEVELOPER_GUIDE.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ for ENI trunking before the deployment.
1414
```sh
1515
make apply-dependencies # install the cert manager and certificate
1616
make apply # Apply your changes
17-
make e2etest # Run the integration test suite
17+
make test-e2e # Run the integration test suite
1818
```
1919

2020
In another terminal, you can tail the logs with stern

go.mod

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ require (
1010
github.com/golang/mock v1.6.0
1111
github.com/google/uuid v1.3.0
1212
github.com/onsi/ginkgo/v2 v2.11.0
13-
github.com/onsi/gomega v1.27.8
13+
github.com/onsi/gomega v1.27.10
1414
github.com/pkg/errors v0.9.1
1515
github.com/prometheus/client_golang v1.15.1
1616
github.com/prometheus/client_model v0.4.0
@@ -61,11 +61,11 @@ require (
6161
go.uber.org/atomic v1.7.0 // indirect
6262
go.uber.org/multierr v1.6.0 // indirect
6363
golang.org/x/exp v0.0.0-20230315142452-642cacee5cc0
64-
golang.org/x/net v0.10.0 // indirect
64+
golang.org/x/net v0.12.0 // indirect
6565
golang.org/x/oauth2 v0.5.0 // indirect
66-
golang.org/x/sys v0.9.0 // indirect
67-
golang.org/x/term v0.8.0 // indirect
68-
golang.org/x/text v0.9.0 // indirect
66+
golang.org/x/sys v0.10.0 // indirect
67+
golang.org/x/term v0.10.0 // indirect
68+
golang.org/x/text v0.11.0 // indirect
6969
golang.org/x/tools v0.9.3 // indirect
7070
google.golang.org/appengine v1.6.7 // indirect
7171
google.golang.org/protobuf v1.30.0 // indirect

go.sum

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -139,8 +139,8 @@ github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 h1:C3w9PqII01/Oq
139139
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822/go.mod h1:+n7T8mK8HuQTcFwEeznm/DIxMOiR9yIdICNftLE1DvQ=
140140
github.com/onsi/ginkgo/v2 v2.11.0 h1:WgqUCUt/lT6yXoQ8Wef0fsNn5cAuMK7+KT9UFRz2tcU=
141141
github.com/onsi/ginkgo/v2 v2.11.0/go.mod h1:ZhrRA5XmEE3x3rhlzamx/JJvujdZoJ2uvgI7kR0iZvM=
142-
github.com/onsi/gomega v1.27.8 h1:gegWiwZjBsf2DgiSbf5hpokZ98JVDMcWkUiigk6/KXc=
143-
github.com/onsi/gomega v1.27.8/go.mod h1:2J8vzI/s+2shY9XHRApDkdgPo1TKT7P2u6fXeJKFnNQ=
142+
github.com/onsi/gomega v1.27.10 h1:naR28SdDFlqrG6kScpT8VWpu1xWY5nJRCF3XaYyBjhI=
143+
github.com/onsi/gomega v1.27.10/go.mod h1:RsS8tutOdbdgzbPtzzATp12yT7kM5I5aElG3evPbQ0M=
144144
github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
145145
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
146146
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
@@ -217,8 +217,8 @@ golang.org/x/net v0.0.0-20201021035429-f5854403a974/go.mod h1:sp8m0HH+o8qH0wwXwY
217217
golang.org/x/net v0.0.0-20210405180319-a5a99cb37ef4/go.mod h1:p54w0d4576C0XHj96bSt6lcn1PtDYWL6XObtHCRCNQM=
218218
golang.org/x/net v0.0.0-20210805182204-aaa1db679c0d/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
219219
golang.org/x/net v0.0.0-20220127200216-cd36cc0744dd/go.mod h1:CfG3xpIq0wQ8r1q4Su4UZFWDARRcnwPjda9FqA0JpMk=
220-
golang.org/x/net v0.10.0 h1:X2//UzNDwYmtCLn7To6G58Wr6f5ahEAQgKNzv9Y951M=
221-
golang.org/x/net v0.10.0/go.mod h1:0qNGK6F8kojg2nk9dLZ2mShWaEBan6FAoqfSigmmuDg=
220+
golang.org/x/net v0.12.0 h1:cfawfvKITfUsFCeJIHJrbSxpeu/E81khclypR0GVT50=
221+
golang.org/x/net v0.12.0/go.mod h1:zEVYFnQC7m/vmpQFELhcD1EWkZlX69l4oqgmer6hfKA=
222222
golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U=
223223
golang.org/x/oauth2 v0.0.0-20200107190931-bf48bf16ab8d/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw=
224224
golang.org/x/oauth2 v0.5.0 h1:HuArIo48skDwlrvM3sEdHXElYslAMsf3KwRkkW4MC4s=
@@ -243,20 +243,20 @@ golang.org/x/sys v0.0.0-20210510120138-977fb7262007/go.mod h1:oPkhp1MJrh7nUepCBc
243243
golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
244244
golang.org/x/sys v0.0.0-20211216021012-1d35b9e2eb4e/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
245245
golang.org/x/sys v0.0.0-20220908164124-27713097b956/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
246-
golang.org/x/sys v0.9.0 h1:KS/R3tvhPqvJvwcKfnBHJwwthS11LRhmM5D59eEXa0s=
247-
golang.org/x/sys v0.9.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
246+
golang.org/x/sys v0.10.0 h1:SqMFp9UcQJZa+pmYuAKjd9xq1f0j5rLcDIk0mj4qAsA=
247+
golang.org/x/sys v0.10.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
248248
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
249249
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
250-
golang.org/x/term v0.8.0 h1:n5xxQn2i3PC0yLAbjTpNT85q/Kgzcr2gIoX9OrJUols=
251-
golang.org/x/term v0.8.0/go.mod h1:xPskH00ivmX89bAKVGSKKtLOWNx2+17Eiy94tnKShWo=
250+
golang.org/x/term v0.10.0 h1:3R7pNqamzBraeqj/Tj8qt1aQ2HpmlC+Cx/qL/7hn4/c=
251+
golang.org/x/term v0.10.0/go.mod h1:lpqdcUyK/oCiQxvxVrppt5ggO2KCZ5QblwqPnfZ6d5o=
252252
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
253253
golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk=
254254
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
255255
golang.org/x/text v0.3.5/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
256256
golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
257257
golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ=
258-
golang.org/x/text v0.9.0 h1:2sjJmO8cDvYveuX97RDLsxlyUxLl+GHoLxBiRdHllBE=
259-
golang.org/x/text v0.9.0/go.mod h1:e1OnstbJyHTd6l/uOt8jFFHp6TRDWZR/bV3emEE/zU8=
258+
golang.org/x/text v0.11.0 h1:LAntKIrcmeSKERyiOh0XMV39LXS8IE9UL2yP7+f5ij4=
259+
golang.org/x/text v0.11.0/go.mod h1:TvPlkZtksWOMsz7fbANvkp4WM8x/WCo/om8BMLbz+aE=
260260
golang.org/x/time v0.3.0 h1:rg5rLMjNzMS1RkNLzCG38eapWhnYLFYXDXj2gOlr8j4=
261261
golang.org/x/time v0.3.0/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
262262
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=

hack/toolchain.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ main() {
1212
tools() {
1313
go install sigs.k8s.io/controller-runtime/tools/[email protected]
1414
go install sigs.k8s.io/controller-tools/cmd/[email protected]
15+
go install github.com/google/ko@latest
1516

1617
if ! echo "$PATH" | grep -q "${GOPATH:-undefined}/bin\|$HOME/go/bin"; then
1718
echo "Go workspace's \"bin\" directory is not in PATH. Run 'export PATH=\"\$PATH:\${GOPATH:-\$HOME/go}/bin\"'."

pkg/aws/ec2/api/eni_cleanup_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import (
1919
"reflect"
2020
"testing"
2121

22-
"github.com/aws/amazon-vpc-resource-controller-k8s/mocks/amazon-vcp-resource-controller-k8s/pkg/aws/ec2/api"
22+
mock_api "github.com/aws/amazon-vpc-resource-controller-k8s/mocks/amazon-vcp-resource-controller-k8s/pkg/aws/ec2/api"
2323
"github.com/aws/amazon-vpc-resource-controller-k8s/pkg/config"
2424

2525
"github.com/aws/aws-sdk-go/aws"

pkg/aws/ec2/api/helper.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ func (h *ec2APIHelper) CreateNetworkInterface(description *string, subnetId *str
171171
if err != nil {
172172
errDelete := h.DeleteNetworkInterface(nwInterface.NetworkInterfaceId)
173173
if errDelete != nil {
174-
return nwInterface, fmt.Errorf("failed to attach the network interface %v: failed to delete the nw interfac %v",
174+
return nwInterface, fmt.Errorf("failed to attach the network interface permissions %v: failed to delete the nw interfac %v",
175175
err, errDelete)
176176
}
177177
return nil, fmt.Errorf("failed to get attach network interface permissions for trunk %v", err)
@@ -396,8 +396,8 @@ func (h *ec2APIHelper) DetachNetworkInterfaceFromInstance(attachmentId *string)
396396
return err
397397
}
398398

399-
// WaitForNetworkInterfaceStatusChange keeps on retrying with backoff to see if the current status of the network
400-
// interface is equal to the desired state of the network interface
399+
// WaitForNetworkInterfaceStatusChange checks if the current network interface attachment status
400+
// equals the desired status with backoff
401401
func (h *ec2APIHelper) WaitForNetworkInterfaceStatusChange(networkInterfaceId *string, desiredStatus string) error {
402402

403403
ErrRetryAttachmentStatusCheck := fmt.Errorf("interface not in desired status yet %s, interface id %s",
@@ -607,7 +607,7 @@ func (h *ec2APIHelper) DetachAndDeleteNetworkInterface(attachmentID *string, nwI
607607
if err != nil {
608608
return err
609609
}
610-
err = h.WaitForNetworkInterfaceStatusChange(nwInterfaceID, ec2.NetworkInterfaceStatusAvailable)
610+
err = h.WaitForNetworkInterfaceStatusChange(nwInterfaceID, ec2.AttachmentStatusDetached)
611611
if err != nil {
612612
return err
613613
}

pkg/aws/ec2/api/helper_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ var (
153153
NetworkInterfaceId: &branchInterfaceId,
154154
InterfaceType: aws.String("interface"),
155155
Attachment: &ec2.NetworkInterfaceAttachment{
156-
Status: aws.String(ec2.NetworkInterfaceStatusAvailable),
156+
Status: aws.String(ec2.AttachmentStatusDetached),
157157
},
158158
},
159159
},
@@ -941,7 +941,7 @@ func TestEc2APIHelper_DetachAndDeleteNetworkInterface(t *testing.T) {
941941

942942
oldStatus := describeNetworkInterfaceOutputUsingOneInterfaceId.NetworkInterfaces[0].Attachment.Status
943943
describeNetworkInterfaceOutputUsingOneInterfaceId.NetworkInterfaces[0].Attachment.Status =
944-
aws.String(ec2.NetworkInterfaceStatusAvailable)
944+
aws.String(ec2.AttachmentStatusDetached)
945945

946946
mockWrapper.EXPECT().DetachNetworkInterface(detachNetworkInterfaceInput).Return(nil, nil)
947947
mockWrapper.EXPECT().DescribeNetworkInterfaces(describeNetworkInterfaceInputUsingOneInterfaceId).

pkg/provider/branch/trunk/trunk.go

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -174,14 +174,18 @@ func (t *trunkENI) InitTrunk(instance ec2.EC2Instance, podList []v1.Pod) error {
174174

175175
// Get trunk network interface
176176
for _, nwInterface := range nwInterfaces {
177-
// It's possible to get an empty network interface response if the instnace
178-
// is being deleted.
177+
// It's possible to get an empty network interface response if the instance is being deleted.
179178
if nwInterface == nil || nwInterface.InterfaceType == nil {
180179
return fmt.Errorf("received an empty network interface response "+
181180
"from EC2 %+v", nwInterface)
182181
}
183182
if *nwInterface.InterfaceType == "trunk" {
184-
t.trunkENIId = *nwInterface.NetworkInterfaceId
183+
// Check that the trunkENI is in attached state before adding to cache
184+
if err = t.ec2ApiHelper.WaitForNetworkInterfaceStatusChange(nwInterface.NetworkInterfaceId, awsEC2.AttachmentStatusAttached); err == nil {
185+
t.trunkENIId = *nwInterface.NetworkInterfaceId
186+
} else {
187+
return fmt.Errorf("failed to verify network interface status attached for %v", *nwInterface.NetworkInterfaceId)
188+
}
185189
}
186190
}
187191

0 commit comments

Comments
 (0)