Accept non-IP as KUBERNETES_SERVICE_HOST
KUBERNETES_SERVICE_HOST environment variable that we use to connect to
Kubernetes API might also be a bare hostname instead of IPv4/IPv6
address. This commit makes sure such a case is supported.
@@ -83,9 +83,13 @@ def setup_kubernetes_client():
# K8s Pods.
host = os.environ['KUBERNETES_SERVICE_HOST']
port = os.environ['KUBERNETES_SERVICE_PORT_HTTPS']
+ try:
addr = ipaddress.ip_address(host)
if addr.version == 6:
host = '[%s]' % host
+ except ValueError:
+ # It's not an IP addres but a hostname, it's fine, move along.
+ pass
api_root = "https://%s:%s" % (host, port)
_clients[_KUBERNETES_CLIENT] = k8s_client.K8sClient(api_root)
