Skip to content

Commit

Permalink
Update Karpenter
Browse files Browse the repository at this point in the history
  • Loading branch information
engedaam committed Mar 26, 2024
1 parent 85dca5a commit db05bc7
Show file tree
Hide file tree
Showing 7 changed files with 19 additions and 16 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ require (
github.com/PuerkitoBio/goquery v1.8.1
github.com/avast/retry-go v3.0.0+incompatible
github.com/aws/aws-sdk-go v1.48.0
github.com/aws/karpenter-core v0.32.8
github.com/aws/karpenter-core v0.32.9-0.20240326160553-6642110e7c0c
github.com/aws/karpenter/tools/kompat v0.0.0-20231010173459-62c25a3ea85c
github.com/go-logr/zapr v1.3.0
github.com/imdario/mergo v0.3.16
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,8 @@ github.com/avast/retry-go v3.0.0+incompatible h1:4SOWQ7Qs+oroOTQOYnAHqelpCO0biHS
github.com/avast/retry-go v3.0.0+incompatible/go.mod h1:XtSnn+n/sHqQIpZ10K1qAevBhOOCWBLXXy3hyiqqBrY=
github.com/aws/aws-sdk-go v1.48.0 h1:1SeJ8agckRDQvnSCt1dGZYAwUaoD2Ixj6IaXB4LCv8Q=
github.com/aws/aws-sdk-go v1.48.0/go.mod h1:LF8svs817+Nz+DmiMQKTO3ubZ/6IaTpq3TjupRn3Eqk=
github.com/aws/karpenter-core v0.32.8 h1:w8XqihzF19w1P/P3+2h/DYJNX7pixNQ9QQAepHcQrSk=
github.com/aws/karpenter-core v0.32.8/go.mod h1:DY6qKd/bLlTrWFDtEdYQtapSUtCArP72DpkseN5EB8U=
github.com/aws/karpenter-core v0.32.9-0.20240326160553-6642110e7c0c h1:lrPySM7TrIohE0TfZmTQqYzsZ1SPILFPQrr3IrsgNuU=
github.com/aws/karpenter-core v0.32.9-0.20240326160553-6642110e7c0c/go.mod h1:DY6qKd/bLlTrWFDtEdYQtapSUtCArP72DpkseN5EB8U=
github.com/aws/karpenter/tools/kompat v0.0.0-20231010173459-62c25a3ea85c h1:oXWwIttmjYLbBKhLazG21aQvpJ3NOOr8IXhCJ/p6e/M=
github.com/aws/karpenter/tools/kompat v0.0.0-20231010173459-62c25a3ea85c/go.mod h1:l/TIBsaCx/IrOr0Xvlj/cHLOf05QzuQKEZ1hx2XWmfU=
github.com/beorn7/perks v0.0.0-20180321164747-3a771d992973/go.mod h1:Dwedo/Wpr24TaqPxmxbtue+5NUziq4I4S80YR8gNf3Q=
Expand Down
2 changes: 1 addition & 1 deletion pkg/cloudprovider/drift.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ func (c *CloudProvider) areStaticFieldsDrifted(nodeClaim *corev1beta1.NodeClaim,
return ""
}

if nodeClass.IsNodeTemplate {
if !nodeClass.IsNodeTemplate {
nodeClassHashVersion, foundNodeClassHashVersion := nodeClass.Annotations[v1beta1.AnnotationEC2NodeClassHashVersion]
nodeClaimHashVersion, foundNodeClaimHashVersion := nodeClaim.Annotations[v1beta1.AnnotationEC2NodeClassHashVersion]
if !foundNodeClassHashVersion || !foundNodeClaimHashVersion {
Expand Down
12 changes: 6 additions & 6 deletions pkg/cloudprovider/nodeclaim_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ var _ = Describe("NodeClaim/CloudProvider", func() {
cloudProviderNodeClaim, err := cloudProvider.Create(ctx, nodeClaim)
Expect(err).To(BeNil())
Expect(cloudProviderNodeClaim).ToNot(BeNil())
_, ok := cloudProviderNodeClaim.ObjectMeta.Annotations[v1beta1.AnnotationNodeClassHash]
_, ok := cloudProviderNodeClaim.ObjectMeta.Annotations[v1beta1.AnnotationEC2NodeClassHash]
Expect(ok).To(BeTrue())
})
Context("EC2 Context", func() {
Expand Down Expand Up @@ -194,12 +194,12 @@ var _ = Describe("NodeClaim/CloudProvider", func() {
Reservations: []*ec2.Reservation{{Instances: []*ec2.Instance{instance}}},
})
nodeClass.Annotations = lo.Assign(nodeClass.Annotations, map[string]string{
v1beta1.AnnotationNodeClassHash: nodeClass.Hash(),
v1beta1.AnnotationEC2NodeClassHash: nodeClass.Hash(),
v1beta1.AnnotationEC2NodeClassHashVersion: v1beta1.EC2NodeClassHashVersion,
})
nodeClaim.Status.ProviderID = fake.ProviderID(lo.FromPtr(instance.InstanceId))
nodeClaim.Annotations = lo.Assign(nodeClaim.Annotations, map[string]string{
v1beta1.AnnotationNodeClassHash: nodeClass.Hash(),
v1beta1.AnnotationEC2NodeClassHash: nodeClass.Hash(),
v1beta1.AnnotationEC2NodeClassHashVersion: v1beta1.EC2NodeClassHashVersion,
})
nodeClaim.Labels = lo.Assign(nodeClaim.Labels, map[string]string{v1.LabelInstanceTypeStable: selectedInstanceType.Name})
Expand Down Expand Up @@ -230,7 +230,7 @@ var _ = Describe("NodeClaim/CloudProvider", func() {
instance.SecurityGroups = []*ec2.GroupIdentifier{{GroupId: aws.String(fake.SecurityGroupID())}}
// Assign a fake hash
nodeClass.Annotations = lo.Assign(nodeClass.Annotations, map[string]string{
v1beta1.AnnotationNodeClassHash: "abcdefghijkl",
v1beta1.AnnotationEC2NodeClassHash: "abcdefghijkl",
})
ExpectApplied(ctx, env.Client, nodeClass)
isDrifted, err := cloudProvider.IsDrifted(ctx, nodeClaim)
Expand Down Expand Up @@ -331,7 +331,7 @@ var _ = Describe("NodeClaim/CloudProvider", func() {
Expect(isDrifted).To(BeEmpty())

Expect(mergo.Merge(nodeClass, changes, mergo.WithOverride))
nodeClass.Annotations = lo.Assign(nodeClass.Annotations, map[string]string{v1beta1.AnnotationNodeClassHash: nodeClass.Hash()})
nodeClass.Annotations = lo.Assign(nodeClass.Annotations, map[string]string{v1beta1.AnnotationEC2NodeClassHash: nodeClass.Hash()})

ExpectApplied(ctx, env.Client, nodeClass)
isDrifted, err = cloudProvider.IsDrifted(ctx, nodeClaim)
Expand All @@ -354,7 +354,7 @@ var _ = Describe("NodeClaim/CloudProvider", func() {
Expect(isDrifted).To(BeEmpty())

Expect(mergo.Merge(nodeClass, changes, mergo.WithOverride))
nodeClass.Annotations = lo.Assign(nodeClass.Annotations, map[string]string{v1beta1.AnnotationNodeClassHash: nodeClass.Hash()})
nodeClass.Annotations = lo.Assign(nodeClass.Annotations, map[string]string{v1beta1.AnnotationEC2NodeClassHash: nodeClass.Hash()})

ExpectApplied(ctx, env.Client, nodeClass)
isDrifted, err = cloudProvider.IsDrifted(ctx, nodeClaim)
Expand Down
10 changes: 6 additions & 4 deletions pkg/controllers/nodeclass/nodeclass_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ import (
_ "knative.dev/pkg/system/testing"
"sigs.k8s.io/controller-runtime/pkg/client"

metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"

corev1beta1 "github.com/aws/karpenter-core/pkg/apis/v1beta1"
coretest "github.com/aws/karpenter-core/pkg/test"
. "github.com/aws/karpenter-core/pkg/test/expectations"
Expand Down Expand Up @@ -702,7 +704,7 @@ var _ = Describe("NodeClassController", func() {
nodeClass = ExpectExists(ctx, env.Client, nodeClass)

expectedHash := nodeClass.Hash()
Expect(nodeClass.ObjectMeta.Annotations[v1beta1.AnnotationNodeClassHash]).To(Equal(expectedHash))
Expect(nodeClass.ObjectMeta.Annotations[v1beta1.AnnotationEC2NodeClassHash]).To(Equal(expectedHash))

Expect(mergo.Merge(nodeClass, changes, mergo.WithOverride)).To(Succeed())

Expand All @@ -711,7 +713,7 @@ var _ = Describe("NodeClassController", func() {
nodeClass = ExpectExists(ctx, env.Client, nodeClass)

expectedHashTwo := nodeClass.Hash()
Expect(nodeClass.Annotations[v1beta1.AnnotationNodeClassHash]).To(Equal(expectedHashTwo))
Expect(nodeClass.Annotations[v1beta1.AnnotationEC2NodeClassHash]).To(Equal(expectedHashTwo))
Expect(expectedHash).ToNot(Equal(expectedHashTwo))

},
Expand All @@ -729,7 +731,7 @@ var _ = Describe("NodeClassController", func() {
nodeClass = ExpectExists(ctx, env.Client, nodeClass)

expectedHash := nodeClass.Hash()
Expect(nodeClass.Annotations[v1beta1.AnnotationNodeClassHash]).To(Equal(expectedHash))
Expect(nodeClass.Annotations[v1beta1.AnnotationEC2NodeClassHash]).To(Equal(expectedHash))

nodeClass.Spec.SubnetSelectorTerms = []v1beta1.SubnetSelectorTerm{
{
Expand All @@ -750,7 +752,7 @@ var _ = Describe("NodeClassController", func() {
ExpectApplied(ctx, env.Client, nodeClass)
ExpectReconcileSucceeded(ctx, nodeClassController, client.ObjectKeyFromObject(nodeClass))
nodeClass = ExpectExists(ctx, env.Client, nodeClass)
Expect(nodeClass.Annotations[v1beta1.AnnotationNodeClassHash]).To(Equal(expectedHash))
Expect(nodeClass.Annotations[v1beta1.AnnotationEC2NodeClassHash]).To(Equal(expectedHash))
})
It("should update ec2nodeclass-hash-version annotation when the ec2nodeclass-hash-version on the NodeClass does not match with the controller hash version", func() {
nodeClass.Annotations = map[string]string{
Expand Down
3 changes: 2 additions & 1 deletion test/pkg/environment/common/expectations.go
Original file line number Diff line number Diff line change
Expand Up @@ -270,11 +270,12 @@ func (env *Environment) ExpectPrefixDelegationDisabled() {
"ENABLE_PREFIX_DELEGATION", "false", "aws-node")
}

func (env *Environment) ExpectExists(obj client.Object) {
func (env *Environment) ExpectExists(obj client.Object) client.Object {
GinkgoHelper()
Eventually(func(g Gomega) {
g.Expect(env.Client.Get(env, client.ObjectKeyFromObject(obj), obj)).To(Succeed())
}).WithTimeout(time.Second * 5).Should(Succeed())
return obj
}

func (env *Environment) EventuallyExpectHealthy(pods ...*v1.Pod) {
Expand Down
2 changes: 1 addition & 1 deletion test/suites/beta/integration/hash_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ var _ = Describe("CRD Hash", func() {
err := env.Client.Get(env, client.ObjectKeyFromObject(nodeClass), nc)
g.Expect(err).ToNot(HaveOccurred())

hash, found := nc.Annotations[v1beta1.AnnotationNodeClassHash]
hash, found := nc.Annotations[v1beta1.AnnotationEC2NodeClassHash]
g.Expect(found).To(BeTrue())
g.Expect(hash).To(Equal(nc.Hash()))
})
Expand Down

0 comments on commit db05bc7

Please sign in to comment.