Fix naming conflict and redo formatting
This commit is contained in:
parent
105bbdb8e4
commit
f1bcdd1a8e
|
|
@ -21,23 +21,23 @@ readonly OPERATOR_PORT="8080"
|
|||
# so the script retries actions until all the resources become available
|
||||
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
|
||||
|
||||
local -r cmd="$1"
|
||||
local -r retry_cmd="$1"
|
||||
local -r retry_msg="$2"
|
||||
|
||||
# times out after 1 minute
|
||||
for i in {1..20}; do
|
||||
if eval "$cmd"; then
|
||||
set -o errexit # enable again
|
||||
if eval "$retry_cmd"; then
|
||||
set -o errexit # enable again
|
||||
return 0
|
||||
fi
|
||||
echo "$retry_msg"
|
||||
echo "$retry_msg"
|
||||
sleep 3
|
||||
done
|
||||
|
||||
>2& echo "The command $cmd timed out"
|
||||
>2& echo "The command $retry_cmd timed out"
|
||||
return 1
|
||||
}
|
||||
|
||||
|
|
@ -55,27 +55,27 @@ function clean_up(){
|
|||
status=$(minikube status --format "{{.MinikubeStatus}}" || true)
|
||||
|
||||
if [[ "$status" = "Running" ]] || [[ "$status" = "Stopped" ]]; then
|
||||
echo "Delete the existing local cluster so that we can cleanly apply resources from scratch..."
|
||||
minikube delete
|
||||
echo "Delete the existing local cluster so that we can cleanly apply resources from scratch..."
|
||||
minikube delete
|
||||
fi
|
||||
|
||||
if [[ -e "$PATH_TO_LOCAL_OPERATOR_MANIFEST" ]]; then
|
||||
rm --verbose "$PATH_TO_LOCAL_OPERATOR_MANIFEST"
|
||||
rm --verbose "$PATH_TO_LOCAL_OPERATOR_MANIFEST"
|
||||
fi
|
||||
|
||||
# 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)
|
||||
if [[ -e "$PATH_TO_PORT_FORWARED_KUBECTL_PID" ]]; then
|
||||
|
||||
local pid
|
||||
pid=$(cat "$PATH_TO_PORT_FORWARED_KUBECTL_PID")
|
||||
local pid
|
||||
pid=$(cat "$PATH_TO_PORT_FORWARED_KUBECTL_PID")
|
||||
|
||||
# the process dies if a minikube stops between two invocations of the script
|
||||
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..."
|
||||
kill "$pid"
|
||||
fi
|
||||
rm --verbose /tmp/kubectl-port-forward.pid
|
||||
# the process dies if a minikube stops between two invocations of the script
|
||||
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..."
|
||||
kill "$pid"
|
||||
fi
|
||||
rm --verbose /tmp/kubectl-port-forward.pid
|
||||
|
||||
fi
|
||||
}
|
||||
|
|
@ -143,13 +143,13 @@ function start_operator(){
|
|||
local file
|
||||
for file in "configmap.yaml" "serviceaccount.yaml"
|
||||
do
|
||||
retry "kubectl create -f manifests/\"$file\"" "attempt to create $file resource"
|
||||
retry "kubectl create -f manifests/\"$file\"" "attempt to create $file resource"
|
||||
done
|
||||
|
||||
if [[ "$should_build_custom_operator" = true ]]; then # set in main()
|
||||
deploy_self_built_image
|
||||
deploy_self_built_image
|
||||
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
|
||||
|
||||
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"
|
||||
|
||||
if retry "$check_cmd" "$check_msg"; then
|
||||
echo "==== SUCCESS: OPERATOR IS RUNNING ==== "
|
||||
echo "To stop it cleanly, run 'minikube delete'"
|
||||
echo "==== SUCCESS: OPERATOR IS RUNNING ==== "
|
||||
echo "To stop it cleanly, run 'minikube delete'"
|
||||
else
|
||||
>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
|
||||
>2& echo "==== FAILURE: OPERATOR DID NOT START OR PORT FORWARDING DID NOT WORK"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
}
|
||||
|
||||
|
||||
function main(){
|
||||
|
||||
if ! [[ $(basename $PWD) == "postgres-operator" ]]; then
|
||||
echo "Please execute the script only from the root directory of the Postgres opepator repo."
|
||||
exit 1
|
||||
if ! [[ $(basename "$PWD") == "postgres-operator" ]]; then
|
||||
echo "Please execute the script only from the root directory of the Postgres opepator repo."
|
||||
exit 1
|
||||
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
|
||||
|
|
@ -207,19 +205,19 @@ function main(){
|
|||
local should_build_custom_operator=false # used in start_operator()
|
||||
while true
|
||||
do
|
||||
# if the 1st param is unset, use the empty string as a default value
|
||||
case "${1:-}" in
|
||||
-h | --help)
|
||||
display_help
|
||||
exit 0
|
||||
;;
|
||||
-r | --rebuild-operator)
|
||||
should_build_custom_operator=true
|
||||
break
|
||||
;;
|
||||
*) break
|
||||
;;
|
||||
esac
|
||||
# if the 1st param is unset, use the empty string as a default value
|
||||
case "${1:-}" in
|
||||
-h | --help)
|
||||
display_help
|
||||
exit 0
|
||||
;;
|
||||
-r | --rebuild-operator)
|
||||
should_build_custom_operator=true
|
||||
break
|
||||
;;
|
||||
*) break
|
||||
;;
|
||||
esac
|
||||
done
|
||||
|
||||
clean_up
|
||||
|
|
@ -233,4 +231,3 @@ function main(){
|
|||
|
||||
|
||||
main "$@"
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue