Skip to content

Commit

Permalink
Merge pull request #4988 from damdo/fix-publicip-subnet-panic
Browse files Browse the repository at this point in the history
🐛 fix: check for nil matching subnet when publicIP: true
  • Loading branch information
k8s-ci-robot committed May 28, 2024
2 parents cc606cf + cf204c7 commit b2fae56
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 b2fae56

Please sign in to comment.