I have simple Bash script running command in Kubernetes, however I need autocomplete in one command to continue:
#!/bin/bash
DATE=$(date +%Y-%m-%d_%H:%M:%S)
printf "Available Kubectl contexts:\n\n"
kubectl config get-contexts -o=name | sort -n
printf "%s\n"
echo -ne "Select Kubectl context: "; read KUBE_CONTEXT
for I in $KUBE_CONTEXT ; do
kubectl config use-context $KUBE_CONTEXT
done
echo -ne "Path to file containing Job ID list: "; read -e JOB_ID_LIST
printf "%s\n"
echo "Setting port forwarding to Prometheus POD in $KUBE_CONTEXT" ;
and this is where I need autocompletion as the pod name is different in each kubectl environment.
kubectl port-forward -n prometheus prometheus-prometheus-RANDOM_TEXT-RANDOM_TEXT 20001:9090
for instance:
kubectl port-forward -n prometheus prometheus-prometheus-6465c4df4c-4dvf7 8080:9090 &
Autocomplete works when I am typing it manually, but I want Bash to autocomplete it in the script. Is it possible?