|
| 1 | +#!/bin/bash |
| 2 | + |
| 3 | +# Copyright 2018 Crunchy Data Solutions, Inc. |
| 4 | +# Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | +# you may not use this file except in compliance with the License. |
| 6 | +# You may obtain a copy of the License at |
| 7 | +# |
| 8 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | +# |
| 10 | +# Unless required by applicable law or agreed to in writing, software |
| 11 | +# distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | +# See the License for the specific language governing permissions and |
| 14 | +# limitations under the License. |
| 15 | + |
| 16 | +LOG="pgo-installer.log" |
| 17 | + |
| 18 | +export CO_VERSION=3.2.0-rc3 |
| 19 | +echo -n "Which Operator version do you want to install? ["$CO_VERSION"]" |
| 20 | +read REPLY |
| 21 | +if [[ "$REPLY" != "" ]]; then |
| 22 | + echo "setting CO_VERSION="$REPLY |
| 23 | + export CO_VERSION=$REPLY |
| 24 | +fi |
| 25 | +echo $CO_VERSION is the version entered | tee -a $LOG |
| 26 | + |
| 27 | +echo "Testing for dependencies..." | tee -a $LOG |
| 28 | + |
| 29 | +which wget > /dev/null 2> /dev/null |
| 30 | +if [[ $? -ne 0 ]]; then |
| 31 | + echo "The required dependency wget is missing on your system." | tee -a $LOG |
| 32 | + exit 1 |
| 33 | +fi |
| 34 | +which kubectl > /dev/null 2> /dev/null |
| 35 | +if [[ $? -ne 0 ]]; then |
| 36 | + echo "The required dependency kubectl is missing on your system." | tee -a $LOG |
| 37 | + exit 1 |
| 38 | +fi |
| 39 | + |
| 40 | +echo "" |
| 41 | +echo "Testing kubectl connection..." | tee -a $LOG |
| 42 | +echo "" |
| 43 | +kubectl get namespaces |
| 44 | +if [[ $? -ne 0 ]]; then |
| 45 | + echo "kubectl is not connecting to your Kubernetes Cluster. A successful connection is required to proceed." | tee -a $LOG |
| 46 | + exit 1 |
| 47 | +fi |
| 48 | + |
| 49 | +echo "Connected to Kubernetes." | tee -a $LOG |
| 50 | +echo "" |
| 51 | + |
| 52 | +NAMESPACE=`kubectl config view | grep namespace:` |
| 53 | +echo "The postgres-operator will be installed into the current namespace which is ["$NAMESPACE"]." |
| 54 | + |
| 55 | +echo -n "Do you want to continue the installation? [Yn] " |
| 56 | +read REPLY |
| 57 | +case $REPLY in |
| 58 | +n) |
| 59 | + echo "Aborting installation." |
| 60 | + exit 1 |
| 61 | + ;; |
| 62 | +esac |
| 63 | + |
| 64 | +echo -n "Is this a 'kube' install or an 'ocp' install?" |
| 65 | +read REPLY |
| 66 | +case $REPLY in |
| 67 | +kube) |
| 68 | + echo "user has selected a kube install" | tee -a $LOG |
| 69 | + export CO_CMD=kubectl |
| 70 | + ;; |
| 71 | +ocp) |
| 72 | + echo "user has selected an ocp install" | tee -a $LOG |
| 73 | + export CO_CMD=oc |
| 74 | + ;; |
| 75 | +*) |
| 76 | + echo "user has entered an invalid install type" |
| 77 | + exit 2 |
| 78 | + ;; |
| 79 | +esac |
| 80 | + |
| 81 | +export GOPATH=$HOME/odev |
| 82 | +export GOBIN=$GOPATH/bin |
| 83 | +export PATH=$PATH:$GOPATH/bin |
| 84 | +export CO_IMAGE_PREFIX=crunchydata |
| 85 | +export CO_IMAGE_TAG=centos7-$CO_VERSION |
| 86 | +export COROOT=$GOPATH/src/github.com/crunchydata/postgres-operator |
| 87 | +export CO_APISERVER_URL=https://127.0.0.1:18443 |
| 88 | +export PGO_CA_CERT=$COROOT/conf/apiserver/server.crt |
| 89 | +export PGO_CLIENT_CERT=$COROOT/conf/apiserver/server.crt |
| 90 | +export PGO_CLIENT_KEY=$COROOT/conf/apiserver/server.key |
| 91 | + |
| 92 | +echo "Setting environment variables in $HOME/.bashrc..." | tee -a $LOG |
| 93 | + |
| 94 | +cat <<'EOF' >> $HOME/.bashrc |
| 95 | +
|
| 96 | +# operator env vars |
| 97 | +export CO_APISERVER_URL=https://127.0.0.1:18443 |
| 98 | +export PGO_CA_CERT=$HOME/odev/src/github.com/crunchydata/postgres-operator/conf/apiserver/server.crt |
| 99 | +export PGO_CLIENT_CERT=$HOME/odev/src/github.com/crunchydata/postgres-operator/conf/apiserver/server.crt |
| 100 | +export PGO_CLIENT_KEY=$HOME/odev/src/github.com/crunchydata/postgres-operator/conf/apiserver/server.key |
| 101 | +# |
| 102 | +EOF |
| 103 | + |
| 104 | +echo "Setting up installation directory..." | tee -a $LOG |
| 105 | + |
| 106 | +mkdir -p $HOME/odev/src $HOME/odev/bin $HOME/odev/pkg |
| 107 | +mkdir -p $GOPATH/src/github.com/crunchydata/postgres-operator |
| 108 | + |
| 109 | +echo "" |
| 110 | +echo "Installing pgo server configuration..." | tee -a $LOG |
| 111 | +wget --quiet https://github.com/CrunchyData/postgres-operator/releases/download/$CO_VERSION/postgres-operator.$CO_VERSION.tar.gz -O /tmp/postgres-operator.$CO_VERSION.tar.gz |
| 112 | +if [[ $? -ne 0 ]]; then |
| 113 | + echo "ERROR: Problem getting the pgo server configuration." |
| 114 | + exit 1 |
| 115 | +fi |
| 116 | + |
| 117 | +cd $COROOT |
| 118 | +tar xzf /tmp/postgres-operator.$CO_VERSION.tar.gz |
| 119 | +if [[ $? -ne 0 ]]; then |
| 120 | + echo "ERROR: Problem unpackaging the $CO_VERSION release." |
| 121 | + exit 1 |
| 122 | +fi |
| 123 | + |
| 124 | +echo "" |
| 125 | +echo "Installing pgo client..." | tee -a $LOG |
| 126 | + |
| 127 | +mv pgo $GOBIN |
| 128 | +mv pgo-mac $GOBIN |
| 129 | +mv pgo.exe $GOBIN |
| 130 | +mv expenv.exe $GOBIN |
| 131 | +mv expenv-mac $GOBIN |
| 132 | +mv expenv $GOBIN |
| 133 | + |
| 134 | +echo "The available storage classes on your system:" |
| 135 | +kubectl get sc |
| 136 | +echo "" |
| 137 | +echo -n "Enter the name of the storage class to use: " |
| 138 | +read STORAGE_CLASS |
| 139 | + |
| 140 | +echo "" |
| 141 | +echo "Setting up pgo storage configuration for the selected storageclass..." | tee -a $LOG |
| 142 | +cp $COROOT/examples/pgo.yaml.storageclass $COROOT/conf/apiserver/pgo.yaml |
| 143 | +sed --in-place=.bak 's/standard/'"$STORAGE_CLASS"'/' $COROOT/conf/apiserver/pgo.yaml |
| 144 | +sed --in-place=.bak 's/demo/'"$NAMESPACE"'/' $COROOT/deploy/cluster-rbac.yaml |
| 145 | +sed --in-place=.bak 's/demo/'"$NAMESPACE"'/' $COROOT/deploy/rbac.yaml |
| 146 | + |
| 147 | +echo "" |
| 148 | +echo "Setting up pgo client authentication..." | tee -a $LOG |
| 149 | +echo "username:password" > $HOME/.pgouser |
| 150 | + |
| 151 | +echo "For pgo bash completion you will need to install the bash-completion package." | tee -a $LOG |
| 152 | + |
| 153 | +cp $COROOT/examples/pgo-bash-completion $HOME/.bash_completion |
| 154 | + |
| 155 | +echo -n "Do you want to deploy the operator? [Yn] " |
| 156 | +read REPLY |
| 157 | +case $REPLY in |
| 158 | +n) |
| 159 | + echo "Aborting installation." |
| 160 | + exit 1 |
| 161 | + ;; |
| 162 | +esac |
| 163 | + |
| 164 | +echo "Installing the CRDs and Kube RBAC for the operator to " | tee -a $LOG |
| 165 | +echo "the Kubernetes cluster. " | tee -a $LOG |
| 166 | +echo "NOTE: this step requires cluster-admin privs..." | tee -a $LOG |
| 167 | +echo "in another terminal window, log in as a cluster-admin and " | tee -a $LOG |
| 168 | +echo "execute the following command..." | tee -a $LOG |
| 169 | + |
| 170 | +echo "" |
| 171 | +echo "export CO_CMD="$CO_CMD | tee -a $LOG |
| 172 | +echo "export CO_NAMESPACE="$NAMESPACE | tee -a $LOG |
| 173 | +echo "export PATH=$PATH:$HOME/odev/bin" | tee -a $LOG |
| 174 | +echo "$COROOT/deploy/install-rbac.sh" | tee -a $LOG |
| 175 | + |
| 176 | +echo "" |
| 177 | +echo -n "Are you ready to continue the install?[Yn]" |
| 178 | +read REPLY |
| 179 | +case $REPLY in |
| 180 | +n) |
| 181 | + echo "Aborting installation." |
| 182 | + exit 1 |
| 183 | + ;; |
| 184 | +esac |
| 185 | +echo "Deploying the operator to the Kubernetes cluster..." | tee -a $LOG |
| 186 | +$COROOT/deploy/deploy.sh | tee -a $LOG |
| 187 | + |
| 188 | +echo "Installation complete." | tee -a $LOG |
| 189 | +echo "" |
| 190 | + |
| 191 | +echo "At this point you can access the operator by using a port-forward command similar to:" |
| 192 | +podname=`$CO_CMD get pod --selector=name=postgres-operator -o jsonpath={..metadata.name}` |
| 193 | +echo $CO_CMD" port-forward " $podname " 18443:8443" |
| 194 | +echo "Run this in another terminal or in the background." |
| 195 | + |
| 196 | +echo "" |
| 197 | +echo "WARNING: For the postgres-operator settings to take effect, it is necessary to log out of your session and back in or reload your .bashrc file." |
| 198 | + |
| 199 | +echo "" |
| 200 | +echo "NOTE: In order to access the pgo CLI, place it within your PATH from its default location in $HOME/odev/bin/pgo." |
0 commit comments