Skip to content

Commit 3f45f21

Browse files
ryan-mistSarthug99
authored andcommitted
helper function
1 parent 58eb28c commit 3f45f21

4 files changed

Lines changed: 14 additions & 18 deletions

File tree

test/pkg/environment/aws/expectations.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,14 @@ func (env *Environment) GetNetworkInterfaces(ids ...string) []ec2types.NetworkIn
218218
return dnio.NetworkInterfaces
219219
}
220220

221+
func FindNetworkInterface(interfaces []ec2types.InstanceNetworkInterface, networkCardIndex, deviceIndex int32) (ec2types.InstanceNetworkInterface, bool) {
222+
return lo.Find(interfaces, func(ni ec2types.InstanceNetworkInterface) bool {
223+
return ni.Attachment != nil &&
224+
ni.Attachment.NetworkCardIndex != nil && aws.ToInt32(ni.Attachment.NetworkCardIndex) == networkCardIndex &&
225+
ni.Attachment.DeviceIndex != nil && aws.ToInt32(ni.Attachment.DeviceIndex) == deviceIndex
226+
})
227+
}
228+
221229
func (env *Environment) GetSpotInstance(id string) ec2types.SpotInstanceRequest {
222230
GinkgoHelper()
223231
siro, err := env.EC2API.DescribeSpotInstanceRequests(env.Context, &ec2.DescribeSpotInstanceRequestsInput{

test/suites/integration/connection_tracking_test.go

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ import (
2626
"sigs.k8s.io/karpenter/pkg/test"
2727

2828
v1 "github.com/aws/karpenter-provider-aws/pkg/apis/v1"
29+
environmentaws "github.com/aws/karpenter-provider-aws/test/pkg/environment/aws"
2930

3031
. "github.com/onsi/ginkgo/v2"
3132
. "github.com/onsi/gomega"
@@ -47,9 +48,7 @@ var _ = Describe("ConnectionTracking", func() {
4748
instance := env.GetInstance(pod.Spec.NodeName)
4849
Expect(instance.NetworkInterfaces).ToNot(BeEmpty())
4950

50-
primaryNI, found := lo.Find(instance.NetworkInterfaces, func(ni ec2types.InstanceNetworkInterface) bool {
51-
return ni.Attachment != nil && ni.Attachment.DeviceIndex != nil && aws.ToInt32(ni.Attachment.DeviceIndex) == 0
52-
})
51+
primaryNI, found := environmentaws.FindNetworkInterface(instance.NetworkInterfaces, 0, 0)
5352
Expect(found).To(BeTrue())
5453

5554
niOutput, err := env.EC2API.DescribeNetworkInterfaces(env.Context, &ec2.DescribeNetworkInterfacesInput{
@@ -144,9 +143,7 @@ var _ = Describe("ConnectionTracking", func() {
144143
instance := env.GetInstance(pod.Spec.NodeName)
145144
Expect(instance.NetworkInterfaces).ToNot(BeEmpty())
146145

147-
primaryNI, found := lo.Find(instance.NetworkInterfaces, func(ni ec2types.InstanceNetworkInterface) bool {
148-
return ni.Attachment != nil && ni.Attachment.DeviceIndex != nil && aws.ToInt32(ni.Attachment.DeviceIndex) == 0
149-
})
146+
primaryNI, found := environmentaws.FindNetworkInterface(instance.NetworkInterfaces, 0, 0)
150147
Expect(found).To(BeTrue())
151148
niOutput, err := env.EC2API.DescribeNetworkInterfaces(env.Context, &ec2.DescribeNetworkInterfacesInput{
152149
NetworkInterfaceIds: []string{aws.ToString(primaryNI.NetworkInterfaceId)},
@@ -168,9 +165,7 @@ var _ = Describe("ConnectionTracking", func() {
168165
instance := env.GetInstance(pod.Spec.NodeName)
169166
Expect(instance.NetworkInterfaces).ToNot(BeEmpty())
170167

171-
primaryNI, found := lo.Find(instance.NetworkInterfaces, func(ni ec2types.InstanceNetworkInterface) bool {
172-
return ni.Attachment != nil && ni.Attachment.DeviceIndex != nil && aws.ToInt32(ni.Attachment.DeviceIndex) == 0
173-
})
168+
primaryNI, found := environmentaws.FindNetworkInterface(instance.NetworkInterfaces, 0, 0)
174169
Expect(found).To(BeTrue())
175170
niOutput, err := env.EC2API.DescribeNetworkInterfaces(env.Context, &ec2.DescribeNetworkInterfacesInput{
176171
NetworkInterfaceIds: []string{aws.ToString(primaryNI.NetworkInterfaceId)},

test/suites/ipv6/suite_test.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -102,9 +102,7 @@ var _ = Describe("IPv6", func() {
102102
node := env.GetNode(pod.Spec.NodeName)
103103
instance := env.GetInstanceByID(env.ExpectParsedProviderID(node.Spec.ProviderID))
104104
Expect(instance.NetworkInterfaces).ToNot(BeEmpty())
105-
primaryNI, found := lo.Find(instance.NetworkInterfaces, func(ni types.InstanceNetworkInterface) bool {
106-
return ni.Attachment != nil && ni.Attachment.DeviceIndex != nil && lo.FromPtr(ni.Attachment.DeviceIndex) == int32(0)
107-
})
105+
primaryNI, found := aws.FindNetworkInterface(instance.NetworkInterfaces, 0, 0)
108106
Expect(found).To(BeTrue())
109107
Expect(primaryNI.Ipv6Addresses).To(HaveLen(1))
110108
_, hasIPv6Primary := lo.Find(primaryNI.Ipv6Addresses, func(ip types.InstanceIpv6Address) bool {

test/suites/scheduling/suite_test.go

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1056,12 +1056,7 @@ var _ = DescribeTableSubtree("Scheduling", Ordered, ContinueOnFailure, func(minV
10561056
Expect(len(networkInterfaces)).To(BeNumerically(">=", 2))
10571057

10581058
for _, deviceIndex := range []int32{0, 1} {
1059-
networkInterface, found := lo.Find(networkInterfaces, func(i ec2types.InstanceNetworkInterface) bool {
1060-
if i.Attachment == nil || i.Attachment.DeviceIndex == nil {
1061-
return false
1062-
}
1063-
return deviceIndex == lo.FromPtr(i.Attachment.DeviceIndex)
1064-
})
1059+
networkInterface, found := environmentaws.FindNetworkInterface(networkInterfaces, 0, deviceIndex)
10651060
Expect(found).To(BeTrue())
10661061
Expect(lo.FromPtr(networkInterface.InterfaceType)).To(Equal(
10671062
lo.Ternary(deviceIndex == 0, string(ec2types.NetworkInterfaceTypeInterface), string(ec2types.NetworkInterfaceTypeEfaOnly)),

0 commit comments

Comments
 (0)