diff --git a/pkg/providers/launchtemplate/launchtemplate.go b/pkg/providers/launchtemplate/launchtemplate.go index 13fdd748c068..6d92c2f61f21 100644 --- a/pkg/providers/launchtemplate/launchtemplate.go +++ b/pkg/providers/launchtemplate/launchtemplate.go @@ -287,25 +287,22 @@ func (p *DefaultProvider) generateNetworkInterfaces(options *amifamily.LaunchTem // with a single EFA network interface, and we should support those use cases. Launch failures with multiple enis should be considered user misconfiguration. AssociatePublicIpAddress: options.AssociatePublicIPAddress, PrimaryIpv6: lo.Ternary(p.ClusterIPFamily == corev1.IPv6Protocol, lo.ToPtr(true), nil), - Ipv6PrefixCount: lo.Ternary(p.ClusterIPFamily == corev1.IPv6Protocol, lo.ToPtr(int32(1)), nil), + Ipv6AddressCount: lo.Ternary(p.ClusterIPFamily == corev1.IPv6Protocol, lo.ToPtr(int32(1)), nil), } }) } - if options.AssociatePublicIPAddress != nil { - return []ec2types.LaunchTemplateInstanceNetworkInterfaceSpecificationRequest{ - { - AssociatePublicIpAddress: options.AssociatePublicIPAddress, - DeviceIndex: aws.Int32(0), - Groups: lo.Map(options.SecurityGroups, func(s v1.SecurityGroup, _ int) string { - return s.ID - }), - PrimaryIpv6: lo.Ternary(p.ClusterIPFamily == corev1.IPv6Protocol, lo.ToPtr(true), nil), - Ipv6PrefixCount: lo.Ternary(p.ClusterIPFamily == corev1.IPv6Protocol, lo.ToPtr(int32(1)), nil), - }, - } + return []ec2types.LaunchTemplateInstanceNetworkInterfaceSpecificationRequest{ + { + AssociatePublicIpAddress: options.AssociatePublicIPAddress, + DeviceIndex: aws.Int32(0), + Groups: lo.Map(options.SecurityGroups, func(s v1.SecurityGroup, _ int) string { + return s.ID + }), + PrimaryIpv6: lo.Ternary(p.ClusterIPFamily == corev1.IPv6Protocol, lo.ToPtr(true), nil), + Ipv6AddressCount: lo.Ternary(p.ClusterIPFamily == corev1.IPv6Protocol, lo.ToPtr(int32(1)), nil), + }, } - return nil } func (p *DefaultProvider) blockDeviceMappings(blockDeviceMappings []*v1.BlockDeviceMapping) []ec2types.LaunchTemplateBlockDeviceMappingRequest { diff --git a/pkg/providers/launchtemplate/suite_test.go b/pkg/providers/launchtemplate/suite_test.go index bddfc1e56e09..32a9a1a40c65 100644 --- a/pkg/providers/launchtemplate/suite_test.go +++ b/pkg/providers/launchtemplate/suite_test.go @@ -2263,17 +2263,20 @@ essential = true ExpectProvisioned(ctx, env.Client, cluster, cloudProvider, prov, pod) ExpectScheduled(ctx, env.Client, pod) input := awsEnv.EC2API.CalledWithCreateLaunchTemplateInput.Pop() - if isPublicAddressSet { - Expect(lo.FromPtr(input.LaunchTemplateData.NetworkInterfaces[0].AssociatePublicIpAddress)).To(Equal(isPublic)) - Expect(lo.FromPtr(input.LaunchTemplateData.NetworkInterfaces[0].Ipv6PrefixCount)).To(Equal(int32(1))) - Expect(lo.FromPtr(input.LaunchTemplateData.NetworkInterfaces[0].PrimaryIpv6)).To(BeTrue()) - } else if !isEFA { - Expect(input.LaunchTemplateData.NetworkInterfaces).To(HaveLen(0)) + + Expect(len(input.LaunchTemplateData.NetworkInterfaces)).To(BeNumerically(">=", 1)) + if !isPublicAddressSet && !isEFA { + Expect(lo.FromPtr(input.LaunchTemplateData.NetworkInterfaces[0].AssociatePublicIpAddress)).To(BeNil()) } else { + Expect(lo.FromPtr(input.LaunchTemplateData.NetworkInterfaces[0].AssociatePublicIpAddress)).To(BeTrue()) + } + if isEFA { Expect(lo.FromPtr(input.LaunchTemplateData.NetworkInterfaces[0].InterfaceType)).To(Equal(string(ec2types.NetworkInterfaceTypeEfa))) - Expect(lo.FromPtr(input.LaunchTemplateData.NetworkInterfaces[0].Ipv6PrefixCount)).To(Equal(int32(1))) - Expect(lo.FromPtr(input.LaunchTemplateData.NetworkInterfaces[0].PrimaryIpv6)).To(BeTrue()) + Expect(lo.FromPtr(input.LaunchTemplateData.NetworkInterfaces[0].AssociatePublicIpAddress)).To(Equal(BeTrue())) } + Expect(lo.FromPtr(input.LaunchTemplateData.NetworkInterfaces[0].Ipv6AddressCount)).To(Equal(int32(1))) + Expect(lo.FromPtr(input.LaunchTemplateData.NetworkInterfaces[0].PrimaryIpv6)).To(BeTrue()) + }, Entry("AssociatePublicIPAddress is not set and EFA is false", false, true, false), Entry("AssociatePublicIPAddress is not set and EFA is true", false, false, true), diff --git a/test/suites/ipv6/suite_test.go b/test/suites/ipv6/suite_test.go index b1af9ef75bc0..b8c6de69ddb2 100644 --- a/test/suites/ipv6/suite_test.go +++ b/test/suites/ipv6/suite_test.go @@ -20,10 +20,7 @@ import ( "github.com/samber/lo" corev1 "k8s.io/api/core/v1" - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "k8s.io/client-go/util/retry" - "sigs.k8s.io/controller-runtime/pkg/client" karpv1 "sigs.k8s.io/karpenter/pkg/apis/v1" coretest "sigs.k8s.io/karpenter/pkg/test" @@ -102,10 +99,6 @@ var _ = Describe("IPv6", func() { It("should provision a static IPv6 prefix with node launch and set IPv6 as primary in the primary network interface", func() { clusterDNSAddr := env.ExpectIPv6ClusterDNS() nodeClass.Spec.Kubelet = &v1.KubeletConfiguration{ClusterDNS: []string{clusterDNSAddr}} - Expect(disableVPCCNIProvisioning(true)).To(Succeed()) - DeferCleanup(func() { - Expect(disableVPCCNIProvisioning(false)).To(Succeed()) - }) pod := coretest.Pod() env.ExpectCreated(pod, nodeClass, nodePool) env.EventuallyExpectHealthy(pod) @@ -113,42 +106,10 @@ var _ = Describe("IPv6", func() { node := env.GetNode(pod.Spec.NodeName) instance := env.GetInstanceByID(env.ExpectParsedProviderID(node.Spec.ProviderID)) Expect(instance.NetworkInterfaces).To(HaveLen(1)) - Expect(instance.NetworkInterfaces[0].Ipv6Prefixes).To(HaveLen(1)) + Expect(instance.NetworkInterfaces[0].Ipv6Addresses).To(HaveLen(1)) _, hasIPv6Primary := lo.Find(instance.NetworkInterfaces[0].Ipv6Addresses, func(ip types.InstanceIpv6Address) bool { return lo.FromPtr(ip.IsPrimaryIpv6) }) Expect(hasIPv6Primary).To(BeTrue()) }) }) - -// disable VPC CNI provisioning on network interfaces and IPs -func disableVPCCNIProvisioning(disable bool) error { - dsClient := env.KubeClient.AppsV1().DaemonSets("kube-system") - retryErr := retry.OnError( - retry.DefaultRetry, - func(err error) bool { - return true - }, - func() error { - awsNode, getErr := dsClient.Get(env.Context, "aws-node", metav1.GetOptions{}) - if getErr != nil { - return getErr - } - - for i := range awsNode.Spec.Template.Spec.Containers { - if awsNode.Spec.Template.Spec.Containers[i].Name == "aws-node" { - for j := range awsNode.Spec.Template.Spec.Containers[i].Env { - if awsNode.Spec.Template.Spec.Containers[i].Env[j].Name == "DISABLE_NETWORK_RESOURCE_PROVISIONING" { - awsNode.Spec.Template.Spec.Containers[i].Env[j].Value = lo.Ternary(disable, "true", "false") - } - } - } - } - - _, updateErr := dsClient.Update(env.Context, awsNode, metav1.UpdateOptions{}) - return updateErr - }, - ) - // ignore AWS VPC CNI is not installed - return client.IgnoreNotFound(retryErr) -}