From 1d32f33e94b11bb1a8f2ce140fe6e284801da79e Mon Sep 17 00:00:00 2001 From: Gagravarr Date: Wed, 8 Nov 2023 17:47:18 +0000 Subject: [PATCH] MiniLangStream enable NodePort if missing for services (#701) --- mini-langstream/mini-langstream | 30 ++++++++++++++++++++++++++---- 1 file changed, 26 insertions(+), 4 deletions(-) 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 }