Skip to content

Commit 09e07ca

Browse files
authored
Installer client-setup script: download pgo client binary
This update will download the `pgo` (Linux) or `pgo-mac` (Darwin) binary from github based on the operating system. The binary will be downloaded to `~/.pgo/<operator-namespace>` and should be added to the users `PATH`.
1 parent 6fbd86b commit 09e07ca

File tree

2 files changed

+44
-10
lines changed

2 files changed

+44
-10
lines changed

docs/content/installation/postgres-operator.md

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -182,15 +182,19 @@ chmod +x client-setup.sh
182182
```
183183

184184
{{% notice tip %}}
185-
Running this script can cause existing `pgouser`, `client.crt`, and `client.key`
186-
files to be overwritten.
185+
Running this script can cause existing `pgo` client binary, `pgouser`,
186+
`client.crt`, and `client.key` files to be overwritten.
187187
{{% /notice %}}
188188

189189
The `client-setup.sh` script performs the following tasks:
190190

191191
- Sets `$PGO_OPERATOR_NAMESPACE` to `pgo` if it is unset. This is the default
192-
namespace that the PostgreSQL Operator is deployed to
192+
namespace that the PostgreSQßL Operator is deployed to
193+
- Checks for valid Operating Systems and determines which `pgo` binary to
194+
download
193195
- Creates a directory in `$HOME/.pgo/$PGO_OPERATOR_NAMESPACE` (e.g. `/home/hippo/.pgo/pgo`)
196+
- Downloads the `pgo` binary, saves it to in `$HOME/.pgo/$PGO_OPERATOR_NAMESPACE`,
197+
and sets it to be executable
194198
- Pulls the TLS keypair from the PostgreSQL Operator `pgo.tls` Secret so that
195199
the `pgo` client can communicate with the PostgreSQL Operator. These are saved
196200
as `client.crt` and `client.key` in the `$HOME/.pgo/$PGO_OPERATOR_NAMESPACE`
@@ -214,13 +218,20 @@ environmental variables to your environment:
214218

215219
```shell
216220
cat <<EOF >> ~/.bashrc
221+
export PATH="$HOME/.pgo/$PGO_OPERATOR_NAMESPACE/pgo:$PATH"
217222
export PGOUSER="$HOME/.pgo/$PGO_OPERATOR_NAMESPACE/pgouser"
218223
export PGO_CA_CERT="$HOME/.pgo/$PGO_OPERATOR_NAMESPACE/client.crt"
219224
export PGO_CLIENT_CERT="$HOME/.pgo/$PGO_OPERATOR_NAMESPACE/client.crt"
220225
export PGO_CLIENT_KEY="$HOME/.pgo/$PGO_OPERATOR_NAMESPACE/client.key"
221226
EOF
222227
```
223228

229+
{{% notice tip %}}
230+
If you are using MacOS the `pgo-mac` binary will need to be renamed to `pgo`.
231+
Alternatively, you can update your path to include `pgo-mac`.
232+
`export PATH="$HOME/.pgo/$PGO_OPERATOR_NAMESPACE/pgo-mac:$PATH"`
233+
{{% /notice %}}
234+
224235
By default, the `client-setup.sh` script targets the user that is stored in the
225236
`pgouser-admin` secret in the `pgo` (`$PGO_OPERATOR_NAMESPACE`) Namespace. If
226237
you wish to use a different Secret, you can set the `PGO_USER_ADMIN`

installers/kubectl/client-setup.sh

Lines changed: 30 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,35 @@
1414
# This script should be run after the operator has been deployed
1515
export PGO_OPERATOR_NAMESPACE="${PGO_OPERATOR_NAMESPACE:-pgo}"
1616
PGO_USER_ADMIN="${PGO_USER_ADMIN:-pgouser-admin}"
17+
PGO_CLIENT_VERSION="${PGO_CLIENT_VERSION:-v4.3.0}"
18+
PGO_CLIENT_URL="https://github.com/CrunchyData/postgres-operator/releases/download/${PGO_CLIENT_VERSION}"
19+
20+
# Checks operating system and determines which binary to download
21+
UNAME_RESULT=$(uname)
22+
if [[ "${UNAME_RESULT}" == "Linux" ]]
23+
then
24+
BIN_NAME="pgo"
25+
elif [[ "${UNAME_RESULT}" == "Darwin" ]]
26+
then
27+
BIN_NAME="pgo-mac"
28+
else
29+
echo "${UNAME_RESULT} is not supported, valid operating systems are: Linux, Darwin"
30+
echo "Exiting..."
31+
exit 1
32+
fi
33+
34+
# Creates the output directory for files
35+
OUTPUT_DIR="${HOME}/.pgo/${PGO_OPERATOR_NAMESPACE}"
36+
mkdir -p "${OUTPUT_DIR}"
37+
# lock down the directory to just this user
38+
chmod a-rwx,u+rwx "${OUTPUT_DIR}"
39+
40+
echo "Operating System found is ${UNAME_RESULT}. Downloading ${BIN_NAME} client binary..."
41+
42+
FULL_PATH="${PGO_CLIENT_URL}/${BIN_NAME}"
43+
curl -L "${FULL_PATH}" -o "${OUTPUT_DIR}/${BIN_NAME}"
44+
chmod +x "${OUTPUT_DIR}/${BIN_NAME}"
45+
1746

1847
# Check that the pgouser-admin secret exists
1948
if [ -z "$(kubectl get secret -n ${PGO_OPERATOR_NAMESPACE} ${PGO_USER_ADMIN})" ]
@@ -33,13 +62,6 @@ then
3362
exit 1
3463
fi
3564

36-
37-
# Creates the output directory for files
38-
OUTPUT_DIR="${HOME}/.pgo/${PGO_OPERATOR_NAMESPACE}"
39-
mkdir -p "${OUTPUT_DIR}"
40-
# lock down the directory to just this user
41-
chmod a-rwx,u+rwx "${OUTPUT_DIR}"
42-
4365
# Use the pgouser-admin secret to generate pgouser file
4466
kubectl get secret -n "${PGO_OPERATOR_NAMESPACE}" "${PGO_USER_ADMIN}" -o 'go-template={{.data.username | base64decode }}:{{.data.password | base64decode}}' > $OUTPUT_DIR/pgouser
4567
# ensure this file is locked down to the specific user running this
@@ -54,6 +76,7 @@ chmod a-rwx,u+rw "${OUTPUT_DIR}/client.crt" "${OUTPUT_DIR}/client.key"
5476

5577

5678
echo "pgo client files have been generated, please add the following to your bashrc"
79+
echo "export PATH=${OUTPUT_DIR}/${BIN_NAME}:\$PATH"
5780
echo "export PGOUSER=${OUTPUT_DIR}/pgouser"
5881
echo "export PGO_CA_CERT=${OUTPUT_DIR}/client.crt"
5982
echo "export PGO_CLIENT_CERT=${OUTPUT_DIR}/client.crt"

0 commit comments

Comments
 (0)