Skip to content

Commit

Permalink
Merge pull request #5007 from k8s-infra-cherrypick-robot/cherry-pick-…
Browse files Browse the repository at this point in the history
…4988-to-release-2.5

[release-2.5] 🐛 fix: check for nil matching subnet when publicIP: true
  • Loading branch information
k8s-ci-robot authored Jun 10, 2024
2 parents bee26e8 + 825f8ca commit 3b350ef
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions pkg/cloud/services/ec2/instances.go
Original file line number Diff line number Diff line change
Expand Up @@ -352,9 +352,17 @@ func (s *Service) findSubnet(scope *scope.MachineScope) (string, error) {
*subnet.SubnetId, *subnet.AvailabilityZone, *failureDomain)
continue
}
if scope.AWSMachine.Spec.PublicIP != nil && *scope.AWSMachine.Spec.PublicIP && !s.scope.Subnets().FindByID(*subnet.SubnetId).IsPublic {
errMessage += fmt.Sprintf(" subnet %q is a private subnet.", *subnet.SubnetId)
continue

if ptr.Deref(scope.AWSMachine.Spec.PublicIP, false) {
matchingSubnet := s.scope.Subnets().FindByID(*subnet.SubnetId)
if matchingSubnet == nil {
errMessage += fmt.Sprintf(" unable to find subnet %q among the AWSCluster subnets.", *subnet.SubnetId)
continue
}
if !matchingSubnet.IsPublic {
errMessage += fmt.Sprintf(" subnet %q is a private subnet.", *subnet.SubnetId)
continue
}
}
filtered = append(filtered, subnet)
}
Expand Down

0 comments on commit 3b350ef

Please sign in to comment.