From 2a806dc1e91c18cce313563002985a1e7210fc30 Mon Sep 17 00:00:00 2001 From: Aakcht Date: Mon, 23 Dec 2019 18:09:15 +0300 Subject: [PATCH] IPv6 addres parsing in KubeConfig.from_service_account (#50) * IPv6 parsing in from_service_account * using "format" instead of "%" --- pykube/config.py | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/pykube/config.py b/pykube/config.py index 981e5ec..3268923 100644 --- a/pykube/config.py +++ b/pykube/config.py @@ -12,6 +12,15 @@ from pykube import exceptions +def _join_host_port(host, port): + """Adapted golang's net.JoinHostPort""" + template = "{}:{}" + host_requires_bracketing = ':' in host or '%' in host + if host_requires_bracketing: + template = "[{}]:{}" + return template.format(host, port) + + class KubeConfig: """ Main configuration class. @@ -36,7 +45,7 @@ def from_service_account(cls, path="/var/run/secrets/kubernetes.io/serviceaccoun { "name": "self", "cluster": { - "server": "https://{}:{}".format(host, port), + "server": "https://" + _join_host_port(host, port), "certificate-authority": os.path.join(path, "ca.crt"), }, },