Skip to content

Commit

Permalink
Force use of IP other than 127.0.0.1 for localhost
Browse files Browse the repository at this point in the history
and overwrite Helm chart with the provided IP address.
  • Loading branch information
rgaiacs committed Jan 9, 2025
1 parent 807c0a7 commit 3f76268
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 3 deletions.
5 changes: 4 additions & 1 deletion config/localhost.yaml
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
# 127.0.0.1.nip.io will not work because when pods try to use it,
# the domain will resolve to the pod itself.
# The deploy.py overwrite the 127.0.0.1 to the user IP address.
binderhub:
config:
BinderHub:
# Use Kubernetes DNS
hub_url: http://hub:8081
hub_url: http://jupyterhub.127.0.0.1.nip.io
use_registry: false

extraConfig:
Expand Down
19 changes: 17 additions & 2 deletions deploy.py
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ def get_config_files(release, config_dir="config"):
return config_files


def deploy(release, name=None, dry_run=False, diff=False):
def deploy(release, name=None, dry_run=False, diff=False, ip_address=None):
"""Deploys a federation member to a k8s cluster.
Waits for deployments and daemonsets to become Ready
Expand Down Expand Up @@ -238,6 +238,14 @@ def deploy(release, name=None, dry_run=False, diff=False):
for config_file in config_files:
helm.extend(["-f", config_file])

if release == "localhost":
helm.extend([
"--set", f"binderhub.config.BinderHub.hub_url=http://jupyterhub.{ip_address}.nip.io",
"--set", f"binderhub.ingress.hosts={{{ip_address}.nip.io}}",
"--set", f"binderhub.jupyterhub.ingress.hosts={{jupyterhub.{ip_address}.nip.io}}",
"--set", f"static.ingress.hosts={{static.{ip_address}.nip.io}}",
])

check_call(helm, dry_run)
print(
BOLD + GREEN + f"SUCCESS: Helm {helm_commands[0]} for {release} completed" + NC,
Expand Down Expand Up @@ -460,6 +468,10 @@ def main():
action="store_true",
help="If the script is running locally, skip auth step",
)
argparser.add_argument(
"--local-ip",
help="IP address of the local machine",
)
argparser.add_argument(
"--dry-run",
action="store_true",
Expand All @@ -483,6 +495,9 @@ def main():
if args.release == "localhost":
args.local = True

if args.local_ip is None:
raise ValueError("Cluster localhost requires IP address.")

# if one argument given make cluster == release
cluster = args.cluster or args.release

Expand Down Expand Up @@ -536,7 +551,7 @@ def main():
if args.stage in ("all", "certmanager"):
setup_certmanager(args.dry_run, args.diff)
if args.stage in ("all", "mybinder"):
deploy(args.release, args.name, args.dry_run, args.diff)
deploy(args.release, args.name, args.dry_run, args.diff, args.local_ip)


if __name__ == "__main__":
Expand Down

0 comments on commit 3f76268

Please sign in to comment.