Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: Fix AMI selection when performing version compat e2e #6170

Merged
merged 2 commits into from
May 9, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 12 additions & 15 deletions test/suites/drift/suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,11 +76,7 @@ var _ = Describe("Drift", func() {
var selector labels.Selector
var numPods int
BeforeEach(func() {
amdAMI = lo.Ternary(env.K8sMinorVersion() == 23,
// Pin to a specific, earlier version of the AMI since a 1.22 version doesn't exist for AL2023
env.GetAMIBySSMPath("/aws/service/eks/optimized-ami/1.23/amazon-linux-2023/x86_64/standard/amazon-eks-node-al2023-x86_64-standard-1.23-v20240213/image_id"),
env.GetAMIBySSMPath(fmt.Sprintf("/aws/service/eks/optimized-ami/%s/amazon-linux-2023/x86_64/standard/recommended/image_id", env.K8sVersionWithOffset(1))),
)
amdAMI = env.GetAMIBySSMPath(fmt.Sprintf("/aws/service/eks/optimized-ami/%s/amazon-linux-2023/x86_64/standard/recommended/image_id", env.K8sVersion()))
numPods = 1
// Add pods with a do-not-disrupt annotation so that we can check node metadata before we disrupt
dep = coretest.Deployment(coretest.DeploymentOptions{
Expand Down Expand Up @@ -375,11 +371,11 @@ var _ = Describe("Drift", func() {
})
})
It("should disrupt nodes that have drifted due to AMIs", func() {
// Choose and old, static image. The 1.23 image is incompatible with EKS 1.29 so fallback to a newer image.
oldCustomAMI := lo.Ternary(env.K8sMinorVersion() >= 29,
env.GetAMIBySSMPath("/aws/service/eks/optimized-ami/1.27/amazon-linux-2023/x86_64/standard/amazon-eks-node-al2023-x86_64-standard-1.27-v20240307/image_id"),
env.GetAMIBySSMPath("/aws/service/eks/optimized-ami/1.23/amazon-linux-2023/arm64/standard/amazon-eks-node-al2023-arm64-standard-1.23-v20240307/image_id"),
)
// Choose an old static image (AL2023 AMIs don't exist for 1.22)
oldCustomAMI := env.GetAMIBySSMPath(lo.Ternary(env.K8sMinorVersion() == 23,
"/aws/service/eks/optimized-ami/1.23/amazon-linux-2023/x86_64/standard/amazon-eks-node-al2023-x86_64-standard-1.23-v20240307/image_id",
fmt.Sprintf("/aws/service/eks/optimized-ami/%s/amazon-linux-2023/x86_64/standard/recommended/image_id", env.K8sVersionWithOffset(1)),
))
nodeClass.Spec.AMIFamily = &v1beta1.AMIFamilyAL2023
nodeClass.Spec.AMISelectorTerms = []v1beta1.AMISelectorTerm{{ID: oldCustomAMI}}

Expand All @@ -400,7 +396,7 @@ var _ = Describe("Drift", func() {
env.EventuallyExpectHealthyPodCount(selector, numPods)
})
It("should return drifted if the AMI no longer matches the existing NodeClaims instance type", func() {
armAMI := env.GetAMIBySSMPath(fmt.Sprintf("/aws/service/eks/optimized-ami/%s/amazon-linux-2023/arm64/standard/recommended/image_id", env.K8sVersionWithOffset(1)))
armAMI := env.GetAMIBySSMPath(fmt.Sprintf("/aws/service/eks/optimized-ami/%s/amazon-linux-2023/arm64/standard/recommended/image_id", env.K8sVersion()))
nodeClass.Spec.AMIFamily = &v1beta1.AMIFamilyAL2023
nodeClass.Spec.AMISelectorTerms = []v1beta1.AMISelectorTerm{{ID: armAMI}}

Expand All @@ -422,11 +418,12 @@ var _ = Describe("Drift", func() {
})
It("should not disrupt nodes that have drifted without the featureGate enabled", func() {
env.ExpectSettingsOverridden(v1.EnvVar{Name: "FEATURE_GATES", Value: "Drift=false"})

// Choose an old static image (AL2023 AMIs don't exist for 1.22)
oldCustomAMI := lo.Ternary(env.K8sMinorVersion() == 23,
env.GetAMIBySSMPath("/aws/service/eks/optimized-ami/1.23/amazon-linux-2023/arm64/standard/amazon-eks-node-al2023-arm64-standard-1.23-v20240307/image_id"),
env.GetAMIBySSMPath(fmt.Sprintf("/aws/service/eks/optimized-ami/%s/amazon-linux-2023/arm64/standard/recommended/image_id", env.K8sVersionWithOffset(1))),
)
oldCustomAMI := env.GetAMIBySSMPath(lo.Ternary(env.K8sMinorVersion() == 23,
"/aws/service/eks/optimized-ami/1.23/amazon-linux-2023/x86_64/standard/amazon-eks-node-al2023-x86_64-standard-1.23-v20240307/image_id",
fmt.Sprintf("/aws/service/eks/optimized-ami/%s/amazon-linux-2023/x86_64/standard/recommended/image_id", env.K8sVersionWithOffset(1)),
))
nodeClass.Spec.AMIFamily = &v1beta1.AMIFamilyAL2023
nodeClass.Spec.AMISelectorTerms = []v1beta1.AMISelectorTerm{{ID: oldCustomAMI}}

Expand Down
6 changes: 3 additions & 3 deletions test/suites/integration/ami_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ import (
var _ = Describe("AMI", func() {
var customAMI string
BeforeEach(func() {
customAMI = env.GetAMIBySSMPath(fmt.Sprintf("/aws/service/eks/optimized-ami/%s/amazon-linux-2023/x86_64/standard/recommended/image_id", env.K8sVersionWithOffset(1)))
customAMI = env.GetAMIBySSMPath(fmt.Sprintf("/aws/service/eks/optimized-ami/%s/amazon-linux-2023/x86_64/standard/recommended/image_id", env.K8sVersion()))
})

It("should use the AMI defined by the AMI Selector Terms", func() {
Expand All @@ -59,8 +59,8 @@ var _ = Describe("AMI", func() {
env.ExpectInstance(pod.Spec.NodeName).To(HaveField("ImageId", HaveValue(Equal(customAMI))))
})
It("should use the most recent AMI when discovering multiple", func() {
// choose an old static image
oldCustomAMI := env.GetAMIBySSMPath(fmt.Sprintf("/aws/service/eks/optimized-ami/%[1]s/amazon-linux-2023/x86_64/standard/amazon-eks-node-al2023-x86_64-standard-%[1]s-v20240307/image_id", env.K8sVersionWithOffset(1)))
// choose an old static image that will definitely have an older cration date
jonathan-innis marked this conversation as resolved.
Show resolved Hide resolved
oldCustomAMI := env.GetAMIBySSMPath(fmt.Sprintf("/aws/service/eks/optimized-ami/%[1]s/amazon-linux-2023/x86_64/standard/amazon-eks-node-al2023-x86_64-standard-%[1]s-v20240307/image_id", env.K8sVersion()))
nodeClass.Spec.AMISelectorTerms = []v1beta1.AMISelectorTerm{
{
ID: customAMI,
Expand Down
2 changes: 1 addition & 1 deletion test/suites/nodeclaim/garbage_collection_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ var _ = Describe("GarbageCollection", func() {
Expect(securityGroups).ToNot(HaveLen(0))
Expect(subnets).ToNot(HaveLen(0))

customAMI = env.GetAMIBySSMPath(fmt.Sprintf("/aws/service/eks/optimized-ami/%s/amazon-linux-2023/x86_64/standard/recommended/image_id", env.K8sVersionWithOffset(1)))
customAMI = env.GetAMIBySSMPath(fmt.Sprintf("/aws/service/eks/optimized-ami/%s/amazon-linux-2023/x86_64/standard/recommended/image_id", env.K8sVersion()))
instanceProfileName = fmt.Sprintf("KarpenterNodeInstanceProfile-%s", env.ClusterName)
roleName = fmt.Sprintf("KarpenterNodeRole-%s", env.ClusterName)
instanceInput = &ec2.RunInstancesInput{
Expand Down
Loading