mirror of https://github.com/k3s-io/k3s
Ensure that only IPs are used as node addresses in OpenStack LBs
parent
481b2dc7cf
commit
7b5f3a1dc5
|
@ -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
|
||||
}
|
||||
|
||||
allowedAddrTypes := []v1.NodeAddressType{v1.NodeInternalIP, v1.NodeExternalIP}
|
||||
|
||||
for _, allowedAddrType := range allowedAddrTypes {
|
||||
for _, addr := range addrs {
|
||||
if addr.Type == v1.NodeInternalIP {
|
||||
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