Skip to content

Commit

Permalink
ci: move tests out from integration suite
Browse files Browse the repository at this point in the history
  • Loading branch information
jigisha620 committed Jun 11, 2024
1 parent 652af0c commit 531d7e0
Show file tree
Hide file tree
Showing 9 changed files with 120 additions and 36 deletions.
6 changes: 6 additions & 0 deletions .github/workflows/e2e-matrix.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,12 @@ jobs:
suite:
- name: Integration
region: ${{ inputs.region }}
- name: AMI
region: ${{ inputs.region }}
- name: Scheduling
region: ${{ inputs.region }}
- name: Storage
region: ${{ inputs.region }}
- name: NodeClaim
region: ${{ inputs.region }}
- name: Consolidation
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,26 @@ See the License for the specific language governing permissions and
limitations under the License.
*/

package integration_test
package ami_test

import (
"testing"

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

corev1beta1 "sigs.k8s.io/karpenter/pkg/apis/v1beta1"

"encoding/base64"
"fmt"
"os"
"strings"
"time"

"github.com/aws/aws-sdk-go/aws"
"github.com/aws/karpenter-provider-aws/pkg/apis/v1beta1"

. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"

"github.com/aws/aws-sdk-go/service/ec2"
"github.com/awslabs/operatorpkg/status"
. "github.com/awslabs/operatorpkg/test/expectations"
Expand All @@ -32,16 +42,33 @@ import (
"k8s.io/apimachinery/pkg/types"
"sigs.k8s.io/controller-runtime/pkg/client"

environmentaws "github.com/aws/karpenter-provider-aws/test/pkg/environment/aws"

coretest "sigs.k8s.io/karpenter/pkg/test"
)

corev1beta1 "sigs.k8s.io/karpenter/pkg/apis/v1beta1"
var env *environmentaws.Environment
var nodeClass *v1beta1.EC2NodeClass
var nodePool *corev1beta1.NodePool

"github.com/aws/karpenter-provider-aws/pkg/apis/v1beta1"
awsenv "github.com/aws/karpenter-provider-aws/test/pkg/environment/aws"
func TestAMI(t *testing.T) {
RegisterFailHandler(Fail)
BeforeSuite(func() {
env = environmentaws.NewEnvironment(t)
})
AfterSuite(func() {
env.Stop()
})
RunSpecs(t, "Ami")
}

. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
)
var _ = BeforeEach(func() {
env.BeforeEach()
nodeClass = env.DefaultEC2NodeClass()
nodePool = env.DefaultNodePool(nodeClass)
})
var _ = AfterEach(func() { env.Cleanup() })
var _ = AfterEach(func() { env.AfterEach() })

