Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion manifests/configmap.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ data:

debug_logging: "true"
workers: "4"
docker_image: registry.opensource.zalan.do/acid/spilo-cdp-11:1.5-p42
docker_image: registry.opensource.zalan.do/acid/spilo-11:1.5-p4
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@sdudoladov , just curious what is the difference between spilo-cdp-11 and spilo-11?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

spilo-cdp is build and pushed by ci/cd system on every commit to the master branch.
Later it is tested and if everything is fine we are tagging it as a spilo.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is spilll-11 aligned with Patroni releases or it is for every commit as well, just after test?

pod_service_account_name: "zalando-postgres-operator"
secret_name_template: '{username}.{cluster}.credentials'
super_username: postgres
Expand Down
2 changes: 1 addition & 1 deletion manifests/minimal-postgres-manifest.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ apiVersion: "acid.zalan.do/v1"
kind: postgresql
metadata:
name: acid-minimal-cluster
namespace: test # assumes namespace exists beforehand
namespace: default
spec:
teamId: "ACID"
volume:
Expand Down
2 changes: 1 addition & 1 deletion manifests/postgres-operator.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ spec:
serviceAccountName: zalando-postgres-operator
containers:
- name: postgres-operator
image: registry.opensource.zalan.do/acid/smoke-tested-postgres-operator:v1.0.0-21-ge39915c
image: registry.opensource.zalan.do/acid/smoke-tested-postgres-operator:v1.0.0-37-g2422d72
imagePullPolicy: IfNotPresent
resources:
requests:
Expand Down
62 changes: 51 additions & 11 deletions run_operator_locally.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@
# Deploy a Postgres operator to a minikube aka local Kubernetes cluster
# Optionally re-build the operator binary beforehand to test local changes

# Known limitations:
# 1) minikube provides a single node k8s cluster. That is, you will not be able test functions like pod
# migration between multiple nodes locally
# 2) this script configures the operator via configmap, not the operator CRD


# enable unofficial bash strict mode
set -o errexit
Expand All @@ -13,6 +18,7 @@ IFS=$'\n\t'

readonly PATH_TO_LOCAL_OPERATOR_MANIFEST="/tmp/local-postgres-operator-manifest.yaml"
readonly PATH_TO_PORT_FORWARED_KUBECTL_PID="/tmp/kubectl-port-forward.pid"
readonly PATH_TO_THE_PG_CLUSTER_MANIFEST="/tmp/minimal-postgres-manifest.yaml"
readonly LOCAL_PORT="8080"
readonly OPERATOR_PORT="8080"

Expand All @@ -37,18 +43,16 @@ function retry(){
return 1
}


function display_help(){
echo "Usage: $0 [ -r | --rebuild-operator ] [ -h | --help ]"
echo "Usage: $0 [ -r | --rebuild-operator ] [ -h | --help ] [ -n | --deploy-new-operator-image ] [ -t | --deploy-pg-to-namespace-test ]"
}


function clean_up(){

echo "==== CLEAN UP PREVIOUS RUN ==== "

local status
status=$(minikube status --format "{{.MinikubeStatus}}" || true)
status=$(minikube status --format "{{.Host}}" || true)

if [[ "$status" = "Running" ]] || [[ "$status" = "Stopped" ]]; then
echo "Delete the existing local cluster so that we can cleanly apply resources from scratch..."
Expand Down Expand Up @@ -123,7 +127,7 @@ function deploy_self_built_image() {
# 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"

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"
}


Expand All @@ -139,17 +143,18 @@ function start_operator(){
retry "kubectl create -f manifests/\"$file\"" "attempt to create $file resource"
done

cp manifests/postgres-operator.yaml $PATH_TO_LOCAL_OPERATOR_MANIFEST

if [[ "$should_build_custom_operator" = true ]]; then # set in main()
deploy_self_built_image
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

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

kubectl create -f manifests/minimal-postgres-manifest.yaml
}


Expand Down Expand Up @@ -186,16 +191,38 @@ function check_health(){
}


function submit_postgresql_manifest(){

echo "==== SUBMIT MINIMAL POSTGRES MANIFEST ==== "

local namespace="default"
cp manifests/minimal-postgres-manifest.yaml $PATH_TO_THE_PG_CLUSTER_MANIFEST

if $should_deploy_pg_to_namespace_test; then
kubectl create namespace test
namespace="test"
sed --in-place 's/namespace: default/namespace: test/' $PATH_TO_THE_PG_CLUSTER_MANIFEST
fi

kubectl create -f $PATH_TO_THE_PG_CLUSTER_MANIFEST
echo "The operator will create the PG cluster with minimal manifest $PATH_TO_THE_PG_CLUSTER_MANIFEST in the ${namespace} namespace"

}


function main(){

if ! [[ $(basename "$PWD") == "postgres-operator" ]]; then
echo "Please execute the script only from the root directory of the Postgres opepator repo."
echo "Please execute the script only from the root directory of the Postgres operator 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

local should_build_custom_operator=false # used in start_operator()
local should_build_custom_operator=false
local should_deploy_pg_to_namespace_test=false
local should_replace_operator_image=false

while true
do
# if the 1st param is unset, use the empty string as a default value
Expand All @@ -204,19 +231,32 @@ function main(){
display_help
exit 0
;;
-r | --rebuild-operator)
-r | --rebuild-operator) # with minikube restart
should_build_custom_operator=true
break
;;
-n | --deploy-new-operator-image) # without minikube restart that takes minutes
should_replace_operator_image=true
break
;;
-t | --deploy-pg-to-namespace-test) # to test multi-namespace support locally
should_deploy_pg_to_namespace_test=true
break
;;
*) break
;;
esac
done

if ${should_replace_operator_image}; then
deploy_self_built_image
exit 0
fi

clean_up
start_minikube
kubectl create namespace test
start_operator
submit_postgresql_manifest
forward_ports
check_health

Expand Down