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

feat: add instance-hypervisor as an AWS node label #1948

Merged
merged 2 commits into from
Jun 16, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ codegen: ## Generate code. Must be run if changes are made to ./pkg/apis/...

docgen: ## Generate docs
go run hack/docs/metrics_gen_docs.go pkg/ website/content/en/preview/tasks/metrics.md
go run hack/docs/instancetypes_gen_docs.go ${KARPENTER_SUBNET_SELECTOR} website/content/en/preview/AWS/instance-types.md
go run hack/docs/instancetypes_gen_docs.go website/content/en/preview/AWS/instance-types.md

release: ## Generate release manifests and publish a versioned container image.
$(WITH_GOFLAGS) ./hack/release.sh
Expand Down
18 changes: 10 additions & 8 deletions hack/docs/instancetypes_gen_docs.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@ import (
"encoding/json"
"flag"
"fmt"
"log"
"os"
"sort"
"strings"

"github.com/aws/karpenter/pkg/apis/provisioning/v1alpha5"
"github.com/aws/karpenter/pkg/cloudprovider"
"github.com/aws/karpenter/pkg/cloudprovider/aws"
Expand All @@ -15,28 +20,25 @@ import (
v1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/api/resource"
"k8s.io/apimachinery/pkg/util/sets"
"log"
"os"
"sort"
"strings"
)

func main() {
flag.Parse()
if flag.NArg() != 2 {
log.Printf("Usage: %s subnet-discovery-tag-value path/to/markdown.md", os.Args[0])
if flag.NArg() != 1 {
log.Printf("Usage: %s path/to/markdown.md", os.Args[0])
os.Exit(1)
}

os.Setenv("AWS_SDK_LOAD_CONFIG", "true")
os.Setenv("AWS_REGION", "us-east-1")
ctx := context.Background()

cp := aws.NewCloudProvider(ctx, cloudprovider.Options{
ClientSet: nil,
KubeClient: nil,
})
provider := v1alpha1.AWS{SubnetSelector: map[string]string{
"karpenter.sh/discovery": flag.Arg(0),
"*": "*",
}}
var buf bytes.Buffer
enc := json.NewEncoder(&buf)
Expand All @@ -51,7 +53,7 @@ func main() {
log.Fatalf("listing instance types, %s", err)
}

outputFileName := flag.Arg(1)
outputFileName := flag.Arg(0)
f, err := os.Create(outputFileName)
if err != nil {
log.Fatalf("error creating output file %s, %s", outputFileName, err)
Expand Down
2 changes: 2 additions & 0 deletions pkg/cloudprovider/aws/apis/v1alpha1/register.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ var (
ResourceAWSNeuron v1.ResourceName = "aws.amazon.com/neuron"
ResourceAWSPodENI v1.ResourceName = "vpc.amazonaws.com/pod-eni"

LabelInstanceHypervisor = LabelDomain + "/instance-hypervisor"
LabelInstanceFamily = LabelDomain + "/instance-family"
LabelInstanceSize = LabelDomain + "/instance-size"
LabelInstanceCPU = LabelDomain + "/instance-cpu"
Expand Down Expand Up @@ -86,6 +87,7 @@ func init() {
Scheme.AddKnownTypes(schema.GroupVersion{Group: v1alpha5.ExtensionsGroup, Version: "v1alpha1"}, &AWS{})
v1alpha5.RestrictedLabelDomains = v1alpha5.RestrictedLabelDomains.Insert(RestrictedLabelDomains...)
v1alpha5.WellKnownLabels = v1alpha5.WellKnownLabels.Insert(
LabelInstanceHypervisor,
LabelInstanceFamily,
LabelInstanceSize,
LabelInstanceCPU,
Expand Down
2 changes: 1 addition & 1 deletion pkg/cloudprovider/aws/fake/ec2api.go
Original file line number Diff line number Diff line change
Expand Up @@ -353,7 +353,7 @@ func (e *EC2API) DescribeInstanceTypesPagesWithContext(_ context.Context, _ *ec2
SupportedVirtualizationTypes: []*string{aws.String("hvm")},
BurstablePerformanceSupported: aws.Bool(false),
BareMetal: aws.Bool(false),
Hypervisor: aws.String("nitro"),
Hypervisor: aws.String("xen"),
ProcessorInfo: &ec2.ProcessorInfo{
SupportedArchitectures: aws.StringSlice([]string{"x86_64"}),
},
Expand Down
1 change: 1 addition & 0 deletions pkg/cloudprovider/aws/instancetype.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ func (i *InstanceType) computeRequirements() scheduling.Requirements {
v1alpha1.LabelInstanceGPUManufacturer: sets.NewSet(),
v1alpha1.LabelInstanceGPUCount: sets.NewSet(),
v1alpha1.LabelInstanceGPUMemory: sets.NewSet(),
v1alpha1.LabelInstanceHypervisor: sets.NewSet(aws.StringValue(i.Hypervisor)),
}
// Instance Type Labels
instanceTypeParts := strings.Split(aws.StringValue(i.InstanceType), ".")
Expand Down
2 changes: 2 additions & 0 deletions pkg/cloudprovider/aws/suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,7 @@ var _ = Describe("Allocation", func() {
ExpectApplied(ctx, env.Client, provisioner)
var pods []*v1.Pod
for key, value := range map[string]string{
v1alpha1.LabelInstanceHypervisor: "xen",
v1alpha1.LabelInstanceFamily: "p3",
v1alpha1.LabelInstanceSize: "xlarge",
v1alpha1.LabelInstanceCPU: "32",
Expand Down Expand Up @@ -1384,6 +1385,7 @@ var _ = Describe("Allocation", func() {
})
It("should support well known labels", func() {
for _, label := range []string{
v1alpha1.LabelInstanceHypervisor,
v1alpha1.LabelInstanceFamily,
v1alpha1.LabelInstanceSize,
v1alpha1.LabelInstanceCPU,
Expand Down