From 4641429889d33765d72651d3e629af159e81592d Mon Sep 17 00:00:00 2001 From: Raniere Silva Date: Thu, 9 Jan 2025 11:07:21 +0100 Subject: [PATCH] Force use of IP other than 127.0.0.1 for localhost and overwrite Helm chart with the provided IP address. --- config/localhost.yaml | 5 ++++- deploy.py | 19 +++++++++++++++++-- 2 files changed, 21 insertions(+), 3 deletions(-) diff --git a/config/localhost.yaml b/config/localhost.yaml index 0b303f227..3e9c74e1c 100644 --- a/config/localhost.yaml +++ b/config/localhost.yaml @@ -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: diff --git a/deploy.py b/deploy.py index dcf0c1c22..7094089e9 100755 --- a/deploy.py +++ b/deploy.py @@ -199,7 +199,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 @@ -239,6 +239,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, @@ -462,6 +470,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", @@ -485,6 +497,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 @@ -538,7 +553,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__":