Skip to content

Commit

Permalink
add more scheduling unit tests
Browse files Browse the repository at this point in the history
- ensures that all instance types passed to the cloud provider meet
  the required constraints
- verify prov/pod constraints on OS
- verify prov/pod constraints on zone/capacity type
- verify mixed prov/pod constraints
  • Loading branch information
tzneal committed Mar 24, 2022
1 parent 81d523b commit b823dce
Show file tree
Hide file tree
Showing 4 changed files with 492 additions and 146 deletions.
37 changes: 37 additions & 0 deletions pkg/cloudprovider/fake/instancetype.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ package fake

import (
"fmt"
"strings"

"github.com/aws/karpenter/pkg/apis/provisioning/v1alpha5"

"github.com/aws/karpenter/pkg/cloudprovider/aws/apis/v1alpha1"

Expand Down Expand Up @@ -65,6 +68,40 @@ func NewInstanceType(options InstanceTypeOptions) *InstanceType {
}
}

// InstanceTypesAssorted create 1000+ unique instance types with varying CPU/memory/architecture/OS/zone/capacity type.
func InstanceTypesAssorted() []cloudprovider.InstanceType {
var instanceTypes []cloudprovider.InstanceType
for _, cpu := range []int{1, 2, 4, 8, 16, 32, 64} {
for _, mem := range []int{1, 2, 4, 8, 16, 32, 64, 128} {
for _, zone := range []string{"test-zone-1", "test-zone-2"} {
for _, ct := range []string{v1alpha1.CapacityTypeSpot, v1alpha1.CapacityTypeOnDemand} {
for _, os := range []sets.String{sets.NewString("darwin"), sets.NewString("linux"), sets.NewString("windows")} {
for _, arch := range []string{v1alpha5.ArchitectureAmd64, v1alpha5.ArchitectureArm64} {
it := NewInstanceType(InstanceTypeOptions{
Name: fmt.Sprintf("%d-cpu-%d-mem-%s-%s-%s-%s", cpu, mem, arch, strings.Join(os.List(), ","), zone, ct),
Architecture: arch,
OperatingSystems: os,
Resources: v1.ResourceList{
v1.ResourceCPU: resource.MustParse(fmt.Sprintf("%d", cpu)),
v1.ResourceMemory: resource.MustParse(fmt.Sprintf("%dGi", mem)),
},
Offerings: []cloudprovider.Offering{
{
CapacityType: ct,
Zone: zone,
},
},
})
instanceTypes = append(instanceTypes, it)
}
}
}
}
}
}
return instanceTypes
}

// InstanceTypes creates instance types with incrementing resources
// 2Gi of RAM and 10 pods for every 1vcpu
// i.e. 1vcpu, 2Gi mem, 10 pods
Expand Down
Loading

0 comments on commit b823dce

Please sign in to comment.