diff --git a/go.mod b/go.mod index 326db5bda308..818f03de4127 100644 --- a/go.mod +++ b/go.mod @@ -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.45.28 - github.com/aws/karpenter-core v0.31.1-0.20231018213242-4555b8dfcd10 + github.com/aws/karpenter-core v0.31.1-0.20231019061253-604d23cb7140 github.com/aws/karpenter/tools/kompat v0.0.0-20231010173459-62c25a3ea85c github.com/imdario/mergo v0.3.16 github.com/mitchellh/hashstructure/v2 v2.0.2 diff --git a/go.sum b/go.sum index 9dcf9ebc8b75..26ce1669d960 100644 --- a/go.sum +++ b/go.sum @@ -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.45.28 h1:p2ATcaK6ffSw4yZ2UAGzgRyRXwKyOJY6ZCiKqj5miJE= github.com/aws/aws-sdk-go v1.45.28/go.mod h1:aVsgQcEevwlmQ7qHE9I3h+dtQgpqhFB+i8Phjh7fkwI= -github.com/aws/karpenter-core v0.31.1-0.20231018213242-4555b8dfcd10 h1:ZKoz01A7DXGVEi0V4tGMd0LbLHEesIzFzYlFQTMQXSE= -github.com/aws/karpenter-core v0.31.1-0.20231018213242-4555b8dfcd10/go.mod h1:rb3kp/3cj38tACF6udfpmIvKoQMwirSVoHNlrd66LyE= +github.com/aws/karpenter-core v0.31.1-0.20231019061253-604d23cb7140 h1:6996xW3nY1C8Ettn25GNltKEu9RoKv6RWrzibuVGWbk= +github.com/aws/karpenter-core v0.31.1-0.20231019061253-604d23cb7140/go.mod h1:rb3kp/3cj38tACF6udfpmIvKoQMwirSVoHNlrd66LyE= 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/benbjohnson/clock v1.1.0/go.mod h1:J11/hYXuz8f4ySSvYwY0FKfm+ezbsZBKZxNJlLklBHA= diff --git a/hack/docs/configuration_gen_docs.go b/hack/docs/configuration_gen_docs.go index 4cfa57b17fee..828369d0e405 100644 --- a/hack/docs/configuration_gen_docs.go +++ b/hack/docs/configuration_gen_docs.go @@ -49,7 +49,9 @@ func main() { topDoc := fmt.Sprintf("%s%s\n\n", startDocSections[0], genStart) bottomDoc := fmt.Sprintf("\n%s%s", genEnd, endDocSections[1]) - fs := flag.NewFlagSet("karpenter", flag.ContinueOnError) + fs := &coreoptions.FlagSet { + FlagSet: flag.NewFlagSet("karpenter", flag.ContinueOnError), + } (&coreoptions.Options{}).AddFlags(fs) (&options.Options{}).AddFlags(fs) diff --git a/pkg/controllers/controllers.go b/pkg/controllers/controllers.go index d048f6d05977..cf2421f65213 100644 --- a/pkg/controllers/controllers.go +++ b/pkg/controllers/controllers.go @@ -58,7 +58,7 @@ func NewControllers(ctx context.Context, sess *session.Session, clk clock.Clock, nodeclaimgarbagecollection.NewController(kubeClient, cloudProvider, linkController), nodeclaimtagging.NewController(kubeClient, instanceProvider), } - if options.FromContext(ctx).InterruptionQueueName != "" { + if options.FromContext(ctx).InterruptionQueue != "" { controllers = append(controllers, interruption.NewController(kubeClient, clk, recorder, interruption.NewSQSProvider(sqs.New(sess)), unavailableOfferings)) } if options.FromContext(ctx).IsolatedVPC { diff --git a/pkg/controllers/interruption/controller.go b/pkg/controllers/interruption/controller.go index e5d4651e610b..f6d594764755 100644 --- a/pkg/controllers/interruption/controller.go +++ b/pkg/controllers/interruption/controller.go @@ -80,8 +80,8 @@ func NewController(kubeClient client.Client, clk clock.Clock, recorder events.Re } func (c *Controller) Reconcile(ctx context.Context, _ reconcile.Request) (reconcile.Result, error) { - ctx = logging.WithLogger(ctx, logging.FromContext(ctx).With("queue", options.FromContext(ctx).InterruptionQueueName)) - if c.cm.HasChanged(options.FromContext(ctx).InterruptionQueueName, nil) { + ctx = logging.WithLogger(ctx, logging.FromContext(ctx).With("queue", options.FromContext(ctx).InterruptionQueue)) + if c.cm.HasChanged(options.FromContext(ctx).InterruptionQueue, nil) { logging.FromContext(ctx).Debugf("watching interruption queue") } sqsMessages, err := c.sqsProvider.GetSQSMessages(ctx) diff --git a/pkg/controllers/interruption/sqs.go b/pkg/controllers/interruption/sqs.go index 6cf518955820..7090da489a13 100644 --- a/pkg/controllers/interruption/sqs.go +++ b/pkg/controllers/interruption/sqs.go @@ -43,7 +43,7 @@ func NewSQSProvider(client sqsiface.SQSAPI) *SQSProvider { } provider.queueURL.Resolve = func(ctx context.Context) (string, error) { input := &sqs.GetQueueUrlInput{ - QueueName: aws.String(options.FromContext(ctx).InterruptionQueueName), + QueueName: aws.String(options.FromContext(ctx).InterruptionQueue), } ret, err := provider.client.GetQueueUrlWithContext(ctx, input) if err != nil { @@ -66,12 +66,12 @@ func (s *SQSProvider) QueueExists(ctx context.Context) (bool, error) { } func (s *SQSProvider) DiscoverQueueURL(ctx context.Context) (string, error) { - if options.FromContext(ctx).InterruptionQueueName != lo.FromPtr(s.queueName.Load()) { + if options.FromContext(ctx).InterruptionQueue != lo.FromPtr(s.queueName.Load()) { res, err := s.queueURL.TryGet(ctx, atomic.IgnoreCacheOption) if err != nil { return res, err } - s.queueName.Store(lo.ToPtr(options.FromContext(ctx).InterruptionQueueName)) + s.queueName.Store(lo.ToPtr(options.FromContext(ctx).InterruptionQueue)) return res, nil } return s.queueURL.TryGet(ctx) diff --git a/pkg/controllers/interruption/suite_test.go b/pkg/controllers/interruption/suite_test.go index 8cb557e1efbf..5b2bd879190a 100644 --- a/pkg/controllers/interruption/suite_test.go +++ b/pkg/controllers/interruption/suite_test.go @@ -94,7 +94,7 @@ var _ = AfterSuite(func() { var _ = BeforeEach(func() { ctx = coreoptions.ToContext(ctx, coretest.Options()) ctx = options.ToContext(ctx, test.Options(test.OptionsFields{ - InterruptionQueueName: lo.ToPtr("test-cluster"), + InterruptionQueue: lo.ToPtr("test-cluster"), })) ctx = settings.ToContext(ctx, test.Settings()) unavailableOfferingsCache.Flush() diff --git a/pkg/operator/options/options.go b/pkg/operator/options/options.go index 2d836d798aa9..9134b944662d 100644 --- a/pkg/operator/options/options.go +++ b/pkg/operator/options/options.go @@ -44,10 +44,10 @@ type Options struct { ClusterEndpoint string IsolatedVPC bool VMMemoryOverheadPercent float64 - InterruptionQueueName string + InterruptionQueue string ReservedENIs int - setFlags map[string]bool + setFlags map[string]bool } func (o *Options) AddFlags(fs *coreoptions.FlagSet) { @@ -58,7 +58,7 @@ func (o *Options) AddFlags(fs *coreoptions.FlagSet) { fs.StringVar(&o.ClusterEndpoint, "cluster-endpoint", env.WithDefaultString("CLUSTER_ENDPOINT", ""), "The external kubernetes cluster endpoint for new nodes to connect with. If not specified, will discover the cluster endpoint using DescribeCluster API.") fs.BoolVarWithEnv(&o.IsolatedVPC, "isolated-vpc", "ISOLATED_VPC", false, "If true, then assume we can't reach AWS services which don't have a VPC endpoint. This also has the effect of disabling look-ups to the AWS pricing endpoint.") fs.Float64Var(&o.VMMemoryOverheadPercent, "vm-memory-overhead-percent", env.WithDefaultFloat64("VM_MEMORY_OVERHEAD_PERCENT", 0.075), "The VM memory overhead as a percent that will be subtracted from the total memory for all instance types.") - fs.StringVar(&o.InterruptionQueueName, "interruption-queue-name", env.WithDefaultString("INTERRUPTION_QUEUE_NAME", ""), "Interruption queue is disabled if not specified. Enabling interruption handling may require additional permissions on the controller service account. Additional permissions are outlined in the docs.") + fs.StringVar(&o.InterruptionQueue, "interruption-queue", env.WithDefaultString("INTERRUPTION_QUEUE", ""), "Interruption queue is disabled if not specified. Enabling interruption handling may require additional permissions on the controller service account. Additional permissions are outlined in the docs.") fs.IntVar(&o.ReservedENIs, "reserved-enis", env.WithDefaultInt("RESERVED_ENIS", 0), "Reserved ENIs are not included in the calculations for max-pods or kube-reserved. This is most often used in the VPC CNI custom networking setup https://docs.aws.amazon.com/eks/latest/userguide/cni-custom-network.html.") } @@ -103,7 +103,7 @@ func (o *Options) MergeSettings(ctx context.Context) { mergeField(&o.ClusterEndpoint, s.ClusterEndpoint, o.setFlags["cluster-endpoint"]) mergeField(&o.IsolatedVPC, s.IsolatedVPC, o.setFlags["isolated-vpc"]) mergeField(&o.VMMemoryOverheadPercent, s.VMMemoryOverheadPercent, o.setFlags["vm-memory-overhead-percent"]) - mergeField(&o.InterruptionQueueName, s.InterruptionQueueName, o.setFlags["interruption-queue-name"]) + mergeField(&o.InterruptionQueue, s.InterruptionQueueName, o.setFlags["interruption-queue"]) mergeField(&o.ReservedENIs, s.ReservedENIs, o.setFlags["reserved-enis"]) if err := o.validateRequiredFields(); err != nil { panic(fmt.Errorf("checking required fields, %w", err)) diff --git a/pkg/operator/options/suite_test.go b/pkg/operator/options/suite_test.go index 267f77f0cbd2..6703ee13598c 100644 --- a/pkg/operator/options/suite_test.go +++ b/pkg/operator/options/suite_test.go @@ -50,8 +50,8 @@ var _ = Describe("Options", func() { "CLUSTER_NAME", "CLUSTER_ENDPOINT", "ISOLATED_VPC", - "VM_MOMORY_OVERHEAD_PERCENT", - "INTERRUPTION_QUEUE_NAME", + "VM_MEMORY_OVERHEAD_PERCENT", + "INTERRUPTION_QUEUE", "RESERVED_ENIS", } @@ -99,7 +99,7 @@ var _ = Describe("Options", func() { "--cluster-endpoint", "https://options-cluster", "--isolated-vpc", "--vm-memory-overhead-percent", "0.1", - "--interruption-queue-name", "options-cluster", + "--interruption-queue", "options-cluster", "--reserved-enis", "10", ) Expect(err).ToNot(HaveOccurred()) @@ -123,7 +123,7 @@ var _ = Describe("Options", func() { ClusterEndpoint: lo.ToPtr("https://options-cluster"), IsolatedVPC: lo.ToPtr(true), VMMemoryOverheadPercent: lo.ToPtr[float64](0.1), - InterruptionQueueName: lo.ToPtr("options-cluster"), + InterruptionQueue: lo.ToPtr("options-cluster"), ReservedENIs: lo.ToPtr(10), })) @@ -151,7 +151,7 @@ var _ = Describe("Options", func() { ClusterEndpoint: lo.ToPtr("https://settings-cluster"), IsolatedVPC: lo.ToPtr(true), VMMemoryOverheadPercent: lo.ToPtr[float64](0.05), - InterruptionQueueName: lo.ToPtr("settings-cluster"), + InterruptionQueue: lo.ToPtr("settings-cluster"), ReservedENIs: lo.ToPtr(8), })) @@ -163,7 +163,7 @@ var _ = Describe("Options", func() { "--cluster-ca-bundle", "options-bundle", "--cluster-name", "options-cluster", "--cluster-endpoint", "https://options-cluster", - "--interruption-queue-name", "options-cluster", + "--interruption-queue", "options-cluster", ) Expect(err).ToNot(HaveOccurred()) ctx = settings.ToContext(ctx, &settings.Settings{ @@ -186,7 +186,7 @@ var _ = Describe("Options", func() { ClusterEndpoint: lo.ToPtr("https://options-cluster"), IsolatedVPC: lo.ToPtr(true), VMMemoryOverheadPercent: lo.ToPtr[float64](0.1), - InterruptionQueueName: lo.ToPtr("options-cluster"), + InterruptionQueue: lo.ToPtr("options-cluster"), ReservedENIs: lo.ToPtr(10), })) }) @@ -199,13 +199,14 @@ var _ = Describe("Options", func() { os.Setenv("CLUSTER_ENDPOINT", "https://env-cluster") os.Setenv("ISOLATED_VPC", "true") os.Setenv("VM_MEMORY_OVERHEAD_PERCENT", "0.1") - os.Setenv("INTERRUPTION_QUEUE_NAME", "env-cluster") + os.Setenv("INTERRUPTION_QUEUE", "env-cluster") os.Setenv("RESERVED_ENIS", "10") fs = &coreoptions.FlagSet{ FlagSet: flag.NewFlagSet("karpenter", flag.ContinueOnError), } opts.AddFlags(fs) - opts.Parse(fs) + err := opts.Parse(fs) + Expect(err).ToNot(HaveOccurred()) expectOptionsEqual(opts, test.Options(test.OptionsFields{ AssumeRoleARN: lo.ToPtr("env-role"), AssumeRoleDuration: lo.ToPtr(20 * time.Minute), @@ -214,7 +215,7 @@ var _ = Describe("Options", func() { ClusterEndpoint: lo.ToPtr("https://env-cluster"), IsolatedVPC: lo.ToPtr(true), VMMemoryOverheadPercent: lo.ToPtr[float64](0.1), - InterruptionQueueName: lo.ToPtr("env-cluster"), + InterruptionQueue: lo.ToPtr("env-cluster"), ReservedENIs: lo.ToPtr(10), })) }) @@ -259,6 +260,6 @@ func expectOptionsEqual(optsA *options.Options, optsB *options.Options) { Expect(optsA.ClusterEndpoint).To(Equal(optsB.ClusterEndpoint)) Expect(optsA.IsolatedVPC).To(Equal(optsB.IsolatedVPC)) Expect(optsA.VMMemoryOverheadPercent).To(Equal(optsB.VMMemoryOverheadPercent)) - Expect(optsA.InterruptionQueueName).To(Equal(optsB.InterruptionQueueName)) + Expect(optsA.InterruptionQueue).To(Equal(optsB.InterruptionQueue)) Expect(optsA.ReservedENIs).To(Equal(optsB.ReservedENIs)) } diff --git a/pkg/providers/instance/suite_test.go b/pkg/providers/instance/suite_test.go index 45e163c0a7c2..44d155b95004 100644 --- a/pkg/providers/instance/suite_test.go +++ b/pkg/providers/instance/suite_test.go @@ -70,8 +70,8 @@ var _ = AfterSuite(func() { }) var _ = BeforeEach(func() { - ctx = options.ToContext(ctx, opts) - ctx = coresettings.ToContext(ctx, coretest.Settings()) + ctx = coreoptions.ToContext(ctx, coretest.Options()) + ctx = options.ToContext(ctx, test.Options()) ctx = settings.ToContext(ctx, test.Settings()) awsEnv.Reset() }) diff --git a/pkg/test/options.go b/pkg/test/options.go index 378b8e2dbc5a..609c118bcb2a 100644 --- a/pkg/test/options.go +++ b/pkg/test/options.go @@ -32,7 +32,7 @@ type OptionsFields struct { ClusterEndpoint *string IsolatedVPC *bool VMMemoryOverheadPercent *float64 - InterruptionQueueName *string + InterruptionQueue *string ReservedENIs *int } @@ -51,7 +51,7 @@ func Options(overrides ...OptionsFields) *options.Options { ClusterEndpoint: lo.FromPtrOr(opts.ClusterEndpoint, "https://test-cluster"), IsolatedVPC: lo.FromPtrOr(opts.IsolatedVPC, false), VMMemoryOverheadPercent: lo.FromPtrOr(opts.VMMemoryOverheadPercent, 0.075), - InterruptionQueueName: lo.FromPtrOr(opts.InterruptionQueueName, ""), + InterruptionQueue: lo.FromPtrOr(opts.InterruptionQueue, ""), ReservedENIs: lo.FromPtrOr(opts.ReservedENIs, 0), } } diff --git a/test/pkg/environment/aws/environment.go b/test/pkg/environment/aws/environment.go index 7d4ab57064ce..9fc111b9759c 100644 --- a/test/pkg/environment/aws/environment.go +++ b/test/pkg/environment/aws/environment.go @@ -56,9 +56,9 @@ type Environment struct { SQSProvider *interruption.SQSProvider - ClusterName string - ClusterEndpoint string - InterruptionQueueName string + ClusterName string + ClusterEndpoint string + InterruptionQueue string } func NewEnvironment(t *testing.T) *Environment { @@ -86,9 +86,9 @@ func NewEnvironment(t *testing.T) *Environment { SQSProvider: interruption.NewSQSProvider(sqs.New(session)), TimeStreamAPI: GetTimeStreamAPI(session), - ClusterName: lo.Must(os.LookupEnv("CLUSTER_NAME")), - ClusterEndpoint: lo.Must(os.LookupEnv("CLUSTER_ENDPOINT")), - InterruptionQueueName: lo.Must(os.LookupEnv("INTERRUPTION_QUEUE_NAME")), + ClusterName: lo.Must(os.LookupEnv("CLUSTER_NAME")), + ClusterEndpoint: lo.Must(os.LookupEnv("CLUSTER_ENDPOINT")), + InterruptionQueue: lo.Must(os.LookupEnv("INTERRUPTION_QUEUE")), } } diff --git a/test/suites/interruption/suite_test.go b/test/suites/interruption/suite_test.go index f370ba99d16d..0e1fc563efd5 100644 --- a/test/suites/interruption/suite_test.go +++ b/test/suites/interruption/suite_test.go @@ -55,7 +55,7 @@ func TestInterruption(t *testing.T) { var _ = BeforeEach(func() { env.Context = options.ToContext(env.Context, awstest.Options(awstest.OptionsFields{ - InterruptionQueueName: lo.ToPtr(env.InterruptionQueueName), + InterruptionQueue: lo.ToPtr(env.InterruptionQueue), })) env.BeforeEach() env.ExpectQueueExists()