Skip to content

Commit 3bd9abb

Browse files
committed
Adds the kube-ssh-wrapper.sh script for using
kubectl in lieu of ssh with pgBackRest, and updates various pgBackRest configuration settings to fully disable sshd and utilize the kubectl wrapper script instead.
1 parent 11d34b6 commit 3bd9abb

File tree

5 files changed

+34
-5
lines changed

5 files changed

+34
-5
lines changed

bin/kube-ssh-wrapper.sh

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#!/bin/bash
2+
3+
# Determine if connecting to the backrest repo or primary db
4+
if [[ "${PGO_BACKREST_REPO}" == "true" ]]
5+
then
6+
source "/tmp/pod_env.sh"
7+
TARGET_LABEL="role=master"
8+
else
9+
TARGET_LABEL="pgo-backrest-repo=true"
10+
fi
11+
12+
CLUSTER_LABEL="pg-cluster=${CLUSTER_NAME}"
13+
CONTAINER_NAME="database"
14+
15+
opts=$(echo "$@" | grep -o "\-\-c.*")
16+
pod=$(kubectl get pods --selector=${CLUSTER_LABEL},${TARGET_LABEL} --field-selector=status.phase=Running -o name)
17+
18+
exec kubectl exec -i "${pod}" -c ${CONTAINER_NAME} -- bash -c "pgbackrest ${opts}"

conf/postgres-operator/backrest-restore-job.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@
8282
"value": "warn"
8383
}, {
8484
"name": "PGBACKREST_CMD_SSH",
85-
"value": "ssh"
85+
"value": "/opt/cpm/bin/kube-ssh-wrapper.sh"
8686
}, {
8787
"name": "CLUSTER_NAME",
8888
"valueFrom": {

conf/postgres-operator/cluster-deployment.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,13 @@
113113
}, {
114114
"name": "PGHOST",
115115
"value": "/tmp"
116+
}, {
117+
"name": "CLUSTER_NAME",
118+
"valueFrom": {
119+
"fieldRef": {
120+
"fieldPath": "metadata.labels['pg-cluster']"
121+
}
122+
}
116123
}],
117124

118125

@@ -280,3 +287,4 @@
280287
}
281288
}
282289
}
290+

conf/postgres-operator/pgbackrest-env-vars.json

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
"name": "BACKREST_SKIP_CREATE_STANZA",
88
"value": "true"
99
}, {
10-
"name": "PGBACKREST",
10+
"name": "PGHA_PGBACKREST",
1111
"value": "true"
1212
}, {
1313
"name": "PGBACKREST_REPO1_PATH",
@@ -17,7 +17,7 @@
1717
"value": "{{.PgbackrestDBPath}}"
1818
}, {
1919
"name": "ENABLE_SSHD",
20-
"value": "true"
20+
"value": "false"
2121
}, {
2222
"name": "PGBACKREST_LOG_PATH",
2323
"value": "/tmp"
@@ -34,3 +34,6 @@
3434
"name": "BACKREST_LOCAL_AND_S3_STORAGE",
3535
"value": "{{.PgbackrestLocalAndS3Storage}}"
3636
}, {
37+
"name": "PGBACKREST_CMD_SSH",
38+
"value": "/opt/cpm/bin/kube-ssh-wrapper.sh"
39+
}, {

conf/postgres-operator/pgo-backrest-repo-template.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@
7070
"value": "{{.PGbackrestDBHost}}"
7171
}, {
7272
"name": "PGBACKREST_CMD_SSH",
73-
"value": "ssh"
73+
"value": "/opt/cpm/bin/kube-ssh-wrapper.sh"
7474
}, {
7575
"name": "PGBACKREST_LOG_LEVEL_CONSOLE",
7676
"value": "warn"
@@ -86,7 +86,7 @@
8686
"value": "true"
8787
}, {
8888
"name": "ENABLE_SSHD",
89-
"value": "true"
89+
"value": "false"
9090
}],
9191
"volumeMounts": [{
9292
"name": "sshd",

0 commit comments

Comments
 (0)