Skip to content

Commit 35803a8

Browse files
author
Sergey Dudoladov
committed
Add a command to replace operator image w/o minikube restart
1 parent 637067e commit 35803a8

File tree

1 file changed

+18
-8
lines changed

1 file changed

+18
-8
lines changed

run_operator_locally.sh

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
# Known limitations:
77
# 1) minikube provides a single node k8s cluster. That is, you will not be able test functions like pod
88
# migration between multiple nodes locally
9+
# 2) this script configures the operator via configmap, not the operator CRD
910

1011

1112
# enable unofficial bash strict mode
@@ -43,7 +44,7 @@ function retry(){
4344
}
4445

4546
function display_help(){
46-
echo "Usage: $0 [ -r | --rebuild-operator ] [ -h | --help ] [ -f | --force-minikube-restart ] [ -t | --deploy-pg-to-namespace-test ]"
47+
echo "Usage: $0 [ -r | --rebuild-operator ] [ -h | --help ] [ -n | --deploy-new-operator-image ] [ -t | --deploy-pg-to-namespace-test ]"
4748
}
4849

4950
function clean_up(){
@@ -126,7 +127,7 @@ function deploy_self_built_image() {
126127
# docker should not attempt to fetch it from the registry due to imagePullPolicy
127128
sed --expression "s/\(image\:.*\:\).*$/\1$TAG/; s/smoke-tested-//" manifests/postgres-operator.yaml > "$PATH_TO_LOCAL_OPERATOR_MANIFEST"
128129

129-
retry "kubectl create -f \"$PATH_TO_LOCAL_OPERATOR_MANIFEST\"" "attempt to create $PATH_TO_LOCAL_OPERATOR_MANIFEST resource"
130+
retry "kubectl apply -f \"$PATH_TO_LOCAL_OPERATOR_MANIFEST\"" "attempt to create $PATH_TO_LOCAL_OPERATOR_MANIFEST resource"
130131
}
131132

132133

@@ -142,17 +143,18 @@ function start_operator(){
142143
retry "kubectl create -f manifests/\"$file\"" "attempt to create $file resource"
143144
done
144145

146+
cp manifests/postgres-operator.yaml $PATH_TO_LOCAL_OPERATOR_MANIFEST
147+
145148
if [[ "$should_build_custom_operator" = true ]]; then # set in main()
146149
deploy_self_built_image
147150
else
148-
retry "kubectl create -f manifests/postgres-operator.yaml" "attempt to create /postgres-operator.yaml resource"
151+
retry "kubectl create -f ${PATH_TO_LOCAL_OPERATOR_MANIFEST}" "attempt to create ${PATH_TO_LOCAL_OPERATOR_MANIFEST} resource"
149152
fi
150153

151154
local -r msg="Wait for the postgresql custom resource definition to register..."
152155
local -r cmd="kubectl get crd | grep --quiet 'postgresqls.acid.zalan.do'"
153156
retry "$cmd" "$msg "
154157

155-
156158
}
157159

158160

@@ -188,6 +190,7 @@ function check_health(){
188190
fi
189191
}
190192

193+
191194
function submit_postgresql_manifest(){
192195

193196
echo "==== SUBMIT MINIMAL POSTGRES MANIFEST ==== "
@@ -206,6 +209,7 @@ function submit_postgresql_manifest(){
206209

207210
}
208211

212+
209213
function main(){
210214

211215
if ! [[ $(basename "$PWD") == "postgres-operator" ]]; then
@@ -217,7 +221,7 @@ function main(){
217221

218222
local should_build_custom_operator=false
219223
local should_deploy_pg_to_namespace_test=false
220-
local should_restart_minikube=false
224+
local should_replace_operator_image=false
221225

222226
while true
223227
do
@@ -227,12 +231,12 @@ function main(){
227231
display_help
228232
exit 0
229233
;;
230-
-r | --rebuild-operator)
234+
-r | --rebuild-operator) # with minikube restart
231235
should_build_custom_operator=true
232236
break
233237
;;
234-
-f | --force-minikube-restart) # restarts take minutes so existing minikube is re-used by default
235-
should_restart_minikube=true
238+
-n | --deploy-new-operator-image) # without minikube restart that takes minutes
239+
should_replace_operator_image=true
236240
break
237241
;;
238242
-t | --deploy-pg-to-namespace-test) # to test multi-namespace support locally
@@ -244,6 +248,11 @@ function main(){
244248
esac
245249
done
246250

251+
if ${should_replace_operator_image}; then
252+
deploy_self_built_image
253+
exit 0
254+
fi
255+
247256
clean_up
248257
start_minikube
249258
start_operator
@@ -254,4 +263,5 @@ function main(){
254263
exit 0
255264
}
256265

266+
257267
main "$@"

0 commit comments

Comments
 (0)