var _ = Describe("AMI", func() {
var customAMI string
Expand Down Expand Up @@ -83,7 +110,7 @@ var _ = Describe("AMI", func() {
})
It("should support AMI Selector Terms for Name but fail with incorrect owners", func() {
output, err := env.EC2API.DescribeImages(&ec2.DescribeImagesInput{
ImageIds: []*string{aws.String(customAMI)},
ImageIds: []*string{awssdk.String(customAMI)},
})
Expect(err).To(BeNil())
Expect(output.Images).To(HaveLen(1))
Expand All @@ -101,7 +128,7 @@ var _ = Describe("AMI", func() {
})
It("should support ami selector Name with default owners", func() {
output, err := env.EC2API.DescribeImages(&ec2.DescribeImagesInput{
ImageIds: []*string{aws.String(customAMI)},
ImageIds: []*string{awssdk.String(customAMI)},
})
Expect(err).To(BeNil())
Expect(output.Images).To(HaveLen(1))
Expand Down Expand Up @@ -174,7 +201,7 @@ var _ = Describe("AMI", func() {
NodeSelectorRequirement: v1.NodeSelectorRequirement{
Key: v1beta1.LabelInstanceFamily,
Operator: v1.NodeSelectorOpNotIn,
Values: awsenv.ExcludedInstanceFamilies,
Values: environmentaws.ExcludedInstanceFamilies,
},
},
)
Expand Down Expand Up @@ -241,7 +268,7 @@ var _ = Describe("AMI", func() {
content, err := os.ReadFile("testdata/al2_userdata_input.sh")
Expect(err).ToNot(HaveOccurred())
nodeClass.Spec.AMIFamily = &v1beta1.AMIFamilyAL2
nodeClass.Spec.UserData = aws.String(string(content))
nodeClass.Spec.UserData = awssdk.String(string(content))
nodePool.Spec.Template.Spec.Taints = []v1.Taint{{Key: "example.com", Value: "value", Effect: "NoExecute"}}
nodePool.Spec.Template.Spec.StartupTaints = []v1.Taint{{Key: "example.com", Value: "value", Effect: "NoSchedule"}}
pod := coretest.Pod(coretest.PodOptions{Tolerations: []v1.Toleration{{Key: "example.com", Operator: v1.TolerationOpExists}}})
Expand All @@ -262,7 +289,7 @@ var _ = Describe("AMI", func() {
content, err := os.ReadFile("testdata/al2_no_mime_userdata_input.sh")
Expect(err).ToNot(HaveOccurred())
nodeClass.Spec.AMIFamily = &v1beta1.AMIFamilyAL2
nodeClass.Spec.UserData = aws.String(string(content))
nodeClass.Spec.UserData = awssdk.String(string(content))
nodePool.Spec.Template.Spec.Taints = []v1.Taint{{Key: "example.com", Value: "value", Effect: "NoExecute"}}
nodePool.Spec.Template.Spec.StartupTaints = []v1.Taint{{Key: "example.com", Value: "value", Effect: "NoSchedule"}}
pod := coretest.Pod(coretest.PodOptions{Tolerations: []v1.Toleration{{Key: "example.com", Operator: v1.TolerationOpExists}}})
Expand All @@ -283,7 +310,7 @@ var _ = Describe("AMI", func() {
content, err := os.ReadFile("testdata/br_userdata_input.sh")
Expect(err).ToNot(HaveOccurred())
nodeClass.Spec.AMIFamily = &v1beta1.AMIFamilyBottlerocket
nodeClass.Spec.UserData = aws.String(string(content))
nodeClass.Spec.UserData = awssdk.String(string(content))
nodePool.Spec.Template.Spec.Taints = []v1.Taint{{Key: "example.com", Value: "value", Effect: "NoExecute"}}
nodePool.Spec.Template.Spec.StartupTaints = []v1.Taint{{Key: "example.com", Value: "value", Effect: "NoSchedule"}}
pod := coretest.Pod(coretest.PodOptions{Tolerations: []v1.Toleration{{Key: "example.com", Operator: v1.TolerationOpExists}}})
Expand All @@ -307,7 +334,7 @@ var _ = Describe("AMI", func() {
content, err := os.ReadFile("testdata/windows_userdata_input.ps1")
Expect(err).ToNot(HaveOccurred())
nodeClass.Spec.AMIFamily = &v1beta1.AMIFamilyWindows2022
nodeClass.Spec.UserData = aws.String(string(content))
nodeClass.Spec.UserData = awssdk.String(string(content))
nodePool.Spec.Template.Spec.Taints = []v1.Taint{{Key: "example.com", Value: "value", Effect: "NoExecute"}}
nodePool.Spec.Template.Spec.StartupTaints = []v1.Taint{{Key: "example.com", Value: "value", Effect: "NoSchedule"}}

Expand All @@ -317,7 +344,7 @@ var _ = Describe("AMI", func() {
NodeSelectorRequirement: v1.NodeSelectorRequirement{
Key: v1beta1.LabelInstanceFamily,
Operator: v1.NodeSelectorOpNotIn,
Values: awsenv.ExcludedInstanceFamilies,
Values: environmentaws.ExcludedInstanceFamilies,
},
},
corev1beta1.NodeSelectorRequirementWithMinValues{
Expand All @@ -329,7 +356,7 @@ var _ = Describe("AMI", func() {
},
)
pod := coretest.Pod(coretest.PodOptions{
Image: awsenv.WindowsDefaultImage,
Image: environmentaws.WindowsDefaultImage,
NodeSelector: map[string]string{
v1.LabelOSStable: string(v1.Windows),
v1.LabelWindowsBuild: "10.0.20348",
Expand Down Expand Up @@ -358,8 +385,8 @@ func getInstanceAttribute(nodeName string, attribute string) *ec2.DescribeInstan
providerIDSplit := strings.Split(node.Spec.ProviderID, "/")
instanceID := providerIDSplit[len(providerIDSplit)-1]
instanceAttribute, err := env.EC2API.DescribeInstanceAttribute(&ec2.DescribeInstanceAttributeInput{
InstanceId: aws.String(instanceID),
Attribute: aws.String(attribute),
InstanceId: awssdk.String(instanceID),
Attribute: awssdk.String(attribute),
})
Expect(err).ToNot(HaveOccurred())
return instanceAttribute
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,11 @@ See the License for the specific language governing permissions and
limitations under the License.
*/

package integration_test
package scheduling_test

import (
"fmt"
"testing"
"time"

"github.com/samber/lo"
Expand All @@ -30,12 +31,34 @@ import (

"github.com/aws/karpenter-provider-aws/pkg/apis/v1beta1"
"github.com/aws/karpenter-provider-aws/test/pkg/debug"
"github.com/aws/karpenter-provider-aws/test/pkg/environment/aws"
environmentaws "github.com/aws/karpenter-provider-aws/test/pkg/environment/aws"

. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
)

var env *environmentaws.Environment
var nodeClass *v1beta1.EC2NodeClass
var nodePool *corev1beta1.NodePool

func TestScheduling(t *testing.T) {
RegisterFailHandler(Fail)
BeforeSuite(func() {
env = environmentaws.NewEnvironment(t)
})
AfterSuite(func() {
env.Stop()
})
RunSpecs(t, "Scheduling")
}

var _ = BeforeEach(func() {
env.BeforeEach()
nodeClass = env.DefaultEC2NodeClass()
nodePool = env.DefaultNodePool(nodeClass)
})
var _ = AfterEach(func() { env.Cleanup() })
var _ = AfterEach(func() { env.AfterEach() })
var _ = Describe("Scheduling", Ordered, ContinueOnFailure, func() {
var selectors sets.Set[string]

Expand Down Expand Up @@ -271,7 +294,7 @@ var _ = Describe("Scheduling", Ordered, ContinueOnFailure, func() {
NodeSelector: nodeSelector,
NodePreferences: requirements,
NodeRequirements: requirements,
Image: aws.WindowsDefaultImage,
Image: environmentaws.WindowsDefaultImage,
}})
nodeClass.Spec.AMIFamily = &v1beta1.AMIFamilyWindows2022
// TODO: remove this requirement once VPC RC rolls out m7a.*, r7a.* ENI data (https://github.com/aws/karpenter-provider-aws/issues/4472)
Expand All @@ -280,7 +303,7 @@ var _ = Describe("Scheduling", Ordered, ContinueOnFailure, func() {
NodeSelectorRequirement: v1.NodeSelectorRequirement{
Key: v1beta1.LabelInstanceFamily,
Operator: v1.NodeSelectorOpNotIn,
Values: aws.ExcludedInstanceFamilies,
Values: environmentaws.ExcludedInstanceFamilies,
},
},
corev1beta1.NodeSelectorRequirementWithMinValues{
Expand Down Expand Up @@ -597,7 +620,7 @@ var _ = Describe("Scheduling", Ordered, ContinueOnFailure, func() {
})

It("should provision a node for a pod with overlapping zone and zone-id requirements", func() {
subnetInfo := lo.UniqBy(env.GetSubnetInfo(map[string]string{"karpenter.sh/discovery": env.ClusterName}), func(s aws.SubnetInfo) string {
subnetInfo := lo.UniqBy(env.GetSubnetInfo(map[string]string{"karpenter.sh/discovery": env.ClusterName}), func(s environmentaws.SubnetInfo) string {
return s.Zone
})
Expect(len(subnetInfo)).To(BeNumerically(">=", 3))
Expand All @@ -609,12 +632,12 @@ var _ = Describe("Scheduling", Ordered, ContinueOnFailure, func() {
{
Key: v1.LabelTopologyZone,
Operator: v1.NodeSelectorOpIn,
Values: lo.Map(subnetInfo[0:2], func(info aws.SubnetInfo, _ int) string { return info.Zone }),
Values: lo.Map(subnetInfo[0:2], func(info environmentaws.SubnetInfo, _ int) string { return info.Zone }),
},
{
Key: v1beta1.LabelTopologyZoneID,
Operator: v1.NodeSelectorOpIn,
Values: lo.Map(subnetInfo[1:3], func(info aws.SubnetInfo, _ int) string { return info.ZoneID }),
Values: lo.Map(subnetInfo[1:3], func(info environmentaws.SubnetInfo, _ int) string { return info.ZoneID }),
},
},
})
Expand All @@ -637,10 +660,10 @@ var _ = Describe("Scheduling", Ordered, ContinueOnFailure, func() {
},
})

subnetInfo := lo.UniqBy(env.GetSubnetInfo(map[string]string{"karpenter.sh/discovery": env.ClusterName}), func(s aws.SubnetInfo) string {
subnetInfo := lo.UniqBy(env.GetSubnetInfo(map[string]string{"karpenter.sh/discovery": env.ClusterName}), func(s environmentaws.SubnetInfo) string {
return s.Zone
})
pods := lo.Map(subnetInfo, func(info aws.SubnetInfo, _ int) *v1.Pod {
pods := lo.Map(subnetInfo, func(info environmentaws.SubnetInfo, _ int) *v1.Pod {
return test.Pod(test.PodOptions{
NodeRequirements: []v1.NodeSelectorRequirement{
{
Expand All @@ -666,7 +689,7 @@ var _ = Describe("Scheduling", Ordered, ContinueOnFailure, func() {
expectedZone, ok := node.Labels[expectedZoneLabel]
Expect(ok).To(BeTrue())
Expect(node.Labels[v1.LabelTopologyZone]).To(Equal(expectedZone))
zoneInfo, ok := lo.Find(subnetInfo, func(info aws.SubnetInfo) bool {
zoneInfo, ok := lo.Find(subnetInfo, func(info environmentaws.SubnetInfo) bool {
return info.Zone == expectedZone
})
Expect(ok).To(BeTrue())
Expand All @@ -678,7 +701,7 @@ var _ = Describe("Scheduling", Ordered, ContinueOnFailure, func() {

func ephemeralInitContainer(requirements v1.ResourceRequirements) v1.Container {
return v1.Container{
Image: aws.EphemeralInitContainerImage,
Image: environmentaws.EphemeralInitContainerImage,
Command: []string{"/bin/sh"},
Args: []string{"-c", "sleep 5"},
Resources: requirements,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,30 +12,58 @@ See the License for the specific language governing permissions and
limitations under the License.
*/

package integration_test
package storage_test

import (
"fmt"
"strings"
"testing"

awssdk "github.com/aws/aws-sdk-go/aws"
corev1beta1 "sigs.k8s.io/karpenter/pkg/apis/v1beta1"

"github.com/aws/karpenter-provider-aws/pkg/apis/v1beta1"
environmentaws "github.com/aws/karpenter-provider-aws/test/pkg/environment/aws"

. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"

appsv1 "k8s.io/api/apps/v1"
v1 "k8s.io/api/core/v1"
storagev1 "k8s.io/api/storage/v1"
"k8s.io/apimachinery/pkg/api/resource"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"

"github.com/aws/aws-sdk-go/aws"
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
"github.com/samber/lo"

"github.com/aws/karpenter-provider-aws/pkg/apis/v1beta1"
"github.com/aws/karpenter-provider-aws/pkg/errors"

"sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/karpenter/pkg/test"
)

var env *environmentaws.Environment
var nodeClass *v1beta1.EC2NodeClass
var nodePool *corev1beta1.NodePool

func TestStorage(t *testing.T) {
RegisterFailHandler(Fail)
BeforeSuite(func() {
env = environmentaws.NewEnvironment(t)
})
AfterSuite(func() {
env.Stop()
})
RunSpecs(t, "Storage")
}

var _ = BeforeEach(func() {
env.BeforeEach()
nodeClass = env.DefaultEC2NodeClass()
nodePool = env.DefaultNodePool(nodeClass)
})
var _ = AfterEach(func() { env.Cleanup() })
var _ = AfterEach(func() { env.AfterEach() })
var _ = Describe("Persistent Volumes", func() {
Context("Static", func() {
It("should run a pod with a pre-bound persistent volume (empty storage class)", func() {
Expand Down Expand Up @@ -127,7 +155,7 @@ var _ = Describe("Persistent Volumes", func() {
ObjectMeta: metav1.ObjectMeta{
Name: "test-storage-class",
},
Provisioner: aws.String("ebs.csi.aws.com"),
Provisioner: awssdk.String("ebs.csi.aws.com"),
VolumeBindingMode: lo.ToPtr(storagev1.VolumeBindingWaitForFirstConsumer),
})
})
Expand Down

0 comments on commit 531d7e0

Please sign in to comment.