Skip to content
This repository was archived by the owner on Oct 3, 2020. It is now read-only.

Commit 2a806dc

Browse files
Aakchthjacobs
authored andcommitted
IPv6 addres parsing in KubeConfig.from_service_account (#50)
* IPv6 parsing in from_service_account * using "format" instead of "%"
1 parent 8cfc074 commit 2a806dc

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

pykube/config.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,15 @@
1212
from pykube import exceptions
1313

1414

15+
def _join_host_port(host, port):
16+
"""Adapted golang's net.JoinHostPort"""
17+
template = "{}:{}"
18+
host_requires_bracketing = ':' in host or '%' in host
19+
if host_requires_bracketing:
20+
template = "[{}]:{}"
21+
return template.format(host, port)
22+
23+
1524
class KubeConfig:
1625
"""
1726
Main configuration class.
@@ -36,7 +45,7 @@ def from_service_account(cls, path="/var/run/secrets/kubernetes.io/serviceaccoun
3645
{
3746
"name": "self",
3847
"cluster": {
39-
"server": "https://{}:{}".format(host, port),
48+
"server": "https://" + _join_host_port(host, port),
4049
"certificate-authority": os.path.join(path, "ca.crt"),
4150
},
4251
},

0 commit comments

Comments
 (0)