diff --git a/mini-langstream/mini-langstream b/mini-langstream/mini-langstream index 140f94ffe..050426a27 100755 --- a/mini-langstream/mini-langstream +++ b/mini-langstream/mini-langstream @@ -219,17 +219,39 @@ install_langstream() { } -start_port_forward() { +query_port_forward() { local service=$1 local file=$(mktemp) minikube_cmd service $1 --url -n $k8s_namespace &> $file if grep -q 'http' $file; then - url=$(grep -e http $file) + url=$(grep -e http $file | head -1) + echo "$url" + return + fi + return 1 +} +start_port_forward() { + local service=$1 + local url + + # See if there is already an external port setup + url=$(query_port_forward $service) + if [ $? -eq 0 ]; then echo "$url" + return + fi + + # Change the service to a NodePort one so it has one + kubectl_cmd -n $k8s_namespace patch svc ${service} -p '{"spec": {"type": "NodePort"}}' &> /dev/null + + # Fetch the auto-generated port details, or error out + url=$(query_port_forward $service) + if [ $? -eq 0 ]; then + echo "$url" + return else - echo "${service}: ❌ - Port forwarding failed to start" >&2 - cat $file >&2 + echo "${service}: ❌ - Port forwarding could not be enabled" >&2 exit 1 fi }