Skip to content

Commit

Permalink
chore: Fill in the NodeClassReference for all NodePools and NodeClaims (
Browse files Browse the repository at this point in the history
  • Loading branch information
jonathan-innis authored Jul 1, 2024
1 parent ef45392 commit cf6ba8c
Show file tree
Hide file tree
Showing 15 changed files with 138 additions and 40 deletions.
5 changes: 3 additions & 2 deletions pkg/apis/v1/nodepool_validation_cel_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,9 @@ var _ = Describe("CEL/Validation", func() {
Template: v1beta1.NodeClaimTemplate{
Spec: v1beta1.NodeClaimSpec{
NodeClassRef: &v1beta1.NodeClassReference{
Kind: "NodeClaim",
Name: "default",
APIVersion: "karpenter.k8s.aws/v1beta1",
Kind: "EC2NodeClass",
Name: "default",
},
Requirements: []v1beta1.NodeSelectorRequirementWithMinValues{
{
Expand Down
5 changes: 3 additions & 2 deletions pkg/apis/v1beta1/nodepool_validation_cel_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,9 @@ var _ = Describe("CEL/Validation", func() {
Template: v1beta1.NodeClaimTemplate{
Spec: v1beta1.NodeClaimSpec{
NodeClassRef: &v1beta1.NodeClassReference{
Kind: "NodeClaim",
Name: "default",
APIVersion: "karpenter.k8s.aws/v1beta1",
Kind: "EC2NodeClass",
Name: "default",
},
Requirements: []v1beta1.NodeSelectorRequirementWithMinValues{
{
Expand Down
29 changes: 22 additions & 7 deletions pkg/cloudprovider/suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
"testing"
"time"

"github.com/awslabs/operatorpkg/object"
v1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/api/resource"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
Expand Down Expand Up @@ -158,7 +159,9 @@ var _ = Describe("CloudProvider", func() {
Template: corev1beta1.NodeClaimTemplate{
Spec: corev1beta1.NodeClaimSpec{
NodeClassRef: &corev1beta1.NodeClassReference{
Name: nodeClass.Name,
APIVersion: object.GVK(nodeClass).GroupVersion().String(),
Kind: object.GVK(nodeClass).Kind,
Name: nodeClass.Name,
},
Requirements: []corev1beta1.NodeSelectorRequirementWithMinValues{
{NodeSelectorRequirement: v1.NodeSelectorRequirement{Key: corev1beta1.CapacityTypeLabelKey, Operator: v1.NodeSelectorOpIn, Values: []string{corev1beta1.CapacityTypeOnDemand}}},
Expand All @@ -173,7 +176,9 @@ var _ = Describe("CloudProvider", func() {
},
Spec: corev1beta1.NodeClaimSpec{
NodeClassRef: &corev1beta1.NodeClassReference{
Name: nodeClass.Name,
APIVersion: object.GVK(nodeClass).GroupVersion().String(),
Kind: object.GVK(nodeClass).Kind,
Name: nodeClass.Name,
},
Requirements: []corev1beta1.NodeSelectorRequirementWithMinValues{
{
Expand Down Expand Up @@ -314,7 +319,9 @@ var _ = Describe("CloudProvider", func() {
Template: corev1beta1.NodeClaimTemplate{
Spec: corev1beta1.NodeClaimSpec{
NodeClassRef: &corev1beta1.NodeClassReference{
Name: nodeClass.Name,
APIVersion: object.GVK(nodeClass).GroupVersion().String(),
Kind: object.GVK(nodeClass).Kind,
Name: nodeClass.Name,
},
Requirements: []corev1beta1.NodeSelectorRequirementWithMinValues{
{
Expand Down Expand Up @@ -410,7 +417,9 @@ var _ = Describe("CloudProvider", func() {
Template: corev1beta1.NodeClaimTemplate{
Spec: corev1beta1.NodeClaimSpec{
NodeClassRef: &corev1beta1.NodeClassReference{
Name: nodeClass.Name,
APIVersion: object.GVK(nodeClass).GroupVersion().String(),
Kind: object.GVK(nodeClass).Kind,
Name: nodeClass.Name,
},
Requirements: []corev1beta1.NodeSelectorRequirementWithMinValues{
{
Expand Down Expand Up @@ -513,7 +522,9 @@ var _ = Describe("CloudProvider", func() {
Template: corev1beta1.NodeClaimTemplate{
Spec: corev1beta1.NodeClaimSpec{
NodeClassRef: &corev1beta1.NodeClassReference{
Name: nodeClass.Name,
APIVersion: object.GVK(nodeClass).GroupVersion().String(),
Kind: object.GVK(nodeClass).Kind,
Name: nodeClass.Name,
},
Requirements: []corev1beta1.NodeSelectorRequirementWithMinValues{
{
Expand Down Expand Up @@ -1188,7 +1199,9 @@ var _ = Describe("CloudProvider", func() {
Template: corev1beta1.NodeClaimTemplate{
Spec: corev1beta1.NodeClaimSpec{
NodeClassRef: &corev1beta1.NodeClassReference{
Name: nodeClass2.Name,
APIVersion: object.GVK(nodeClass2).GroupVersion().String(),
Kind: object.GVK(nodeClass2).Kind,
Name: nodeClass2.Name,
},
},
},
Expand Down Expand Up @@ -1230,7 +1243,9 @@ var _ = Describe("CloudProvider", func() {
Template: corev1beta1.NodeClaimTemplate{
Spec: corev1beta1.NodeClaimSpec{
NodeClassRef: &corev1beta1.NodeClassReference{
Name: misconfiguredNodeClass.Name,
APIVersion: object.GVK(misconfiguredNodeClass).GroupVersion().String(),
Kind: object.GVK(misconfiguredNodeClass).Kind,
Name: misconfiguredNodeClass.Name,
},
},
},
Expand Down
17 changes: 13 additions & 4 deletions pkg/controllers/nodeclaim/garbagecollection/suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (

"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/service/ec2"
"github.com/awslabs/operatorpkg/object"
"github.com/samber/lo"
v1 "k8s.io/api/core/v1"
"k8s.io/client-go/tools/record"
Expand Down Expand Up @@ -88,7 +89,9 @@ var _ = Describe("GarbageCollection", func() {
Template: corev1beta1.NodeClaimTemplate{
Spec: corev1beta1.NodeClaimSpec{
NodeClassRef: &corev1beta1.NodeClassReference{
Name: nodeClass.Name,
APIVersion: object.GVK(nodeClass).GroupVersion().String(),
Kind: object.GVK(nodeClass).Kind,
Name: nodeClass.Name,
},
},
},
Expand Down Expand Up @@ -243,7 +246,9 @@ var _ = Describe("GarbageCollection", func() {
nodeClaim := coretest.NodeClaim(corev1beta1.NodeClaim{
Spec: corev1beta1.NodeClaimSpec{
NodeClassRef: &corev1beta1.NodeClassReference{
Name: nodeClass.Name,
APIVersion: object.GVK(nodeClass).GroupVersion().String(),
Kind: object.GVK(nodeClass).Kind,
Name: nodeClass.Name,
},
},
Status: corev1beta1.NodeClaimStatus{
Expand Down Expand Up @@ -304,7 +309,9 @@ var _ = Describe("GarbageCollection", func() {
nodeClaim := coretest.NodeClaim(corev1beta1.NodeClaim{
Spec: corev1beta1.NodeClaimSpec{
NodeClassRef: &corev1beta1.NodeClassReference{
Name: nodeClass.Name,
APIVersion: object.GVK(nodeClass).GroupVersion().String(),
Kind: object.GVK(nodeClass).Kind,
Name: nodeClass.Name,
},
},
Status: corev1beta1.NodeClaimStatus{
Expand Down Expand Up @@ -360,7 +367,9 @@ var _ = Describe("GarbageCollection", func() {
nodeClaim := coretest.NodeClaim(corev1beta1.NodeClaim{
Spec: corev1beta1.NodeClaimSpec{
NodeClassRef: &corev1beta1.NodeClassReference{
Name: nodeClass.Name,
APIVersion: object.GVK(nodeClass).GroupVersion().String(),
Kind: object.GVK(nodeClass).Kind,
Name: nodeClass.Name,
},
},
Status: corev1beta1.NodeClaimStatus{
Expand Down
17 changes: 13 additions & 4 deletions pkg/controllers/nodeclass/hash/suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (
"testing"

"github.com/aws/aws-sdk-go/aws"
"github.com/awslabs/operatorpkg/object"
"github.com/imdario/mergo"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
corev1beta1 "sigs.k8s.io/karpenter/pkg/apis/v1beta1"
Expand Down Expand Up @@ -178,7 +179,9 @@ var _ = Describe("NodeClass Hash Controller", func() {
},
Spec: corev1beta1.NodeClaimSpec{
NodeClassRef: &corev1beta1.NodeClassReference{
Name: nodeClass.Name,
APIVersion: object.GVK(nodeClass).GroupVersion().String(),
Kind: object.GVK(nodeClass).Kind,
Name: nodeClass.Name,
},
},
})
Expand All @@ -191,7 +194,9 @@ var _ = Describe("NodeClass Hash Controller", func() {
},
Spec: corev1beta1.NodeClaimSpec{
NodeClassRef: &corev1beta1.NodeClassReference{
Name: nodeClass.Name,
APIVersion: object.GVK(nodeClass).GroupVersion().String(),
Kind: object.GVK(nodeClass).Kind,
Name: nodeClass.Name,
},
},
})
Expand Down Expand Up @@ -224,7 +229,9 @@ var _ = Describe("NodeClass Hash Controller", func() {
},
Spec: corev1beta1.NodeClaimSpec{
NodeClassRef: &corev1beta1.NodeClassReference{
Name: nodeClass.Name,
APIVersion: object.GVK(nodeClass).GroupVersion().String(),
Kind: object.GVK(nodeClass).Kind,
Name: nodeClass.Name,
},
},
})
Expand Down Expand Up @@ -257,7 +264,9 @@ var _ = Describe("NodeClass Hash Controller", func() {
},
Spec: corev1beta1.NodeClaimSpec{
NodeClassRef: &corev1beta1.NodeClassReference{
Name: nodeClass.Name,
APIVersion: object.GVK(nodeClass).GroupVersion().String(),
Kind: object.GVK(nodeClass).Kind,
Name: nodeClass.Name,
},
},
})
Expand Down
5 changes: 4 additions & 1 deletion pkg/controllers/nodeclass/termination/suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (
"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/service/ec2"
"github.com/aws/aws-sdk-go/service/iam"
"github.com/awslabs/operatorpkg/object"
"github.com/samber/lo"
"k8s.io/client-go/tools/record"
"sigs.k8s.io/controller-runtime/pkg/controller/controllerutil"
Expand Down Expand Up @@ -207,7 +208,9 @@ var _ = Describe("NodeClass Termination", func() {
nc := coretest.NodeClaim(corev1beta1.NodeClaim{
Spec: corev1beta1.NodeClaimSpec{
NodeClassRef: &corev1beta1.NodeClassReference{
Name: nodeClass.Name,
APIVersion: object.GVK(nodeClass).GroupVersion().String(),
Kind: object.GVK(nodeClass).Kind,
Name: nodeClass.Name,
},
},
})
Expand Down
9 changes: 7 additions & 2 deletions pkg/providers/instance/suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (

"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/service/ec2"
"github.com/awslabs/operatorpkg/object"
"github.com/samber/lo"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/util/sets"
Expand Down Expand Up @@ -87,7 +88,9 @@ var _ = Describe("InstanceProvider", func() {
Template: corev1beta1.NodeClaimTemplate{
Spec: corev1beta1.NodeClaimSpec{
NodeClassRef: &corev1beta1.NodeClassReference{
Name: nodeClass.Name,
APIVersion: object.GVK(nodeClass).GroupVersion().String(),
Kind: object.GVK(nodeClass).Kind,
Name: nodeClass.Name,
},
},
},
Expand All @@ -101,7 +104,9 @@ var _ = Describe("InstanceProvider", func() {
},
Spec: corev1beta1.NodeClaimSpec{
NodeClassRef: &corev1beta1.NodeClassReference{
Name: nodeClass.Name,
APIVersion: object.GVK(nodeClass).GroupVersion().String(),
Kind: object.GVK(nodeClass).Kind,
Name: nodeClass.Name,
},
},
})
Expand Down
15 changes: 12 additions & 3 deletions pkg/providers/launchtemplate/suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import (
"github.com/aws/aws-sdk-go/aws/awserr"
"github.com/aws/aws-sdk-go/service/ec2"
admv1alpha1 "github.com/awslabs/amazon-eks-ami/nodeadm/api/v1alpha1"
"github.com/awslabs/operatorpkg/object"
opstatus "github.com/awslabs/operatorpkg/status"
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
Expand Down Expand Up @@ -174,7 +175,9 @@ var _ = Describe("LaunchTemplate Provider", func() {
},
Kubelet: &corev1beta1.KubeletConfiguration{},
NodeClassRef: &corev1beta1.NodeClassReference{
Name: nodeClass.Name,
APIVersion: object.GVK(nodeClass).GroupVersion().String(),
Kind: object.GVK(nodeClass).Kind,
Name: nodeClass.Name,
},
},
},
Expand Down Expand Up @@ -210,7 +213,9 @@ var _ = Describe("LaunchTemplate Provider", func() {
},
},
NodeClassRef: &corev1beta1.NodeClassReference{
Name: nodeClass2.Name,
APIVersion: object.GVK(nodeClass2).GroupVersion().String(),
Kind: object.GVK(nodeClass2).Kind,
Name: nodeClass2.Name,
},
},
},
Expand Down Expand Up @@ -1396,7 +1401,11 @@ var _ = Describe("LaunchTemplate Provider", func() {
ExpectLaunchTemplatesCreatedWithUserData(fmt.Sprintf(string(content), corev1beta1.NodePoolLabelKey, nodePool.Name))
})
It("should not bootstrap when provider ref points to a non-existent EC2NodeClass resource", func() {
nodePool.Spec.Template.Spec.NodeClassRef = &corev1beta1.NodeClassReference{Name: "doesnotexist"}
nodePool.Spec.Template.Spec.NodeClassRef = &corev1beta1.NodeClassReference{
APIVersion: "doesnotexist",
Kind: "doesnotexist",
Name: "doesnotexist",
}
ExpectApplied(ctx, env.Client, nodePool)
pod := coretest.UnschedulablePod()
ExpectProvisioned(ctx, env.Client, cluster, cloudProvider, prov, pod)
Expand Down
5 changes: 4 additions & 1 deletion test/pkg/environment/common/environment.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (
"testing"
"time"

"github.com/awslabs/operatorpkg/object"
"github.com/onsi/gomega"
"github.com/samber/lo"
v1 "k8s.io/api/core/v1"
Expand Down Expand Up @@ -134,7 +135,9 @@ func NewClient(ctx context.Context, config *rest.Config) client.Client {
func (env *Environment) DefaultNodePool(nodeClass *v1beta1.EC2NodeClass) *corev1beta1.NodePool {
nodePool := coretest.NodePool()
nodePool.Spec.Template.Spec.NodeClassRef = &corev1beta1.NodeClassReference{
Name: nodeClass.Name,
APIVersion: object.GVK(nodeClass).GroupVersion().String(),
Kind: object.GVK(nodeClass).Kind,
Name: nodeClass.Name,
}
nodePool.Spec.Template.Spec.Requirements = []corev1beta1.NodeSelectorRequirementWithMinValues{
{
Expand Down
19 changes: 16 additions & 3 deletions test/suites/consolidation/suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
"time"

"github.com/aws/aws-sdk-go/aws"
"github.com/awslabs/operatorpkg/object"
"github.com/samber/lo"
appsv1 "k8s.io/api/apps/v1"
v1 "k8s.io/api/core/v1"
Expand Down Expand Up @@ -433,7 +434,11 @@ var _ = Describe("Consolidation", func() {
},
},
},
NodeClassRef: &corev1beta1.NodeClassReference{Name: nodeClass.Name},
NodeClassRef: &corev1beta1.NodeClassReference{
APIVersion: object.GVK(nodeClass).GroupVersion().String(),
Kind: object.GVK(nodeClass).Kind,
Name: nodeClass.Name,
},
},
},
},
Expand Down Expand Up @@ -519,7 +524,11 @@ var _ = Describe("Consolidation", func() {
},
},
},
NodeClassRef: &corev1beta1.NodeClassReference{Name: nodeClass.Name},
NodeClassRef: &corev1beta1.NodeClassReference{
APIVersion: object.GVK(nodeClass).GroupVersion().String(),
Kind: object.GVK(nodeClass).Kind,
Name: nodeClass.Name,
},
},
},
},
Expand Down Expand Up @@ -662,7 +671,11 @@ var _ = Describe("Consolidation", func() {
},
},
},
NodeClassRef: &corev1beta1.NodeClassReference{Name: nodeClass.Name},
NodeClassRef: &corev1beta1.NodeClassReference{
APIVersion: object.GVK(nodeClass).GroupVersion().String(),
Kind: object.GVK(nodeClass).Kind,
Name: nodeClass.Name,
},
},
},
},
Expand Down
7 changes: 6 additions & 1 deletion test/suites/drift/suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"testing"
"time"

"github.com/awslabs/operatorpkg/object"
"github.com/samber/lo"
appsv1 "k8s.io/api/apps/v1"
v1 "k8s.io/api/core/v1"
Expand Down Expand Up @@ -541,7 +542,11 @@ var _ = Describe("Drift", func() {
Spec: corev1beta1.NodePoolSpec{
Template: corev1beta1.NodeClaimTemplate{
Spec: corev1beta1.NodeClaimSpec{
NodeClassRef: &corev1beta1.NodeClassReference{Name: nodeClass.Name},
NodeClassRef: &corev1beta1.NodeClassReference{
APIVersion: object.GVK(nodeClass).GroupVersion().String(),
Kind: object.GVK(nodeClass).Kind,
Name: nodeClass.Name,
},
},
},
},
Expand Down
Loading

0 comments on commit cf6ba8c

Please sign in to comment.