From 7ce36a3d5bc764079dfb92ec9351aa9dce0d5438 Mon Sep 17 00:00:00 2001 From: Sergey Dudoladov Date: Thu, 25 Jan 2018 15:36:45 +0100 Subject: [PATCH] Apply stashed changes that build operator --- run_locally.sh | 42 ++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 40 insertions(+), 2 deletions(-) diff --git a/run_locally.sh b/run_locally.sh index f7c6973fe..419bcf1fb 100755 --- a/run_locally.sh +++ b/run_locally.sh @@ -20,6 +20,37 @@ function retry(){ # timeouts after 1 minutes return 1 } +function build_operator_binary(){ + make tools && make deps && make local +} + +# the fastest way to run your docker image locally is to reuse the docker from minikube. +function deploy_self_built_image() { + + echo "==== DEPLOY CUSTOM OPERATOR IMAGE ==== " + + build_operator_binary + + # set docker env vars so that it can talk to the Docker daemon inside the minikube VM + eval $(minikube docker-env) + + # image tag consists of a git tag or a unique commit prefix + # and the "-dev" suffix if there are uncommited changes in the working dir + export TAG=$(git describe --tags --always --dirty="-dev") + + # build the image + make docker + + # update the tag in the postgres operator conf + # since the image with this tag is already present on the machine, + # docker should not attempt to fetch it from the registry due to imagePullPolicy + file="manifests/local-postgres-operator.yaml" + sed -e "s/\(image\:.*\:\).*$/\1$TAG/" manifests/postgres-operator.yaml >> "$file" + + retry "kubectl create -f \"$file\"" "attempt to create $file resource" + } + + echo "==== CLEAN UP PREVIOUS RUN ==== " status=$(minikube status --format "{{.MinikubeStatus}}") @@ -39,8 +70,8 @@ if [ -e /tmp/kubectl-port-forward.pid ]; then kill "$pid" fi rm /tmp/kubectl-port-forward.pid -fi +fi echo "==== START MINIKUBE ==== " echo "May take a few minutes ..." @@ -52,11 +83,18 @@ minikube status echo "==== START OPERATOR ==== " # the order of files is significant -for file in "configmap.yaml" "serviceaccount.yaml" "postgres-operator.yaml" +for file in "configmap.yaml" "serviceaccount.yaml" do retry "kubectl create -f manifests/\"$file\"" "attempt to create $file resource" done +should_build_operator=true +if [ "$should_build_operator" = true ]; then + deploy_self_built_image +else + retry "kubectl create -f manifests/postgres-operator.yaml" "attempt to create $file resource" +fi + msg="Wait for the postgresql custom resource definition to register..." cmd="kubectl get crd | grep --quiet 'postgresqls.acid.zalan.do'" retry "$cmd" "$msg "