mirror of https://github.com/k3s-io/k3s
Merge pull request #64318 from gonzolino/os-lbaas-addresses
Automatic merge from submit-queue (batch tested with PRs 64318, 64269, 64438, 64516, 64311). If you want to cherry-pick this change to another branch, please follow the instructions <a href="https://github.com/kubernetes/community/blob/master/contributors/devel/cherry-picks.md">here</a>. Ensure that only IPs are used as node addresses in OpenStack LBs **What this PR does / why we need it**: ATM, when no InternalIP can be found for a node, the openstack cloud provider tries to create a LB with whatever is the first address it can find for the node. This could also be the hostname or a dns name. However, LBaaS will reject anything that is not an IP address for pool members. Therefore a meaningful error should be returned instead of just returning the first address of the node, even if it is clear that this will lead to an error in LBaaS. **Which issue(s) this PR fixes** *(optional, in `fixes #<issue number>(, fixes #<issue_number>, ...)` format, will close the issue(s) when PR gets merged)*: Fixes #64317 **Special notes for your reviewer**: **Release note**: ```release-note Provide a meaningful error message in openstack cloud provider when no valid IP address can be found for a node ```pull/8/head
commit
5aa513429b
|
@ -487,21 +487,27 @@ func (lbaas *LbaasV2) GetLoadBalancer(ctx context.Context, clusterName string, s
|
|||
|
||||
// The LB needs to be configured with instance addresses on the same
|
||||
// subnet as the LB (aka opts.SubnetID). Currently we're just
|
||||
// guessing that the node's InternalIP is the right address - and that
|
||||
// should be sufficient for all "normal" cases.
|
||||
// guessing that the node's InternalIP is the right address.
|
||||
// In case no InternalIP can be found, ExternalIP is tried.
|
||||
// If neither InternalIP nor ExternalIP can be found an error is
|
||||
// returned.
|
||||
func nodeAddressForLB(node *v1.Node) (string, error) {
|
||||
addrs := node.Status.Addresses
|
||||
if len(addrs) == 0 {
|
||||
return "", ErrNoAddressFound
|
||||
}
|
||||
|
||||
for _, addr := range addrs {
|
||||
if addr.Type == v1.NodeInternalIP {
|
||||
return addr.Address, nil
|
||||
allowedAddrTypes := []v1.NodeAddressType{v1.NodeInternalIP, v1.NodeExternalIP}
|
||||
|
||||
for _, allowedAddrType := range allowedAddrTypes {
|
||||
for _, addr := range addrs {
|
||||
if addr.Type == allowedAddrType {
|
||||
return addr.Address, nil
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return addrs[0].Address, nil
|
||||
return "", ErrNoAddressFound
|
||||
}
|
||||
|
||||
//getStringFromServiceAnnotation searches a given v1.Service for a specific annotationKey and either returns the annotation's value or a specified defaultSetting
|
||||
|
|
Loading…
Reference in New Issue