Skip to content

Commit 41132e6

Browse files
committed
utilize init container for the new .sh
1 parent 84350e5 commit 41132e6

7 files changed

Lines changed: 58 additions & 6 deletions

File tree

build/postgres-operator/Dockerfile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,9 @@ COPY --from=go_builder /usr/local/bin/pgbackrest /usr/local/bin/
6363
COPY --from=go_builder /licenses /licenses
6464
COPY build/postgres-operator/install-extensions.sh /usr/local/bin
6565
COPY build/postgres-operator/init-entrypoint.sh /usr/local/bin
66+
COPY build/postgres-operator/postgres-entrypoint.sh /usr/local/bin
67+
COPY build/postgres-operator/postgres-liveness-check.sh /usr/local/bin
68+
COPY build/postgres-operator/postgres-readiness-check.sh /usr/local/bin
6669
COPY hack/tools/queries /opt/crunchy/conf
6770

6871
RUN chgrp -R 0 /opt/crunchy/conf && chmod -R g=u opt/crunchy/conf

build/postgres-operator/init-entrypoint.sh

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,6 @@ set -o xtrace
66
CRUNCHY_BINDIR="/opt/crunchy"
77

88
install -o "$(id -u)" -g "$(id -g)" -m 0755 -D "/usr/local/bin/pgbackrest" "${CRUNCHY_BINDIR}/bin/pgbackrest"
9+
install -o "$(id -u)" -g "$(id -g)" -m 0755 -D "/usr/local/bin/postgres-entrypoint.sh" "${CRUNCHY_BINDIR}/bin/postgres-entrypoint.sh"
10+
install -o "$(id -u)" -g "$(id -g)" -m 0755 -D "/usr/local/bin/postgres-liveness-check.sh" "${CRUNCHY_BINDIR}/bin/postgres-liveness-check.sh"
11+
install -o "$(id -u)" -g "$(id -g)" -m 0755 -D "/usr/local/bin/postgres-readiness-check.sh" "${CRUNCHY_BINDIR}/bin/postgres-readiness-check.sh"
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#!/bin/bash
2+
3+
# /pgdata/ is already mounted to the pg database container with rw permissions
4+
recovery_file='/pgdata/sleep-forever'
5+
if [[ -f ${recovery_file} ]]; then
6+
set +o xtrace
7+
echo "The $recovery_file file is detected, node entered an infinite sleep"
8+
echo "If you want to exit from the infinite sleep, remove the $recovery_file file"
9+
while [ -f "${recovery_file}" ]; do
10+
sleep 3
11+
done
12+
exit 0
13+
fi
14+
15+
exec "$@"
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#!/bin/bash
2+
3+
PATRONI_PORT=8008
4+
PATRONI_HOST=localhost
5+
6+
# /pgdata/ is already mounted to the pg database container with rw permissions
7+
recovery_file='/pgdata/sleep-forever'
8+
if [ -f "${recovery_file}" ]; then
9+
set +o xtrace
10+
echo "The $recovery_file file is detected, node entered an infinite sleep"
11+
echo "If you want to exit from the infinite sleep, remove the $recovery_file file"
12+
exit 0
13+
fi
14+
15+
response=$(curl -s -o /dev/null -w "%{http_code}" -k "https://${PATRONI_HOST}:${PATRONI_PORT}/liveness")
16+
17+
if [[ $response -eq 200 ]]; then
18+
exit 0
19+
fi
20+
exit 1
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#!/bin/bash
2+
3+
PATRONI_PORT=8008
4+
PATRONI_HOST=localhost
5+
6+
response=$(curl -s -o /dev/null -w "%{http_code}" -k "https://${PATRONI_HOST}:${PATRONI_PORT}/readiness")
7+
8+
if [[ $response -eq 200 ]]; then
9+
exit 0
10+
fi
11+
exit 1

internal/patroni/reconcile.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ func InstancePod(ctx context.Context,
107107
container.Command = []string{"patroni", configDirectory}
108108
// K8SPG-708 introduces a new entrypoint script in the percona-docker repository.
109109
if inCluster.CompareVersion("2.7.0") >= 0 {
110-
container.Command = []string{"/usr/local/bin/entrypoint.sh", "patroni", configDirectory}
110+
container.Command = []string{"/opt/crunchy/bin/postgres-entrypoint.sh", "patroni", configDirectory}
111111
}
112112

113113
container.Env = append(container.Env,
@@ -178,7 +178,7 @@ func livenessProbe(cluster *v1beta1.PostgresCluster) corev1.ProbeHandler {
178178
if cluster.CompareVersion("2.7.0") >= 0 {
179179
return corev1.ProbeHandler{
180180
Exec: &corev1.ExecAction{
181-
Command: []string{"bash", "-c", "/usr/local/bin/postgres-liveness-check.sh"},
181+
Command: []string{"bash", "-c", "/opt/crunchy/bin/postgres-liveness-check.sh"},
182182
},
183183
}
184184
}
@@ -199,7 +199,7 @@ func readinessProbe(cluster *v1beta1.PostgresCluster) corev1.ProbeHandler {
199199
if cluster.CompareVersion("2.7.0") >= 0 {
200200
return corev1.ProbeHandler{
201201
Exec: &corev1.ExecAction{
202-
Command: []string{"bash", "-c", "/usr/local/bin/postgres-readiness-check.sh"},
202+
Command: []string{"bash", "-c", "/opt/crunchy/bin/postgres-readiness-check.sh"},
203203
},
204204
}
205205
}

internal/patroni/reconcile_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ func TestInstancePod(t *testing.T) {
123123
expectedSpec: `
124124
containers:
125125
- command:
126-
- /usr/local/bin/entrypoint.sh
126+
- /opt/crunchy/bin/postgres-entrypoint.sh
127127
- patroni
128128
- /etc/patroni
129129
env:
@@ -159,7 +159,7 @@ containers:
159159
command:
160160
- bash
161161
- -c
162-
- /usr/local/bin/postgres-liveness-check.sh
162+
- /opt/crunchy/bin/postgres-liveness-check.sh
163163
failureThreshold: 3
164164
initialDelaySeconds: 3
165165
periodSeconds: 10
@@ -171,7 +171,7 @@ containers:
171171
command:
172172
- bash
173173
- -c
174-
- /usr/local/bin/postgres-readiness-check.sh
174+
- /opt/crunchy/bin/postgres-readiness-check.sh
175175
failureThreshold: 3
176176
initialDelaySeconds: 3
177177
periodSeconds: 10

0 commit comments

Comments
 (0)