split run.sh into functions for readability

This commit is contained in:
Sergey Dudoladov 2019-05-14 14:10:06 +02:00
parent c3f5200d4b
commit 9b05215b28
2 changed files with 41 additions and 20 deletions

View File

@ -96,6 +96,8 @@ e2e-build:
docker build --tag="postgres-operator-e2e-tests" -f e2e/Dockerfile . docker build --tag="postgres-operator-e2e-tests" -f e2e/Dockerfile .
e2e-tools: e2e-tools:
# install pinned version of 'kind'
# leave the name as is to avoid overwriting official binary named `kind`
wget https://github.com/kubernetes-sigs/kind/releases/download/0.2.1/kind-linux-amd64 wget https://github.com/kubernetes-sigs/kind/releases/download/0.2.1/kind-linux-amd64
chmod +x kind-linux-amd64 chmod +x kind-linux-amd64
mv kind-linux-amd64 $(KIND_PATH) mv kind-linux-amd64 $(KIND_PATH)

View File

@ -9,27 +9,46 @@ IFS=$'\n\t'
readonly cluster_name="postgres-operator-e2e-tests" readonly cluster_name="postgres-operator-e2e-tests"
readonly operator_image=$(docker images --filter=reference="registry.opensource.zalan.do/acid/postgres-operator" --format "{{.Repository}}:{{.Tag}}" | head -1) readonly operator_image=$(docker images --filter=reference="registry.opensource.zalan.do/acid/postgres-operator" --format "{{.Repository}}:{{.Tag}}" | head -1)
readonly e2e_test_image=${cluster_name} readonly e2e_test_image=${cluster_name}
readonly kind_api_server_port=6443 # well-known in the 'kind' codebase readonly kubeconfig_path="/tmp/kind-config-${cluster_name}"
readonly kubeconfig_path="./e2e/kind-config-${cluster_name}"
# avoid interference with previous test runs
if [[ $(kind-linux-amd64 get clusters | grep "^${cluster_name}*") != "" ]] function start_kind(){
then
# avoid interference with previous test runs
if [[ $(kind-linux-amd64 get clusters | grep "^${cluster_name}*") != "" ]]
then
kind-linux-amd64 delete cluster --name ${cluster_name} kind-linux-amd64 delete cluster --name ${cluster_name}
fi fi
kind-linux-amd64 create cluster --name ${cluster_name} --config ./e2e/kind-cluster-postgres-operator-e2e-tests.yaml kind-linux-amd64 create cluster --name ${cluster_name} --config ./e2e/kind-cluster-postgres-operator-e2e-tests.yaml
export KUBECONFIG="$(kind-linux-amd64 get kubeconfig-path --name=${cluster_name})" kind-linux-amd64 load docker-image ${operator_image} --name ${cluster_name}
export KUBECONFIG="$(kind-linux-amd64 get kubeconfig-path --name=${cluster_name})"
}
kind-linux-amd64 load docker-image ${operator_image} --name ${cluster_name} function set_kind_api_server_ip(){
# use the actual kubeconfig to connect to the 'kind' API server
# but update the IP address of the API server to the one from the Docker 'bridge' network
cp ${KUBECONFIG} /tmp
readonly local kind_api_server_port=6443 # well-known in the 'kind' codebase
readonly local kind_api_server=$(docker inspect --format "{{ .NetworkSettings.IPAddress }}:${kind_api_server_port}" ${cluster_name}-control-plane)
sed -i "s/server.*$/server: https:\/\/$kind_api_server/g" ${kubeconfig_path}
}
# use the actual kubeconfig to connect to the 'kind' API server function run_tests(){
# but update the IP address of the API server to the one from the Docker 'bridge' network docker run --rm --mount type=bind,source="$(readlink -f ${kubeconfig_path})",target=/root/.kube/config -e OPERATOR_IMAGE=${operator_image} ${e2e_test_image}
cp $KUBECONFIG ./e2e }
kind_api_server=$(docker inspect --format "{{ .NetworkSettings.IPAddress }}:${kind_api_server_port}" ${cluster_name}-control-plane)
sed -i "s/server.*$/server: https:\/\/$kind_api_server/g" ${kubeconfig_path}
docker run --rm --mount type=bind,source="$(readlink -f ${kubeconfig_path})",target=/root/.kube/config -e OPERATOR_IMAGE=${operator_image} ${e2e_test_image} function clean_up(){
kind-linux-amd64 delete cluster --name ${cluster_name}
rm -rf ${kubeconfig_path}
}
kind-linux-amd64 delete cluster --name ${cluster_name} function main(){
rm -rf ${kubeconfig_path} start_kind
set_kind_api_server_ip
run_tests
clean_up
exit 0
}
main "$@"