Skip to content

Commit 86e25ab

Browse files
Merge pull request #116 from mtulio/OCPBUGS-44373
OCPBUGS-44373: fix Associate*IpAddress flag when launch EC2
2 parents ae84f36 + 9cc233f commit 86e25ab

File tree

2 files changed

+20
-12
lines changed

2 files changed

+20
-12
lines changed

pkg/actuators/machine/instances.go

+11-5
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,10 @@ import (
2222
runtimeclient "sigs.k8s.io/controller-runtime/pkg/client"
2323
)
2424

25+
const (
26+
zoneTypeWavelengthZone = "wavelength-zone"
27+
)
28+
2529
// Scan machine tags, and return a deduped tags list. The first found value gets precedence.
2630
func removeDuplicatedTags(tags []*ec2.Tag) []*ec2.Tag {
2731
m := make(map[string]bool)
@@ -368,10 +372,12 @@ func launchInstance(machine *machinev1beta1.Machine, machineProviderConfig *mach
368372
Groups: securityGroupsIDs,
369373
},
370374
}
371-
// Public IP assignment is different in Wavelength Zones.
372-
// AvailabilityZone and LocalZone uses InternetGateway.
373-
// WavelengthZone uses Carrier Gateway.
374-
if aws.BoolValue(machineProviderConfig.PublicIP) {
375+
376+
// Public IP address assignment to instances created in Wavelength
377+
// Zones' subnet requires the attribute AssociateCarrierIpAddress
378+
// instead of AssociatePublicIpAddress.
379+
// AssociatePublicIpAddress and AssociateCarrierIpAddress are mutually exclusive.
380+
if machineProviderConfig.PublicIP != nil {
375381
zoneName, err := getAvalabilityZoneFromSubnetID(*subnetID, awsClient)
376382
if err != nil {
377383
return nil, mapierrors.InvalidMachineConfiguration("error discoverying zone type: %v", err)
@@ -381,7 +387,7 @@ func launchInstance(machine *machinev1beta1.Machine, machineProviderConfig *mach
381387
return nil, mapierrors.InvalidMachineConfiguration("error discoverying zone type: %v", err)
382388
}
383389

384-
if zoneType == "wavelength-zone" {
390+
if zoneType == zoneTypeWavelengthZone {
385391
networkInterfaces[0].AssociateCarrierIpAddress = machineProviderConfig.PublicIP
386392
} else {
387393
networkInterfaces[0].AssociatePublicIpAddress = machineProviderConfig.PublicIP

pkg/actuators/machine/instances_test.go

+9-7
Original file line numberDiff line numberDiff line change
@@ -1095,8 +1095,8 @@ func TestLaunchInstance(t *testing.T) {
10951095
}},
10961096
NetworkInterfaces: []*ec2.InstanceNetworkInterfaceSpecification{
10971097
{
1098-
DeviceIndex: aws.Int64(providerConfig.DeviceIndex),
10991098
AssociateCarrierIpAddress: aws.Bool(true),
1099+
DeviceIndex: aws.Int64(providerConfig.DeviceIndex),
11001100
SubnetId: aws.String(stubSubnetID),
11011101
Groups: stubSecurityGroupsDefault,
11021102
},
@@ -1133,9 +1133,10 @@ func TestLaunchInstance(t *testing.T) {
11331133
}},
11341134
NetworkInterfaces: []*ec2.InstanceNetworkInterfaceSpecification{
11351135
{
1136-
DeviceIndex: aws.Int64(providerConfig.DeviceIndex),
1137-
SubnetId: aws.String(stubSubnetID),
1138-
Groups: stubSecurityGroupsDefault,
1136+
AssociateCarrierIpAddress: aws.Bool(false),
1137+
DeviceIndex: aws.Int64(providerConfig.DeviceIndex),
1138+
SubnetId: aws.String(stubSubnetID),
1139+
Groups: stubSecurityGroupsDefault,
11391140
},
11401141
},
11411142
UserData: aws.String(""),
@@ -1169,9 +1170,10 @@ func TestLaunchInstance(t *testing.T) {
11691170
}},
11701171
NetworkInterfaces: []*ec2.InstanceNetworkInterfaceSpecification{
11711172
{
1172-
DeviceIndex: aws.Int64(providerConfig.DeviceIndex),
1173-
SubnetId: aws.String(stubSubnetID),
1174-
Groups: stubSecurityGroupsDefault,
1173+
AssociatePublicIpAddress: aws.Bool(false),
1174+
DeviceIndex: aws.Int64(providerConfig.DeviceIndex),
1175+
SubnetId: aws.String(stubSubnetID),
1176+
Groups: stubSecurityGroupsDefault,
11751177
},
11761178
},
11771179
UserData: aws.String(""),

0 commit comments

Comments
 (0)