Skip to content

Commit

Permalink
Merge pull request #619 from nikhiljha/v6-addr-fmt
Browse files Browse the repository at this point in the history
properly handle IPv6 IPs
  • Loading branch information
minrk committed Aug 10, 2022
2 parents 564111c + e4c2aa8 commit 9f31d48
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
3 changes: 3 additions & 0 deletions kubespawner/spawner.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
implementation that should be used by JupyterHub.
"""
import asyncio
import ipaddress
import os
import string
import sys
Expand Down Expand Up @@ -1934,6 +1935,8 @@ def _get_pod_url(self, pod):
else:
proto = "http"
hostname = pod["status"]["podIP"]
if isinstance(ipaddress.ip_address(hostname), ipaddress.IPv6Address):
hostname = f"[{hostname}]"

if self.pod_connect_ip:
hostname = ".".join(
Expand Down
12 changes: 12 additions & 0 deletions tests/test_spawner.py
Original file line number Diff line number Diff line change
Expand Up @@ -802,3 +802,15 @@ async def test_delete_pvc(kube_ns, kube_client, hub, config):
else:
break
assert pvc_name not in pvc_names


async def test_ipv6_addr():
"""make sure ipv6 addresses are templated into URL correctly"""
# https://github.com/jupyterhub/jupyterhub/pull/3020
# https://github.com/jupyterhub/kubespawner/pull/619

spawner = KubeSpawner(
_mock=True,
)
url = spawner._get_pod_url({"status": {"podIP": "cafe:f00d::"}})
assert "[" in url and "]" in url

0 comments on commit 9f31d48

Please sign in to comment.