Skip to content

Commit 825f8ca

Browse files
damdok8s-infra-cherrypick-robot
authored and
k8s-infra-cherrypick-robot
committed
fix: check for nil matching subnet when publicIP is set
1 parent bee26e8 commit 825f8ca

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

pkg/cloud/services/ec2/instances.go

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -352,9 +352,17 @@ func (s *Service) findSubnet(scope *scope.MachineScope) (string, error) {
352352
*subnet.SubnetId, *subnet.AvailabilityZone, *failureDomain)
353353
continue
354354
}
355-
if scope.AWSMachine.Spec.PublicIP != nil && *scope.AWSMachine.Spec.PublicIP && !s.scope.Subnets().FindByID(*subnet.SubnetId).IsPublic {
356-
errMessage += fmt.Sprintf(" subnet %q is a private subnet.", *subnet.SubnetId)
357-
continue
355+
356+
if ptr.Deref(scope.AWSMachine.Spec.PublicIP, false) {
357+
matchingSubnet := s.scope.Subnets().FindByID(*subnet.SubnetId)
358+
if matchingSubnet == nil {
359+
errMessage += fmt.Sprintf(" unable to find subnet %q among the AWSCluster subnets.", *subnet.SubnetId)
360+
continue
361+
}
362+
if !matchingSubnet.IsPublic {
363+
errMessage += fmt.Sprintf(" subnet %q is a private subnet.", *subnet.SubnetId)
364+
continue
365+
}
358366
}
359367
filtered = append(filtered, subnet)
360368
}

0 commit comments

Comments
 (0)