mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-09-20 09:33:52 +00:00
Fix issue where missing external IP address breaks SSH Tunnel.
Added unit test to cover missing external IP case. Justin's feedback. Lint fix. Lavalmap's feedback.
This commit is contained in:
@@ -64,6 +64,17 @@ func GetHostname(hostnameOverride string) (string, error) {
|
||||
return strings.ToLower(hostName), nil
|
||||
}
|
||||
|
||||
// NoMatchError is a typed implementation of the error interface. It indicates a failure to get a matching Node.
|
||||
type NoMatchError struct {
|
||||
addresses []v1.NodeAddress
|
||||
}
|
||||
|
||||
// Error is the implementation of the conventional interface for
|
||||
// representing an error condition, with the nil value representing no error.
|
||||
func (e *NoMatchError) Error() string {
|
||||
return fmt.Sprintf("no preferred addresses found; known addresses: %v", e.addresses)
|
||||
}
|
||||
|
||||
// GetPreferredNodeAddress returns the address of the provided node, using the provided preference order.
|
||||
// If none of the preferred address types are found, an error is returned.
|
||||
func GetPreferredNodeAddress(node *v1.Node, preferredAddressTypes []v1.NodeAddressType) (string, error) {
|
||||
@@ -74,7 +85,7 @@ func GetPreferredNodeAddress(node *v1.Node, preferredAddressTypes []v1.NodeAddre
|
||||
}
|
||||
}
|
||||
}
|
||||
return "", fmt.Errorf("no preferred addresses found; known addresses: %v", node.Status.Addresses)
|
||||
return "", &NoMatchError{addresses: node.Status.Addresses}
|
||||
}
|
||||
|
||||
// GetNodeHostIP returns the provided node's IP, based on the priority:
|
||||
|
Reference in New Issue
Block a user