Skip to content
Snippets Groups Projects
Commit 35803a8c authored by Sergey Dudoladov's avatar Sergey Dudoladov
Browse files

Add a command to replace operator image w/o minikube restart

parent 637067e8
No related branches found
No related tags found
No related merge requests found
...@@ -6,6 +6,7 @@ ...@@ -6,6 +6,7 @@
# Known limitations: # Known limitations:
# 1) minikube provides a single node k8s cluster. That is, you will not be able test functions like pod # 1) minikube provides a single node k8s cluster. That is, you will not be able test functions like pod
# migration between multiple nodes locally # migration between multiple nodes locally
# 2) this script configures the operator via configmap, not the operator CRD
# enable unofficial bash strict mode # enable unofficial bash strict mode
...@@ -43,7 +44,7 @@ function retry(){ ...@@ -43,7 +44,7 @@ function retry(){
} }
function display_help(){ function display_help(){
echo "Usage: $0 [ -r | --rebuild-operator ] [ -h | --help ] [ -f | --force-minikube-restart ] [ -t | --deploy-pg-to-namespace-test ]" echo "Usage: $0 [ -r | --rebuild-operator ] [ -h | --help ] [ -n | --deploy-new-operator-image ] [ -t | --deploy-pg-to-namespace-test ]"
} }
function clean_up(){ function clean_up(){
...@@ -126,7 +127,7 @@ function deploy_self_built_image() { ...@@ -126,7 +127,7 @@ function deploy_self_built_image() {
# docker should not attempt to fetch it from the registry due to imagePullPolicy # docker should not attempt to fetch it from the registry due to imagePullPolicy
sed --expression "s/\(image\:.*\:\).*$/\1$TAG/; s/smoke-tested-//" manifests/postgres-operator.yaml > "$PATH_TO_LOCAL_OPERATOR_MANIFEST" sed --expression "s/\(image\:.*\:\).*$/\1$TAG/; s/smoke-tested-//" manifests/postgres-operator.yaml > "$PATH_TO_LOCAL_OPERATOR_MANIFEST"
retry "kubectl create -f \"$PATH_TO_LOCAL_OPERATOR_MANIFEST\"" "attempt to create $PATH_TO_LOCAL_OPERATOR_MANIFEST resource" retry "kubectl apply -f \"$PATH_TO_LOCAL_OPERATOR_MANIFEST\"" "attempt to create $PATH_TO_LOCAL_OPERATOR_MANIFEST resource"
} }
...@@ -142,17 +143,18 @@ function start_operator(){ ...@@ -142,17 +143,18 @@ function start_operator(){
retry "kubectl create -f manifests/\"$file\"" "attempt to create $file resource" retry "kubectl create -f manifests/\"$file\"" "attempt to create $file resource"
done done
cp manifests/postgres-operator.yaml $PATH_TO_LOCAL_OPERATOR_MANIFEST
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 ${PATH_TO_LOCAL_OPERATOR_MANIFEST}" "attempt to create ${PATH_TO_LOCAL_OPERATOR_MANIFEST} 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..."
local -r cmd="kubectl get crd | grep --quiet 'postgresqls.acid.zalan.do'" local -r cmd="kubectl get crd | grep --quiet 'postgresqls.acid.zalan.do'"
retry "$cmd" "$msg " retry "$cmd" "$msg "
} }
...@@ -188,6 +190,7 @@ function check_health(){ ...@@ -188,6 +190,7 @@ function check_health(){
fi fi
} }
function submit_postgresql_manifest(){ function submit_postgresql_manifest(){
echo "==== SUBMIT MINIMAL POSTGRES MANIFEST ==== " echo "==== SUBMIT MINIMAL POSTGRES MANIFEST ==== "
...@@ -206,6 +209,7 @@ function submit_postgresql_manifest(){ ...@@ -206,6 +209,7 @@ function submit_postgresql_manifest(){
} }
function main(){ function main(){
if ! [[ $(basename "$PWD") == "postgres-operator" ]]; then if ! [[ $(basename "$PWD") == "postgres-operator" ]]; then
...@@ -217,7 +221,7 @@ function main(){ ...@@ -217,7 +221,7 @@ function main(){
local should_build_custom_operator=false local should_build_custom_operator=false
local should_deploy_pg_to_namespace_test=false local should_deploy_pg_to_namespace_test=false
local should_restart_minikube=false local should_replace_operator_image=false
while true while true
do do
...@@ -227,12 +231,12 @@ function main(){ ...@@ -227,12 +231,12 @@ function main(){
display_help display_help
exit 0 exit 0
;; ;;
-r | --rebuild-operator) -r | --rebuild-operator) # with minikube restart
should_build_custom_operator=true should_build_custom_operator=true
break break
;; ;;
-f | --force-minikube-restart) # restarts take minutes so existing minikube is re-used by default -n | --deploy-new-operator-image) # without minikube restart that takes minutes
should_restart_minikube=true should_replace_operator_image=true
break break
;; ;;
-t | --deploy-pg-to-namespace-test) # to test multi-namespace support locally -t | --deploy-pg-to-namespace-test) # to test multi-namespace support locally
...@@ -244,6 +248,11 @@ function main(){ ...@@ -244,6 +248,11 @@ function main(){
esac esac
done done
if ${should_replace_operator_image}; then
deploy_self_built_image
exit 0
fi
clean_up clean_up
start_minikube start_minikube
start_operator start_operator
...@@ -254,4 +263,5 @@ function main(){ ...@@ -254,4 +263,5 @@ function main(){
exit 0 exit 0
} }
main "$@" main "$@"
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment