Skip to content

Commit

Permalink
e2e test
Browse files Browse the repository at this point in the history
  • Loading branch information
jmdeal committed Jan 5, 2024
1 parent 3383e8f commit 27ec8eb
Show file tree
Hide file tree
Showing 2 changed files with 112 additions and 0 deletions.
8 changes: 8 additions & 0 deletions test/pkg/environment/aws/expectations.go
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,14 @@ func (env *Environment) GetSpotInstanceRequest(id *string) *ec2.SpotInstanceRequ
return siro.SpotInstanceRequests[0]
}

// GetZones returns all available zones mapped from zone -> zone type
func (env *Environment) GetZones() map[string]string {
output := lo.Must(env.EC2API.DescribeAvailabilityZones(&ec2.DescribeAvailabilityZonesInput{}))
return lo.Associate(output.AvailabilityZones, func(zone *ec2.AvailabilityZone) (string, string) {
return lo.FromPtr(zone.ZoneName), lo.FromPtr(zone.ZoneType)
})
}

// GetSubnets returns all subnets matching the label selector
// mapped from AZ -> {subnet-ids...}
func (env *Environment) GetSubnets(tags map[string]string) map[string][]string {
Expand Down
104 changes: 104 additions & 0 deletions test/suites/localzone/suite_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
/*
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package localzone_test

import (
"testing"

"github.com/samber/lo"
v1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/api/resource"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/labels"

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

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

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

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

func TestLocalZone(t *testing.T) {
RegisterFailHandler(Fail)
BeforeSuite(func() {
env = aws.NewEnvironment(t)
})
AfterSuite(func() {
env.Stop()
})
RunSpecs(t, "LocalZone")
}

var _ = BeforeEach(func() {
env.BeforeEach()
nodeClass = env.DefaultEC2NodeClass()
// The majority of local zones do not support GP3. Feature support in local zones can be tracked here:
// https://aws.amazon.com/about-aws/global-infrastructure/localzones/features/
nodeClass.Spec.BlockDeviceMappings = append(nodeClass.Spec.BlockDeviceMappings, &v1beta1.BlockDeviceMapping{
DeviceName: lo.ToPtr("/dev/xvda"),
EBS: &v1beta1.BlockDevice{
VolumeSize: func() *resource.Quantity {
quantity, err := resource.ParseQuantity("80Gi")
Expect(err).To(BeNil())
return &quantity
}(),
VolumeType: lo.ToPtr("gp2"),
Encrypted: lo.ToPtr(false),
},
})
nodePool = env.DefaultNodePool(nodeClass)
nodePool.Spec.Template.Spec.Requirements = append(nodePool.Spec.Template.Spec.Requirements, v1.NodeSelectorRequirement{
Key: v1.LabelTopologyZone,
Operator: v1.NodeSelectorOpIn,
Values: lo.Keys(lo.PickByValues(env.GetZones(), []string{"local-zone"})),
})
})
var _ = AfterEach(func() { env.Cleanup() })
var _ = AfterEach(func() { env.AfterEach() })

var _ = Describe("LocalZone", func() {
It("should successfully scale up nodes in a local zone", func() {
nodeCount := 3
depLabels := map[string]string{
"foo": "bar",
}
dep := test.Deployment(test.DeploymentOptions{
PodOptions: test.PodOptions{
ObjectMeta: metav1.ObjectMeta{
Labels: depLabels,
},
TopologySpreadConstraints: []v1.TopologySpreadConstraint{{
TopologyKey: v1.LabelHostname,
MaxSkew: 1,
WhenUnsatisfiable: v1.DoNotSchedule,
LabelSelector: &metav1.LabelSelector{
MatchLabels: depLabels,
},
}},
},
Replicas: int32(nodeCount),
})
env.ExpectCreated(nodeClass, nodePool, dep)
env.EventuallyExpectHealthyPodCount(labels.SelectorFromSet(depLabels), nodeCount)
env.EventuallyExpectNodeCount("==", nodeCount)
})
})

0 comments on commit 27ec8eb

Please sign in to comment.