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:
Walter Fender
2018-12-07 11:31:19 -08:00
parent 05183bffe5
commit d92ee41e44
3 changed files with 39 additions and 1 deletions

View File

@@ -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: