Skip to content

Commit 57d87ba

Browse files
committed
vpc: ipam pool under vpc.ipv6 should be used for VPC IPv6 CIDR
The field awscluster.spec.network.vpc.ipv6.ipamPool defines the IPAM pool to allocate an IPv6 CIDR for the VPC. Previously, CAPA only considers field awscluster.spec.network.vpc.ipamPool, which is used only for VPC IPv4 CIDR allocation. Additionally, CAPA should preserve the ipv6 spec fields, provided by the users, for example, the ipv6 ipamPool. Previously, these spec fields are lost during vpc reconcilation.
1 parent e0c6232 commit 57d87ba

File tree

1 file changed

+19
-9
lines changed
  • pkg/cloud/services/network

1 file changed

+19
-9
lines changed

pkg/cloud/services/network/vpc.go

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,10 @@ func (s *Service) reconcileVPC() error {
5858

5959
s.scope.VPC().CidrBlock = vpc.CidrBlock
6060
if s.scope.VPC().IsIPv6Enabled() {
61+
if vpc.IPv6 != nil {
62+
// Preserve spec fields are not available when describing vpcs
63+
vpc.IPv6.IPAMPool = s.scope.VPC().IPv6.IPAMPool
64+
}
6165
s.scope.VPC().IPv6 = vpc.IPv6
6266
}
6367
if s.scope.TagUnmanagedNetworkResources() {
@@ -107,7 +111,6 @@ func (s *Service) reconcileVPC() error {
107111

108112
// .spec.vpc.id is nil. This means no managed VPC exists or we failed to save its ID before. Check if a managed VPC
109113
// with the desired name exists, or if not, create a new managed VPC.
110-
111114
vpc, err := s.describeVPCByName()
112115
if err == nil {
113116
// An VPC already exists with the desired name
@@ -133,10 +136,17 @@ func (s *Service) reconcileVPC() error {
133136
}
134137

135138
s.scope.VPC().CidrBlock = vpc.CidrBlock
136-
s.scope.VPC().IPv6 = vpc.IPv6
137139
s.scope.VPC().Tags = vpc.Tags
138140
s.scope.VPC().ID = vpc.ID
139141

142+
if s.scope.VPC().IsIPv6Enabled() {
143+
if vpc.IPv6 != nil {
144+
// Preserve spec fields are not available when describing vpcs
145+
vpc.IPv6.IPAMPool = s.scope.VPC().IPv6.IPAMPool
146+
}
147+
s.scope.VPC().IPv6 = vpc.IPv6
148+
}
149+
140150
if !conditions.Has(s.scope.InfraCluster(), infrav1.VpcReadyCondition) {
141151
conditions.MarkFalse(s.scope.InfraCluster(), infrav1.VpcReadyCondition, infrav1.VpcCreationStartedReason, clusterv1.ConditionSeverityInfo, "")
142152
if err := s.scope.PatchObject(); err != nil {
@@ -382,15 +392,15 @@ func (s *Service) ensureManagedVPCAttributes(vpc *infrav1.VPCSpec) error {
382392
return nil
383393
}
384394

385-
func (s *Service) getIPAMPoolID() (*string, error) {
395+
func (s *Service) getIPAMPoolID(ipamPool *infrav1.IPAMPool) (*string, error) {
386396
input := &ec2.DescribeIpamPoolsInput{}
387397

388-
if s.scope.VPC().IPAMPool.ID != "" {
389-
input.Filters = append(input.Filters, filter.EC2.IPAM(s.scope.VPC().IPAMPool.ID))
398+
if ipamPool.ID != "" {
399+
input.Filters = append(input.Filters, filter.EC2.IPAM(ipamPool.ID))
390400
}
391401

392-
if s.scope.VPC().IPAMPool.Name != "" {
393-
input.Filters = append(input.Filters, filter.EC2.Name(s.scope.VPC().IPAMPool.Name))
402+
if ipamPool.Name != "" {
403+
input.Filters = append(input.Filters, filter.EC2.Name(ipamPool.Name))
394404
}
395405

396406
output, err := s.EC2Client.DescribeIpamPools(context.TODO(), input)
@@ -426,7 +436,7 @@ func (s *Service) createVPC() (*infrav1.VPCSpec, error) {
426436
input.Ipv6Pool = aws.String(s.scope.VPC().IPv6.PoolID)
427437
input.AmazonProvidedIpv6CidrBlock = aws.Bool(false)
428438
case s.scope.VPC().IPv6.IPAMPool != nil:
429-
ipamPoolID, err := s.getIPAMPoolID()
439+
ipamPoolID, err := s.getIPAMPoolID(s.scope.VPC().IPv6.IPAMPool)
430440
if err != nil {
431441
return nil, errors.Wrap(err, "failed to get IPAM Pool ID")
432442
}
@@ -444,7 +454,7 @@ func (s *Service) createVPC() (*infrav1.VPCSpec, error) {
444454

445455
// IPv4-specific configuration
446456
if s.scope.VPC().IPAMPool != nil {
447-
ipamPoolID, err := s.getIPAMPoolID()
457+
ipamPoolID, err := s.getIPAMPoolID(s.scope.VPC().IPAMPool)
448458
if err != nil {
449459
return nil, errors.Wrap(err, "failed to get IPAM Pool ID")
450460
}

0 commit comments

Comments
 (0)