Skip to content

Commit 4503f75

Browse files
authored
remove self-managed node group from pod-eni test suite (#2547)
1 parent cb853a9 commit 4503f75

File tree

6 files changed

+84
-123
lines changed

6 files changed

+84
-123
lines changed

test/framework/resources/aws/utils/nodegroup.go

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import (
1818
"os"
1919
"strconv"
2020
"strings"
21+
"time"
2122

2223
"gopkg.in/yaml.v2"
2324

@@ -26,6 +27,7 @@ import (
2627

2728
"github.com/aws/amazon-vpc-cni-k8s/pkg/vpc"
2829
"github.com/aws/amazon-vpc-cni-k8s/test/framework"
30+
k8sUtils "github.com/aws/amazon-vpc-cni-k8s/test/framework/resources/k8s/utils"
2931
"github.com/aws/amazon-vpc-cni-k8s/test/framework/utils"
3032
)
3133

@@ -283,7 +285,7 @@ func GetClusterVPCConfig(f *framework.Framework) (*ClusterVPCConfig, error) {
283285
for _, subnet := range clusterConfig.PublicSubnetList {
284286
describeSubnet, err := f.CloudServices.EC2().DescribeSubnet(subnet)
285287
if err != nil {
286-
return nil, fmt.Errorf("failed to descrieb the subnet %s: %v", subnet, err)
288+
return nil, fmt.Errorf("failed to describe the subnet %s: %v", subnet, err)
287289
}
288290
if ok := uniqueAZ[*describeSubnet.Subnets[0].AvailabilityZone]; !ok {
289291
uniqueAZ[*describeSubnet.Subnets[0].AvailabilityZone] = true
@@ -294,3 +296,24 @@ func GetClusterVPCConfig(f *framework.Framework) (*ClusterVPCConfig, error) {
294296

295297
return clusterConfig, nil
296298
}
299+
300+
func TerminateInstances(f *framework.Framework, ngLabelKey string, ngLabelVal string) error {
301+
nodeList, err := f.K8sResourceManagers.NodeManager().GetNodes(ngLabelKey, ngLabelVal)
302+
if err != nil {
303+
return fmt.Errorf("failed to get list of nodes created: %v", err)
304+
}
305+
306+
var instanceIDs []string
307+
for _, node := range nodeList.Items {
308+
instanceIDs = append(instanceIDs, k8sUtils.GetInstanceIDFromNode(node))
309+
}
310+
311+
err = f.CloudServices.EC2().TerminateInstance(instanceIDs)
312+
if err != nil {
313+
return fmt.Errorf("failed to terminate instances: %v", err)
314+
}
315+
316+
// Wait for instances to be replaced
317+
time.Sleep(time.Second * 450)
318+
return nil
319+
}

test/integration/custom-networking/custom_networking_suite_test.go

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -205,22 +205,3 @@ var _ = AfterSuite(func() {
205205
}
206206
Expect(errs.MaybeUnwrap()).ToNot(HaveOccurred())
207207
})
208-
209-
func TerminateInstances(f *framework.Framework) {
210-
By("getting the list of nodes created")
211-
nodeList, err := f.K8sResourceManagers.NodeManager().
212-
GetNodes(nodeGroupProperties.NgLabelKey, nodeGroupProperties.NgLabelVal)
213-
Expect(err).ToNot(HaveOccurred())
214-
215-
var instanceIDs []string
216-
for _, node := range nodeList.Items {
217-
instanceIDs = append(instanceIDs, k8sUtils.GetInstanceIDFromNode(node))
218-
}
219-
220-
By("terminating all the nodes")
221-
err = f.CloudServices.EC2().TerminateInstance(instanceIDs)
222-
Expect(err).ToNot(HaveOccurred())
223-
224-
By("waiting for nodes to be recycled")
225-
time.Sleep(time.Second * 300)
226-
}

test/integration/custom-networking/custom_networking_test.go

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import (
1818
"net"
1919
"strconv"
2020

21+
awsUtils "github.com/aws/amazon-vpc-cni-k8s/test/framework/resources/aws/utils"
2122
"github.com/aws/amazon-vpc-cni-k8s/test/framework/resources/k8s/manifest"
2223
"github.com/aws/amazon-vpc-cni-k8s/test/framework/utils"
2324

@@ -140,7 +141,9 @@ var _ = Describe("Custom Networking Test", func() {
140141
})
141142

142143
It("deployment should not become ready", func() {
143-
TerminateInstances(f)
144+
By("terminating instances")
145+
err := awsUtils.TerminateInstances(f, nodeGroupProperties.NgLabelKey, nodeGroupProperties.NgLabelVal)
146+
Expect(err).ToNot(HaveOccurred())
144147

145148
// Nodes should be stuck in NotReady state since no ENIs could be attached and no pod
146149
// IP addresses are available.
@@ -181,7 +184,10 @@ var _ = Describe("Custom Networking Test", func() {
181184
})
182185

183186
It("deployment should become ready", func() {
184-
TerminateInstances(f)
187+
By("terminating instances")
188+
err := awsUtils.TerminateInstances(f, nodeGroupProperties.NgLabelKey, nodeGroupProperties.NgLabelVal)
189+
Expect(err).ToNot(HaveOccurred())
190+
185191
deployment := manifest.NewBusyBoxDeploymentBuilder(f.Options.TestImageRegistry).
186192
Replicas(2).
187193
NodeSelector(nodeGroupProperties.NgLabelKey, nodeGroupProperties.NgLabelVal).

test/integration/pod-eni/security_group_per_pod_suite_test.go

Lines changed: 36 additions & 87 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,7 @@
1414
package pod_eni
1515

1616
import (
17-
"net/url"
18-
"path"
17+
"fmt"
1918
"strings"
2019
"testing"
2120

@@ -24,7 +23,7 @@ import (
2423
k8sUtils "github.com/aws/amazon-vpc-cni-k8s/test/framework/resources/k8s/utils"
2524
"github.com/aws/amazon-vpc-cni-k8s/test/framework/utils"
2625
"github.com/aws/amazon-vpc-resource-controller-k8s/pkg/aws/vpc"
27-
v1 "k8s.io/api/core/v1"
26+
corev1 "k8s.io/api/core/v1"
2827

2928
. "github.com/onsi/ginkgo/v2"
3029
. "github.com/onsi/gomega"
@@ -35,26 +34,22 @@ const AmazonEKSVPCResourceControllerARN = "arn:aws:iam::aws:policy/AmazonEKSVPCR
3534
var (
3635
f *framework.Framework
3736
err error
38-
// Key pair used for creating new self managed node group
39-
keyPairName = "pod-eni-test"
4037
// Security Group that will be used to to create Security Group Policy
4138
securityGroupId string
4239
// Ports that will be opened on the Security Group used for testing
4340
openPort = 80
44-
// Size of the Auto Scaling Group used for testing Security Group For Pods
45-
asgSize = 3
46-
// Nitro Based instance type only
47-
instanceType = "c5.xlarge"
41+
// Port than metrics server listens on
42+
metricsPort = 8080
4843
// Maximum number of Branch Interface created across all the self managed nodes
4944
totalBranchInterface int
50-
// Self managed node group
51-
nodeGroupProperties awsUtils.NodeGroupProperties
5245
// Cluster Role name derived from cluster Role ARN, used to attach VPC Controller Policy
5346
clusterRoleName string
54-
// NodeSecurityGroupId for Node-Node communication
55-
nodeSecurityGroupID string
47+
// Cluster security group ID for node to node communication
48+
clusterSGID string
5649

57-
node v1.Node
50+
targetNode corev1.Node
51+
// Number of nodes in cluster
52+
numNodes int
5853
)
5954

6055
func TestSecurityGroupForPods(t *testing.T) {
@@ -65,25 +60,15 @@ func TestSecurityGroupForPods(t *testing.T) {
6560
var _ = BeforeSuite(func() {
6661
f = framework.New(framework.GlobalOptions)
6762

68-
By("creating ec2 key-pair for the new node group")
69-
_, err := f.CloudServices.EC2().CreateKey(keyPairName)
70-
Expect(err).ToNot(HaveOccurred())
71-
7263
By("creating a new security group used in Security Group Policy")
7364
securityGroupOutput, err := f.CloudServices.EC2().CreateSecurityGroup("pod-eni-automation",
7465
"test created by vpc cni automation test suite", f.Options.AWSVPCID)
7566
Expect(err).ToNot(HaveOccurred())
7667
securityGroupId = *securityGroupOutput.GroupId
7768

7869
By("authorizing egress and ingress on security group for client-server communication")
79-
f.CloudServices.EC2().
80-
AuthorizeSecurityGroupEgress(securityGroupId, "TCP", openPort, openPort, "0.0.0.0/0")
81-
f.CloudServices.EC2().
82-
AuthorizeSecurityGroupIngress(securityGroupId, "TCP", openPort, openPort, "0.0.0.0/0")
83-
84-
By("getting the cluster VPC Config")
85-
clusterVPCConfig, err := awsUtils.GetClusterVPCConfig(f)
86-
Expect(err).ToNot(HaveOccurred())
70+
f.CloudServices.EC2().AuthorizeSecurityGroupEgress(securityGroupId, "TCP", openPort, openPort, "0.0.0.0/0")
71+
f.CloudServices.EC2().AuthorizeSecurityGroupIngress(securityGroupId, "TCP", openPort, openPort, "0.0.0.0/0")
8772

8873
By("getting the cluster role name")
8974
describeClusterOutput, err := f.CloudServices.EKS().DescribeCluster(f.Options.ClusterName)
@@ -95,69 +80,38 @@ var _ = BeforeSuite(func() {
9580
AttachRolePolicy(AmazonEKSVPCResourceControllerARN, clusterRoleName)
9681
Expect(err).ToNot(HaveOccurred())
9782

98-
nodeGroupProperties = awsUtils.NodeGroupProperties{
99-
NgLabelKey: "node-type",
100-
NgLabelVal: "pod-eni-node",
101-
AsgSize: asgSize,
102-
NodeGroupName: "pod-eni-node",
103-
Subnet: clusterVPCConfig.PublicSubnetList,
104-
InstanceType: instanceType,
105-
KeyPairName: keyPairName,
106-
ContainerRuntime: f.Options.ContainerRuntime,
107-
}
108-
109-
if f.Options.InstanceType == "arm64" {
110-
// override instanceType for arm64
111-
instanceType = "m6g.large"
112-
nodeGroupProperties.InstanceType = instanceType
113-
nodeGroupProperties.NodeImageId = "ami-087fca294139386b6"
114-
}
115-
116-
totalBranchInterface = vpc.Limits[instanceType].BranchInterface * asgSize
117-
118-
By("creating a new self managed node group")
119-
err = awsUtils.CreateAndWaitTillSelfManagedNGReady(f, nodeGroupProperties)
83+
By("getting branch ENI limits")
84+
nodeList, err := f.K8sResourceManagers.NodeManager().GetNodes(f.Options.NgNameLabelKey, f.Options.NgNameLabelVal)
12085
Expect(err).ToNot(HaveOccurred())
86+
numNodes = len(nodeList.Items)
87+
Expect(numNodes).Should(BeNumerically(">", 1))
12188

122-
By("Get Reference to any node from the self managed node group")
123-
nodeList, err := f.K8sResourceManagers.NodeManager().GetNodes(nodeGroupProperties.NgLabelKey,
124-
nodeGroupProperties.NgLabelVal)
125-
Expect(err).ToNot(HaveOccurred())
126-
Expect(len(nodeList.Items)).Should(BeNumerically(">", 0))
127-
128-
// Get ref to any node from newly created nodegroup
129-
By("Getting providerID of the node")
130-
node = nodeList.Items[0]
131-
providerID := node.Spec.ProviderID
132-
Expect(len(providerID)).To(BeNumerically(">", 0))
133-
134-
By("Get InstanceID from the node")
135-
awsUrl, err := url.Parse(providerID)
136-
Expect(err).NotTo(HaveOccurred())
137-
138-
instanceID := path.Base(awsUrl.Path)
139-
Expect(len(instanceID)).To(BeNumerically(">", 0))
89+
node := nodeList.Items[0]
90+
instanceID := k8sUtils.GetInstanceIDFromNode(node)
91+
nodeInstance, err := f.CloudServices.EC2().DescribeInstance(instanceID)
92+
instanceType := *nodeInstance.InstanceType
93+
totalBranchInterface = vpc.Limits[instanceType].BranchInterface * numNodes
14094

141-
By("Fetching Node Security GroupId")
142-
instance, err := f.CloudServices.EC2().DescribeInstance(instanceID)
95+
By("Getting Cluster Security Group ID")
96+
clusterRes, err := f.CloudServices.EKS().DescribeCluster(f.Options.ClusterName)
14397
Expect(err).NotTo(HaveOccurred())
144-
145-
networkInterface := instance.NetworkInterfaces[0]
146-
securityGroups := networkInterface.Groups
147-
nodeSecurityGroupPrefix := nodeGroupProperties.NgLabelVal + "-NodeSecurityGroup"
148-
for _, group := range securityGroups {
149-
if strings.HasPrefix(*group.GroupName, nodeSecurityGroupPrefix) {
150-
nodeSecurityGroupID = *group.GroupId
151-
break
152-
}
153-
}
154-
Expect(len(nodeSecurityGroupID)).To(BeNumerically(">", 0))
98+
clusterSGID = *(clusterRes.Cluster.ResourcesVpcConfig.ClusterSecurityGroupId)
99+
fmt.Fprintf(GinkgoWriter, "cluster security group is %s\n", clusterSGID)
155100

156101
By("enabling pod eni on aws-node DaemonSet")
157102
k8sUtils.AddEnvVarToDaemonSetAndWaitTillUpdated(f, utils.AwsNodeName,
158103
utils.AwsNodeNamespace, utils.AwsNodeName, map[string]string{
159104
"ENABLE_POD_ENI": "true",
160105
})
106+
107+
By("terminating instances")
108+
err = awsUtils.TerminateInstances(f, f.Options.NgNameLabelKey, f.Options.NgNameLabelVal)
109+
Expect(err).ToNot(HaveOccurred())
110+
111+
By("getting target node")
112+
nodeList, err = f.K8sResourceManagers.NodeManager().GetNodes(f.Options.NgNameLabelKey, f.Options.NgNameLabelVal)
113+
Expect(err).ToNot(HaveOccurred())
114+
targetNode = nodeList.Items[0]
161115
})
162116

163117
var _ = AfterSuite(func() {
@@ -167,20 +121,15 @@ var _ = AfterSuite(func() {
167121
"ENABLE_POD_ENI": {},
168122
})
169123

170-
By("deleting the key-pair used to create nodegroup")
171-
err = f.CloudServices.EC2().DeleteKey(keyPairName)
172-
Expect(err).ToNot(HaveOccurred())
173-
174-
By("deleting the self managed node group")
175-
err = awsUtils.DeleteAndWaitTillSelfManagedNGStackDeleted(f, nodeGroupProperties)
124+
By("terminating instances")
125+
err := awsUtils.TerminateInstances(f, f.Options.NgNameLabelKey, f.Options.NgNameLabelVal)
176126
Expect(err).ToNot(HaveOccurred())
177127

178128
By("deleting the security group")
179129
err = f.CloudServices.EC2().DeleteSecurityGroup(securityGroupId)
180130
Expect(err).ToNot(HaveOccurred())
181131

182132
By("detaching the AmazonEKSVPCResourceController policy from the cluster role")
183-
err = f.CloudServices.IAM().
184-
DetachRolePolicy(AmazonEKSVPCResourceControllerARN, clusterRoleName)
133+
err = f.CloudServices.IAM().DetachRolePolicy(AmazonEKSVPCResourceControllerARN, clusterRoleName)
185134
Expect(err).ToNot(HaveOccurred())
186135
})

test/integration/pod-eni/security_group_per_pod_test.go

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,7 @@ var _ = Describe("Security Group for Pods Test", func() {
6161
CreateNamespace(utils.DefaultTestNamespace)
6262

6363
serverDeploymentBuilder = manifest.NewDefaultDeploymentBuilder().
64-
Name("traffic-server").
65-
NodeSelector(nodeGroupProperties.NgLabelKey, nodeGroupProperties.NgLabelVal)
64+
Name("traffic-server")
6665

6766
securityGroupPolicy, err = vpcControllerFW.NewSGPBuilder().
6867
Namespace(utils.DefaultTestNamespace).
@@ -73,8 +72,7 @@ var _ = Describe("Security Group for Pods Test", func() {
7372
Expect(err).ToNot(HaveOccurred())
7473

7574
By("creating the Security Group Policy")
76-
err = f.K8sResourceManagers.
77-
CustomResourceManager().CreateResource(securityGroupPolicy)
75+
err = f.K8sResourceManagers.CustomResourceManager().CreateResource(securityGroupPolicy)
7876
Expect(err).ToNot(HaveOccurred())
7977
})
8078

@@ -122,10 +120,11 @@ var _ = Describe("Security Group for Pods Test", func() {
122120
// Both the Server and Client Pods will get Branch ENI
123121
branchPodLabelVal = []string{serverPodLabelVal, clientPodLabelVal}
124122

125-
// Allow Ingress on NodeSecurityGroup so that client-pods can communicate with metric pod
123+
// Allow Ingress on cluster security group so client pods can communicate with metric pod
126124
// 8080: metric-pod listener port
127125
By("Adding an additional Ingress Rule on NodeSecurityGroupID to allow client-to-metric traffic")
128-
f.CloudServices.EC2().AuthorizeSecurityGroupIngress(nodeSecurityGroupID, "tcp", openPort, 8080, "0.0.0.0/0")
126+
err := f.CloudServices.EC2().AuthorizeSecurityGroupIngress(clusterSGID, "TCP", metricsPort, metricsPort, "0.0.0.0/0")
127+
Expect(err).ToNot(HaveOccurred())
129128
})
130129

131130
It("should have 99%+ success rate", func() {
@@ -152,11 +151,12 @@ var _ = Describe("Security Group for Pods Test", func() {
152151
AfterEach(func() {
153152
// Revoke the Ingress rule for traffic from client pods added to Node Security Group
154153
By("Revoking the additional Ingress rule added to allow client-to-metric traffic")
155-
f.CloudServices.EC2().RevokeSecurityGroupIngress(nodeSecurityGroupID, "tcp", openPort, 8080, "0.0.0.0/0")
154+
err := f.CloudServices.EC2().RevokeSecurityGroupIngress(clusterSGID, "TCP", metricsPort, metricsPort, "0.0.0.0/0")
155+
Expect(err).ToNot(HaveOccurred())
156156
})
157157
})
158158

159-
Context("when testing traffic to a port on Branch ENI that's not open", func() {
159+
Context("when testing traffic to a port on Branch ENI that is not open", func() {
160160
BeforeEach(func() {
161161
// Only the Server Pods will get Branch ENI
162162
branchPodLabelVal = []string{serverPodLabelVal}
@@ -226,19 +226,18 @@ var _ = Describe("Security Group for Pods Test", func() {
226226
Name("liveliness-pod").
227227
Container(container).
228228
PodLabel(labelKey, serverPodLabelVal).
229-
NodeSelector(nodeGroupProperties.NgLabelKey, nodeGroupProperties.NgLabelVal).
230229
RestartPolicy(v1.RestartPolicyAlways).
231230
Build()
232231

233-
By("creating branch ENI pod with liveliness probe")
232+
By("creating branch ENI pod with liveness probe")
234233
pod, err := f.K8sResourceManagers.PodManager().CreateAndWaitTillRunning(pod)
235234
Expect(err).ToNot(HaveOccurred())
236235

237236
ValidatePodsHaveBranchENI(v1.PodList{Items: []v1.Pod{*pod}})
238237

239238
timeAfterLivelinessProbeFails := initialDelay + (periodSecond * failureCount) + 10
240239

241-
By("waiting for the liveliness probe to succeed/fail")
240+
By("waiting for the liveness probe to succeed/fail")
242241
time.Sleep(time.Second * time.Duration(timeAfterLivelinessProbeFails))
243242

244243
By("getting the updated branch ENI pod")
@@ -279,10 +278,11 @@ var _ = Describe("Security Group for Pods Test", func() {
279278
branchPodLabelVal = []string{busyboxPodLabelVal}
280279
})
281280
It("Deploy BusyBox Pods with branch ENI and verify HostNetworking", func() {
281+
// Pin deployment to primary node
282282
deployment := manifest.NewBusyBoxDeploymentBuilder(f.Options.TestImageRegistry).
283-
Replicas(totalBranchInterface/asgSize).
283+
Replicas(totalBranchInterface/numNodes).
284284
PodLabel(labelKey, busyboxPodLabelVal).
285-
NodeName(node.Name).
285+
NodeName(targetNode.Name).
286286
Build()
287287

288288
By("creating a deployment to launch pod using Branch ENI")
@@ -350,9 +350,10 @@ func ValidateHostNetworking(testType TestType, podValidationInputString string)
350350
Args(testerArgs).
351351
Build()
352352

353+
// Pin pod to primary node
353354
testPod := manifest.NewDefaultPodBuilder().
354355
Container(testContainer).
355-
NodeName(node.Name).
356+
NodeName(targetNode.Name).
356357
HostNetwork(true).
357358
Build()
358359

0 commit comments

Comments
 (0)