From f75c48e1efc1f022f2bb3fa7720c06e15afe7e9b Mon Sep 17 00:00:00 2001 From: Yu Xiang Zhang Date: Thu, 25 Jan 2024 02:14:52 +0000 Subject: [PATCH] Expand Karpenter settings.aws block to settings for v0.33.0 and greater --- pkg/karpenter/karpenter.go | 21 ++++++++++++++------- pkg/karpenter/karpenter_test.go | 15 +++++++++++++++ 2 files changed, 29 insertions(+), 7 deletions(-) diff --git a/pkg/karpenter/karpenter.go b/pkg/karpenter/karpenter.go index b80b556bc1..fd8293664b 100644 --- a/pkg/karpenter/karpenter.go +++ b/pkg/karpenter/karpenter.go @@ -9,6 +9,7 @@ import ( api "github.com/weaveworks/eksctl/pkg/apis/eksctl.io/v1alpha5" "github.com/weaveworks/eksctl/pkg/karpenter/providers" + "github.com/weaveworks/eksctl/pkg/utils" ) const ( @@ -78,16 +79,22 @@ func (k *Installer) Install(ctx context.Context, serviceAccountRoleARN string, i defaultInstanceProfile: instanceProfileName, }, settings: map[string]interface{}{ - aws: map[string]interface{}{ - defaultInstanceProfile: instanceProfileName, - clusterName: k.ClusterConfig.Metadata.Name, - clusterEndpoint: k.ClusterConfig.Status.Endpoint, - interruptionQueueName: k.ClusterConfig.Metadata.Name, - }, + defaultInstanceProfile: instanceProfileName, + clusterName: k.ClusterConfig.Metadata.Name, + clusterEndpoint: k.ClusterConfig.Status.Endpoint, + interruptionQueueName: k.ClusterConfig.Metadata.Name, }, serviceAccount: serviceAccountMap, } + version := k.ClusterConfig.Karpenter.Version + compareVersions, err := utils.CompareVersions(version, "0.33.0") + if err == nil && compareVersions < 0 { + values[settings] = map[string]interface{}{ + aws: values[settings], + } + } + registryClient, err := registry.NewClient( registry.ClientOptEnableCache(true), ) @@ -101,7 +108,7 @@ func (k *Installer) Install(ctx context.Context, serviceAccountRoleARN string, i Namespace: DefaultNamespace, ReleaseName: releaseName, Values: values, - Version: k.ClusterConfig.Karpenter.Version, + Version: version, RegistryClient: registryClient, } diff --git a/pkg/karpenter/karpenter_test.go b/pkg/karpenter/karpenter_test.go index 2fb6f1fedf..d0a47235e8 100644 --- a/pkg/karpenter/karpenter_test.go +++ b/pkg/karpenter/karpenter_test.go @@ -81,6 +81,21 @@ var _ = Describe("Install", func() { })) }) + It("installs karpenter with expanded settings.aws values for version greater or equal to v0.33.0", func() { + installerUnderTest.Options.ClusterConfig.Karpenter.Version = "0.33.0" + Expect(installerUnderTest.Install(context.Background(), "dummy", "dummy")).To(Succeed()) + _, opts := fakeHelmInstaller.InstallChartArgsForCall(0) + values := map[string]interface{}{ + settings: map[string]interface{}{ + defaultInstanceProfile: "dummy", + clusterName: cfg.Metadata.Name, + clusterEndpoint: cfg.Status.Endpoint, + interruptionQueueName: cfg.Metadata.Name, + }, + } + Expect(opts.Values[settings]).To(Equal(values[settings])) + }) + When("install chart fails", func() { BeforeEach(func() {