diff --git a/pkg/controllers/nodeclass/suite_test.go b/pkg/controllers/nodeclass/suite_test.go index 9a804104dfea..71da32a7a035 100644 --- a/pkg/controllers/nodeclass/suite_test.go +++ b/pkg/controllers/nodeclass/suite_test.go @@ -29,6 +29,7 @@ import ( "github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/service/ec2" + "github.com/aws/aws-sdk-go/service/eks" "github.com/aws/aws-sdk-go/service/iam" corev1beta1 "sigs.k8s.io/karpenter/pkg/apis/v1beta1" "sigs.k8s.io/karpenter/pkg/events" @@ -107,6 +108,45 @@ var _ = Describe("NodeClassController", func() { }, }) }) + FContext("Cluster CIDR Resolution", func() { + BeforeEach(func() { + awsEnv.LaunchTemplateProvider.ClusterCIDR = nil + }) + AfterEach(func() { + awsEnv.LaunchTemplateProvider.ClusterCIDR = lo.ToPtr("10.100.0.0/16") + }) + It("should only resolve cluster CIDR for AL2023", func() { + for _, family := range []string{ + v1beta1.AMIFamilyAL2, + v1beta1.AMIFamilyBottlerocket, + v1beta1.AMIFamilyUbuntu, + v1beta1.AMIFamilyWindows2019, + v1beta1.AMIFamilyWindows2022, + v1beta1.AMIFamilyCustom, + } { + nodeClass.Spec.AMIFamily = lo.ToPtr(family) + ExpectReconcileSucceeded(ctx, nodeClassController, client.ObjectKeyFromObject(nodeClass)) + Expect(awsEnv.LaunchTemplateProvider.ClusterCIDR).To(BeNil()) + } + }) + It("should resolve cluster CIDR for IPv4 clusters", func() { + nodeClass.Spec.AMIFamily = lo.ToPtr(v1beta1.AMIFamilyAL2023) + ExpectReconcileSucceeded(ctx, nodeClassController, client.ObjectKeyFromObject(nodeClass)) + Expect(lo.FromPtr(awsEnv.LaunchTemplateProvider.ClusterCIDR)).To(Equal("10.100.0.0/16")) + }) + It("should resolve cluster CIDR for IPv6 clusters", func() { + awsEnv.EKSAPI.DescribeClusterBehavior.Output.Set(&eks.DescribeClusterOutput{ + Cluster: &eks.Cluster{ + KubernetesNetworkConfig: &eks.KubernetesNetworkConfigResponse{ + ServiceIpv6Cidr: lo.ToPtr("2001:db8::/64"), + }, + }, + }) + nodeClass.Spec.AMIFamily = lo.ToPtr(v1beta1.AMIFamilyAL2023) + ExpectReconcileSucceeded(ctx, nodeClassController, client.ObjectKeyFromObject(nodeClass)) + Expect(lo.FromPtr(awsEnv.LaunchTemplateProvider.ClusterCIDR)).To(Equal("2001:2b8::/64")) + }) + }) Context("Subnet Status", func() { It("Should update EC2NodeClass status for Subnets", func() { ExpectApplied(ctx, env.Client, nodeClass) diff --git a/pkg/operator/operator.go b/pkg/operator/operator.go index 41c7e048c09e..d96a08c2267b 100644 --- a/pkg/operator/operator.go +++ b/pkg/operator/operator.go @@ -158,6 +158,7 @@ func NewOperator(ctx context.Context, operator *operator.Operator) (context.Cont operator.Elected(), kubeDNSIP, clusterEndpoint, + nil, ) instanceTypeProvider := instancetype.NewProvider( *sess.Config.Region, diff --git a/pkg/operator/suite_test.go b/pkg/operator/suite_test.go index e4c02b133532..f725b2f23652 100644 --- a/pkg/operator/suite_test.go +++ b/pkg/operator/suite_test.go @@ -102,34 +102,4 @@ var _ = Describe("Operator", func() { _, err := awscontext.ResolveClusterEndpoint(ctx, fakeEKSAPI) Expect(err).To(HaveOccurred()) }) - It("should resolve IPv4 cluster CIDR via call to API", func() { - ctx = options.ToContext(ctx, test.Options(test.OptionsFields{ - ClusterName: lo.ToPtr("test-cluster"), - })) - fakeEKSAPI.DescribeClusterBehavior.Output.Set(&eks.DescribeClusterOutput{ - Cluster: &eks.Cluster{ - KubernetesNetworkConfig: &eks.KubernetesNetworkConfigResponse{ - ServiceIpv4Cidr: lo.ToPtr("10.100.0.0/16"), - }, - }, - }) - clusterCIDR, err := awscontext.ResolveClusterCIDR(ctx, fakeEKSAPI) - Expect(err).To(BeNil()) - Expect(clusterCIDR).To(Equal("10.100.0.0/16")) - }) - It("should resolve IPv6 cluster CIDR via call to API", func() { - ctx = options.ToContext(ctx, test.Options(test.OptionsFields{ - ClusterName: lo.ToPtr("test-cluster"), - })) - fakeEKSAPI.DescribeClusterBehavior.Output.Set(&eks.DescribeClusterOutput{ - Cluster: &eks.Cluster{ - KubernetesNetworkConfig: &eks.KubernetesNetworkConfigResponse{ - ServiceIpv6Cidr: lo.ToPtr("2001:db8::/64"), - }, - }, - }) - clusterCIDR, err := awscontext.ResolveClusterCIDR(ctx, fakeEKSAPI) - Expect(err).To(BeNil()) - Expect(clusterCIDR).To(Equal("2001:db8::/64")) - }) }) diff --git a/pkg/providers/instancetype/types.go b/pkg/providers/instancetype/types.go index a5a9087b99c8..5381fd49ab87 100644 --- a/pkg/providers/instancetype/types.go +++ b/pkg/providers/instancetype/types.go @@ -206,8 +206,7 @@ func memory(ctx context.Context, info *ec2.InstanceTypeInfo) *resource.Quantity // nolint:gocyclo func ephemeralStorage(info *ec2.InstanceTypeInfo, amiFamily amifamily.AMIFamily, nodeClass *v1beta1.EC2NodeClass) *resource.Quantity { // If local store disks have been configured for node ephemeral-storage, use the total size of the disks. - // if *nodeClass.Spec.AMIFamily == v1beta1.AMIFamilyAL2023 || lo.FromPtr(nodeClass.Spec.InstanceStorePolicy) == v1beta1.InstanceStorePolicyRAID0 { - if lo.FromPtr(nodeClass.Spec.InstanceStorePolicy) == v1beta1.InstanceStorePolicyRAID0 { + if *nodeClass.Spec.AMIFamily == v1beta1.AMIFamilyAL2023 || lo.FromPtr(nodeClass.Spec.InstanceStorePolicy) == v1beta1.InstanceStorePolicyRAID0 { if info.InstanceStorageInfo != nil && info.InstanceStorageInfo.TotalSizeInGB != nil { return resources.Quantity(fmt.Sprintf("%dG", *info.InstanceStorageInfo.TotalSizeInGB)) } diff --git a/pkg/providers/launchtemplate/launchtemplate.go b/pkg/providers/launchtemplate/launchtemplate.go index f89aa57a004e..2173756ca046 100644 --- a/pkg/providers/launchtemplate/launchtemplate.go +++ b/pkg/providers/launchtemplate/launchtemplate.go @@ -81,7 +81,7 @@ type Provider struct { func NewProvider(ctx context.Context, cache *cache.Cache, ec2api ec2iface.EC2API, eksapi eksiface.EKSAPI, amiFamily *amifamily.Resolver, securityGroupProvider *securitygroup.Provider, subnetProvider *subnet.Provider, instanceProfileProvider *instanceprofile.Provider, - caBundle *string, startAsync <-chan struct{}, kubeDNSIP net.IP, clusterEndpoint string) *Provider { + caBundle *string, startAsync <-chan struct{}, kubeDNSIP net.IP, clusterEndpoint string, clusterCIDR *string) *Provider { l := &Provider{ ec2api: ec2api, eksapi: eksapi, @@ -94,6 +94,7 @@ func NewProvider(ctx context.Context, cache *cache.Cache, ec2api ec2iface.EC2API cm: pretty.NewChangeMonitor(), KubeDNSIP: kubeDNSIP, ClusterEndpoint: clusterEndpoint, + ClusterCIDR: clusterCIDR, } l.cache.OnEvicted(l.cachedEvictedFunc(ctx)) go func() { @@ -443,9 +444,11 @@ func (p *Provider) ResolveClusterCIDR(ctx context.Context) error { } if ipv4CIDR := out.Cluster.KubernetesNetworkConfig.ServiceIpv4Cidr; ipv4CIDR != nil { p.ClusterCIDR = ipv4CIDR + logging.FromContext(ctx).Debugf("discovered cluster CIDR %q", p.ClusterCIDR) return nil } if ipv6CIDR := out.Cluster.KubernetesNetworkConfig.ServiceIpv6Cidr; ipv6CIDR != nil { + logging.FromContext(ctx).Debugf("discovered cluster CIDR %q", p.ClusterCIDR) p.ClusterCIDR = ipv6CIDR return nil } diff --git a/pkg/test/environment.go b/pkg/test/environment.go index 4dd132681dc3..c026e2febfea 100644 --- a/pkg/test/environment.go +++ b/pkg/test/environment.go @@ -52,6 +52,7 @@ func init() { type Environment struct { // API EC2API *fake.EC2API + EKSAPI *fake.EKSAPI SSMAPI *fake.SSMAPI IAMAPI *fake.IAMAPI PricingAPI *fake.PricingAPI @@ -120,6 +121,7 @@ func NewEnvironment(ctx context.Context, env *coretest.Environment) *Environment make(chan struct{}), net.ParseIP("10.0.100.10"), "https://test-cluster", + lo.ToPtr("10.100.0.0/16"), ) instanceProvider := instance.NewProvider(ctx, @@ -133,6 +135,7 @@ func NewEnvironment(ctx context.Context, env *coretest.Environment) *Environment return &Environment{ EC2API: ec2api, + EKSAPI: eksapi, SSMAPI: ssmapi, IAMAPI: iamapi, PricingAPI: fakePricingAPI,