Skip to content

Commit

Permalink
MiniLangStream enable NodePort if missing for services (#701)
Browse files Browse the repository at this point in the history
  • Loading branch information
Gagravarr authored Nov 8, 2023
1 parent f73c28d commit 1d32f33
Showing 1 changed file with 26 additions and 4 deletions.
30 changes: 26 additions & 4 deletions mini-langstream/mini-langstream
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down

0 comments on commit 1d32f33

Please sign in to comment.