Fix naming conflict and redo formatting

This commit is contained in:
Sergey Dudoladov 2018-01-30 12:24:35 +01:00
parent 105bbdb8e4
commit f1bcdd1a8e
1 changed files with 70 additions and 73 deletions

View File

@ -21,23 +21,23 @@ readonly OPERATOR_PORT="8080"
# so the script retries actions until all the resources become available # so the script retries actions until all the resources become available
function retry(){ function retry(){
# errexit may break "eval $cmd", so we disable it temporarily # errexit may break "eval $retry_cmd", so we disable it temporarily
set +o errexit set +o errexit
local -r cmd="$1" local -r retry_cmd="$1"
local -r retry_msg="$2" local -r retry_msg="$2"
# times out after 1 minute # times out after 1 minute
for i in {1..20}; do for i in {1..20}; do
if eval "$cmd"; then if eval "$retry_cmd"; then
set -o errexit # enable again set -o errexit # enable again
return 0 return 0
fi fi
echo "$retry_msg" echo "$retry_msg"
sleep 3 sleep 3
done done
>2& echo "The command $cmd timed out" >2& echo "The command $retry_cmd timed out"
return 1 return 1
} }
@ -55,27 +55,27 @@ function clean_up(){
status=$(minikube status --format "{{.MinikubeStatus}}" || true) status=$(minikube status --format "{{.MinikubeStatus}}" || true)
if [[ "$status" = "Running" ]] || [[ "$status" = "Stopped" ]]; then if [[ "$status" = "Running" ]] || [[ "$status" = "Stopped" ]]; then
echo "Delete the existing local cluster so that we can cleanly apply resources from scratch..." echo "Delete the existing local cluster so that we can cleanly apply resources from scratch..."
minikube delete minikube delete
fi fi
if [[ -e "$PATH_TO_LOCAL_OPERATOR_MANIFEST" ]]; then if [[ -e "$PATH_TO_LOCAL_OPERATOR_MANIFEST" ]]; then
rm --verbose "$PATH_TO_LOCAL_OPERATOR_MANIFEST" rm --verbose "$PATH_TO_LOCAL_OPERATOR_MANIFEST"
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 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)
if [[ -e "$PATH_TO_PORT_FORWARED_KUBECTL_PID" ]]; then if [[ -e "$PATH_TO_PORT_FORWARED_KUBECTL_PID" ]]; then
local pid local pid
pid=$(cat "$PATH_TO_PORT_FORWARED_KUBECTL_PID") pid=$(cat "$PATH_TO_PORT_FORWARED_KUBECTL_PID")
# the process dies if a minikube stops between two invocations of the script # the process dies if a minikube stops between two invocations of the script
if ps --pid "$pid" > /dev/null 2>&1; then if ps --pid "$pid" > /dev/null 2>&1; then
echo "Kill the kubectl process responsible for port forwarding for minikube so that we can re-use the same ports for forwarding later..." 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" kill "$pid"
fi fi
rm --verbose /tmp/kubectl-port-forward.pid rm --verbose /tmp/kubectl-port-forward.pid
fi fi
} }
@ -143,13 +143,13 @@ function start_operator(){
local file local file
for file in "configmap.yaml" "serviceaccount.yaml" for file in "configmap.yaml" "serviceaccount.yaml"
do 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
if [[ "$should_build_custom_operator" = true ]]; then # set in main() if [[ "$should_build_custom_operator" = true ]]; then # set in main()
deploy_self_built_image deploy_self_built_image
else else
retry "kubectl create -f manifests/postgres-operator.yaml" "attempt to create /postgres-operator.yaml resource" retry "kubectl create -f manifests/postgres-operator.yaml" "attempt to create /postgres-operator.yaml resource"
fi fi
local -r msg="Wait for the postgresql custom resource definition to register..." local -r msg="Wait for the postgresql custom resource definition to register..."
@ -184,22 +184,20 @@ function check_health(){
echo "Command for checking: $check_cmd" echo "Command for checking: $check_cmd"
if retry "$check_cmd" "$check_msg"; then if retry "$check_cmd" "$check_msg"; then
echo "==== SUCCESS: OPERATOR IS RUNNING ==== " echo "==== SUCCESS: OPERATOR IS RUNNING ==== "
echo "To stop it cleanly, run 'minikube delete'" echo "To stop it cleanly, run 'minikube delete'"
else else
>2& echo "==== FAILURE: OPERATOR DID NOT START OR PORT FORWARDING DID NOT WORK" >2& echo "==== FAILURE: OPERATOR DID NOT START OR PORT FORWARDING DID NOT WORK"
>2& echo "This *might* have left the minikube VM image in inconsistent state." exit 1
exit 1
fi fi
} }
function main(){ function main(){
if ! [[ $(basename $PWD) == "postgres-operator" ]]; then if ! [[ $(basename "$PWD") == "postgres-operator" ]]; then
echo "Please execute the script only from the root directory of the Postgres opepator repo." echo "Please execute the script only from the root directory of the Postgres opepator repo."
exit 1 exit 1
fi fi
trap "echo 'If you observe issues with minikube VM not starting/not proceeding, consider deleting the .minikube dir and/or rebooting before re-running the script'" EXIT trap "echo 'If you observe issues with minikube VM not starting/not proceeding, consider deleting the .minikube dir and/or rebooting before re-running the script'" EXIT
@ -207,19 +205,19 @@ function main(){
local should_build_custom_operator=false # used in start_operator() local should_build_custom_operator=false # used in start_operator()
while true while true
do do
# if the 1st param is unset, use the empty string as a default value # if the 1st param is unset, use the empty string as a default value
case "${1:-}" in case "${1:-}" in
-h | --help) -h | --help)
display_help display_help
exit 0 exit 0
;; ;;
-r | --rebuild-operator) -r | --rebuild-operator)
should_build_custom_operator=true should_build_custom_operator=true
break break
;; ;;
*) break *) break
;; ;;
esac esac
done done
clean_up clean_up
@ -233,4 +231,3 @@ function main(){
main "$@" main "$@"