respond to code review
This commit is contained in:
parent
d707bba2fb
commit
2cd6e9d989
|
|
@ -1,38 +1,44 @@
|
||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
|
# unofficial bash strict mode w/o the -e option
|
||||||
|
# -e breaks "eval $cmd" in the retry function
|
||||||
set -uo pipefail
|
set -uo pipefail
|
||||||
IFS=$'\n\t'
|
IFS=$'\n\t'
|
||||||
|
|
||||||
# timeouts after 3 minutes
|
function retry(){ # timeouts after 1 minutes
|
||||||
function retry(){
|
|
||||||
cmd="$1"
|
cmd="$1"
|
||||||
retryMsg="$2"
|
retryMsg="$2"
|
||||||
for i in {1..90}; do
|
for i in {1..20}; do
|
||||||
eval "$cmd"
|
eval "$cmd"
|
||||||
if [ $? -eq 0 ]; then
|
if [ $? -eq 0 ]; then
|
||||||
return 0
|
return 0
|
||||||
fi
|
fi
|
||||||
echo "$retryMsg"
|
echo "$retryMsg"
|
||||||
sleep 2
|
sleep 3
|
||||||
done
|
done
|
||||||
|
|
||||||
return 1
|
return 1
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
echo "==== CLEAN UP PREVIOUS RUN ==== "
|
echo "==== CLEAN UP PREVIOUS RUN ==== "
|
||||||
|
|
||||||
status=$(minikube status --format "{{.MinikubeStatus}}")
|
status=$(minikube status --format "{{.MinikubeStatus}}")
|
||||||
if [ "$status" = "Running" ]; then
|
if [ "$status" = "Running" ] || [ "$status" = "Stopped" ]; then
|
||||||
|
echo "Delete the existing local cluster so that we can cleanly apply resources from scratch..."
|
||||||
minikube delete
|
minikube delete
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# the kubectl process does the port-forwarding between operator and local ports
|
# the kubectl process does the port-forwarding between operator and local ports
|
||||||
# we restart the process to be able to bind to the same port again (see end of script)
|
# we restart the process to bind to the same port again (see end of script)
|
||||||
echo "Kill kubectl process to re-init port-forwarding for minikube"
|
if [ -e /tmp/kubectl-port-forward.pid ]; then
|
||||||
kubepid=$(pidof "kubectl")
|
|
||||||
if [ $? -eq 0 ]; then
|
pid=$(cat /tmp/kubectl-port-forward.pid)
|
||||||
kill "$kubepid"
|
# the process will die if a minikube is stopped manually between two invocations of the script
|
||||||
|
if ps --pid "$pid" > /dev/null; then
|
||||||
|
echo "Kill the kubectl process responsible for port forwarding for minikube so that we can re-use the same ports for forwarding later..."
|
||||||
|
kill "$pid"
|
||||||
|
fi
|
||||||
|
rm /tmp/kubectl-port-forward.pid
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -51,8 +57,8 @@ do
|
||||||
retry "kubectl create -f manifests/\"$file\"" "attempt to create $file resource"
|
retry "kubectl create -f manifests/\"$file\"" "attempt to create $file resource"
|
||||||
done
|
done
|
||||||
|
|
||||||
msg="Wait for the postgresql custom resource definition to register."
|
msg="Wait for the postgresql custom resource definition to register..."
|
||||||
cmd="kubectl get crd | grep 'postgresqls.acid.zalan.do' &> /dev/null"
|
cmd="kubectl get crd | grep --quiet 'postgresqls.acid.zalan.do'"
|
||||||
retry "$cmd" "$msg "
|
retry "$cmd" "$msg "
|
||||||
|
|
||||||
kubectl create -f manifests/complete-postgres-manifest.yaml
|
kubectl create -f manifests/complete-postgres-manifest.yaml
|
||||||
|
|
@ -62,22 +68,18 @@ operatorPort="8080"
|
||||||
echo "==== FORWARD OPERATOR PORT $operatorPort TO LOCAL PORT $localPort ===="
|
echo "==== FORWARD OPERATOR PORT $operatorPort TO LOCAL PORT $localPort ===="
|
||||||
operatorPod=$(kubectl get pod -l name=postgres-operator -o jsonpath={.items..metadata.name})
|
operatorPod=$(kubectl get pod -l name=postgres-operator -o jsonpath={.items..metadata.name})
|
||||||
# runs in the background to keep current terminal responsive
|
# runs in the background to keep current terminal responsive
|
||||||
# 1> redirects stdout to remove the info message about forwarded ports; the message sometimes garbles the cli prompt
|
# stdout redirect removes the info message about forwarded ports; the message sometimes garbles the cli prompt
|
||||||
kubectl port-forward "$operatorPod" "$localPort":"$operatorPort" 1> /dev/null &
|
kubectl port-forward "$operatorPod" "$localPort":"$operatorPort" &> /dev/null &
|
||||||
|
pgrep --newest "kubectl" > /tmp/kubectl-port-forward.pid
|
||||||
|
|
||||||
echo "==== RUN HEALTH CHECK ==== "
|
echo "==== RUN HEALTH CHECK ==== "
|
||||||
checkCmd="curl -L http://127.0.0.1:$localPort/clusters &> /dev/null"
|
checkCmd="curl --location --silent http://127.0.0.1:$localPort/clusters &> /dev/null"
|
||||||
|
echo "Command for checking: $checkCmd"
|
||||||
checkMsg="Wait for port forwarding to take effect"
|
checkMsg="Wait for port forwarding to take effect"
|
||||||
retry "$checkCmd" "$checkMsg"
|
|
||||||
|
|
||||||
if [ $? -eq 0 ]; then
|
if retry "$checkCmd" "$checkMsg" ; then
|
||||||
echo "==== SUCCESS: OPERATOR IS RUNNING ==== "
|
echo "==== SUCCESS: OPERATOR IS RUNNING ==== "
|
||||||
else
|
else
|
||||||
echo "Operator did not start or port forwarding did not work"
|
echo "==== FAILURE: OPERATOR DID NOT START OR PORT FORWARDING DID NOT WORK"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue