Skip to content

Commit a2dbe30

Browse files
authored
K8SPG-708 replace ready/live probe http check with custom command, change pg entrypoint (#1099)
1 parent c6aef45 commit a2dbe30

29 files changed

+3052
-51
lines changed

build/crd/crunchy/generated/postgres-operator.crunchydata.com_postgresclusters.yaml

Lines changed: 264 additions & 0 deletions
Large diffs are not rendered by default.

build/crd/percona/generated/pgv2.percona.com_perconapgclusters.yaml

Lines changed: 264 additions & 0 deletions
Large diffs are not rendered by default.

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: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
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+
10+
if [[ ! -d /tmp/postgres ]]; then
11+
mkdir -p /tmp/postgres
12+
fi
13+
14+
while [ -f "${recovery_file}" ]; do
15+
sleep 3
16+
done
17+
exit 0
18+
fi
19+
20+
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

config/crd/bases/pgv2.percona.com_perconapgclusters.yaml

Lines changed: 264 additions & 0 deletions
Large diffs are not rendered by default.

config/crd/bases/postgres-operator.crunchydata.com_postgresclusters.yaml

Lines changed: 264 additions & 0 deletions
Large diffs are not rendered by default.

deploy/bundle.yaml

Lines changed: 528 additions & 0 deletions
Large diffs are not rendered by default.

deploy/cr.yaml

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,31 @@ spec:
174174
instances:
175175
- name: instance1
176176
replicas: 3
177+
# initContainer:
178+
# image: perconalab/percona-postgresql-operator:main
179+
# resources:
180+
# limits:
181+
# cpu: 2.0
182+
# memory: 4Gi
183+
# containerSecurityContext:
184+
# fsGroup: 1001
185+
# runAsUser: 1001
186+
# runAsNonRoot: true
187+
# fsGroupChangePolicy: "OnRootMismatch"
188+
# runAsGroup: 1001
189+
# seLinuxOptions:
190+
# type: spc_t
191+
# level: s0:c123,c456
192+
# seccompProfile:
193+
# type: Localhost
194+
# localhostProfile: localhost/profile.json
195+
# supplementalGroups:
196+
# - 1001
197+
# sysctls:
198+
# - name: net.ipv4.tcp_keepalive_time
199+
# value: "600"
200+
# - name: net.ipv4.tcp_keepalive_intvl
201+
# value: "60"
177202

178203
affinity:
179204
podAntiAffinity:

deploy/crd.yaml

Lines changed: 528 additions & 0 deletions
Large diffs are not rendered by default.

deploy/cw-bundle.yaml

Lines changed: 528 additions & 0 deletions
Large diffs are not rendered by default.

e2e-tests/functions

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,7 @@ get_cr() {
178178
.spec.users += [{"name":"postgres","password":{"type":"AlphaNumeric"}}] |
179179
.spec.users += [{"name":"'${cr_name}'","password":{"type":"AlphaNumeric"}}] |
180180
.spec.image = "'$IMAGE_POSTGRESQL'" |
181+
.spec.initContainer.image = "perconalab/percona-postgresql-operator:K8SPG-708-12" |
181182
.spec.backups.pgbackrest.image = "'$IMAGE_BACKREST'" |
182183
.spec.proxy.pgBouncer.image = "'$IMAGE_PGBOUNCER'" |
183184
.spec.pmm.image = "'$IMAGE_PMM_CLIENT'" |

e2e-tests/tests/custom-extensions/02-assert.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,8 @@ spec:
5252
- name: postgres-data
5353
- mountPath: /tmp
5454
name: tmp
55+
- command:
56+
- /usr/local/bin/init-entrypoint.sh
5557
- name: nss-wrapper-init
5658
status:
5759
observedGeneration: 2

e2e-tests/tests/custom-extensions/05-assert.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,8 @@ spec:
5252
- name: postgres-data
5353
- mountPath: /tmp
5454
name: tmp
55+
- command:
56+
- /usr/local/bin/init-entrypoint.sh
5557
- name: nss-wrapper-init
5658
status:
5759
observedGeneration: 2

e2e-tests/tests/custom-extensions/06-assert.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,8 @@ spec:
5454
- name: postgres-data
5555
- mountPath: /tmp
5656
name: tmp
57+
- command:
58+
- /usr/local/bin/init-entrypoint.sh
5759
- name: nss-wrapper-init
5860
status:
5961
observedGeneration: 3

e2e-tests/tests/custom-extensions/07-assert.yaml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ spec:
2424
- /usr/local/bin/relocate-extensions.sh
2525
- command:
2626
- /usr/local/bin/install-extensions.sh
27+
- command:
28+
- /usr/local/bin/init-entrypoint.sh
2729
- name: nss-wrapper-init
2830
status:
2931
observedGeneration: 3
@@ -47,4 +49,4 @@ status:
4749
size: 3
4850
ready: 3
4951
size: 3
50-
state: ready
52+
state: ready

internal/controller/postgrescluster/cluster_test.go

Lines changed: 32 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -144,11 +144,17 @@ func TestCustomLabels(t *testing.T) {
144144
cluster.ObjectMeta.Name = "global-cluster"
145145
cluster.ObjectMeta.Namespace = ns.Name
146146
cluster.Spec.InstanceSets = []v1beta1.PostgresInstanceSetSpec{{
147-
Name: "daisy-instance1",
147+
Name: "daisy-instance1",
148+
InitContainer: &v1beta1.InitContainerSpec{
149+
Image: "some-image",
150+
},
148151
Replicas: initialize.Int32(1),
149152
DataVolumeClaimSpec: testVolumeClaimSpec(),
150153
}, {
151-
Name: "daisy-instance2",
154+
Name: "daisy-instance2",
155+
InitContainer: &v1beta1.InitContainerSpec{
156+
Image: "some-image",
157+
},
152158
Replicas: initialize.Int32(1),
153159
DataVolumeClaimSpec: testVolumeClaimSpec(),
154160
}}
@@ -194,14 +200,20 @@ func TestCustomLabels(t *testing.T) {
194200
cluster.ObjectMeta.Name = "instance-cluster"
195201
cluster.ObjectMeta.Namespace = ns.Name
196202
cluster.Spec.InstanceSets = []v1beta1.PostgresInstanceSetSpec{{
197-
Name: "max-instance",
203+
Name: "max-instance",
204+
InitContainer: &v1beta1.InitContainerSpec{
205+
Image: "some-image",
206+
},
198207
Replicas: initialize.Int32(1),
199208
DataVolumeClaimSpec: testVolumeClaimSpec(),
200209
Metadata: &v1beta1.Metadata{
201210
Labels: map[string]string{"my.instance.label": "max"},
202211
},
203212
}, {
204-
Name: "lucy-instance",
213+
Name: "lucy-instance",
214+
InitContainer: &v1beta1.InitContainerSpec{
215+
Image: "some-image",
216+
},
205217
Replicas: initialize.Int32(1),
206218
DataVolumeClaimSpec: testVolumeClaimSpec(),
207219
Metadata: &v1beta1.Metadata{
@@ -396,11 +408,17 @@ func TestCustomAnnotations(t *testing.T) {
396408
cluster.ObjectMeta.Name = "global-cluster"
397409
cluster.ObjectMeta.Namespace = ns.Name
398410
cluster.Spec.InstanceSets = []v1beta1.PostgresInstanceSetSpec{{
399-
Name: "daisy-instance1",
411+
Name: "daisy-instance1",
412+
InitContainer: &v1beta1.InitContainerSpec{
413+
Image: "some-image",
414+
},
400415
Replicas: initialize.Int32(1),
401416
DataVolumeClaimSpec: testVolumeClaimSpec(),
402417
}, {
403-
Name: "daisy-instance2",
418+
Name: "daisy-instance2",
419+
InitContainer: &v1beta1.InitContainerSpec{
420+
Image: "some-image",
421+
},
404422
Replicas: initialize.Int32(1),
405423
DataVolumeClaimSpec: testVolumeClaimSpec(),
406424
}}
@@ -447,14 +465,20 @@ func TestCustomAnnotations(t *testing.T) {
447465
cluster.ObjectMeta.Name = "instance-cluster"
448466
cluster.ObjectMeta.Namespace = ns.Name
449467
cluster.Spec.InstanceSets = []v1beta1.PostgresInstanceSetSpec{{
450-
Name: "max-instance",
468+
Name: "max-instance",
469+
InitContainer: &v1beta1.InitContainerSpec{
470+
Image: "some-image",
471+
},
451472
Replicas: initialize.Int32(1),
452473
DataVolumeClaimSpec: testVolumeClaimSpec(),
453474
Metadata: &v1beta1.Metadata{
454475
Annotations: map[string]string{"my.instance.annotation": "max"},
455476
},
456477
}, {
457-
Name: "lucy-instance",
478+
Name: "lucy-instance",
479+
InitContainer: &v1beta1.InitContainerSpec{
480+
Image: "some-image",
481+
},
458482
Replicas: initialize.Int32(1),
459483
DataVolumeClaimSpec: testVolumeClaimSpec(),
460484
Metadata: &v1beta1.Metadata{

internal/controller/postgrescluster/controller_test.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,8 @@ spec:
9797
image: postgres
9898
instances:
9999
- name: register-now
100+
initContainer:
101+
image: postgres
100102
dataVolumeClaimSpec:
101103
accessModes:
102104
- "ReadWriteMany"
@@ -233,6 +235,8 @@ spec:
233235
image: postgres
234236
instances:
235237
- name: samba
238+
initContainer:
239+
image: postgres
236240
dataVolumeClaimSpec:
237241
accessModes:
238242
- "ReadWriteMany"
@@ -438,6 +442,8 @@ spec:
438442
image: postgres
439443
instances:
440444
- name: samba
445+
initContainer:
446+
image: postgres
441447
dataVolumeClaimSpec:
442448
accessModes:
443449
- "ReadWriteMany"

internal/controller/postgrescluster/helpers_test.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,10 @@ func testCluster() *v1beta1.PostgresCluster {
116116
Name: "myImagePullSecret"},
117117
},
118118
InstanceSets: []v1beta1.PostgresInstanceSetSpec{{
119-
Name: "instance1",
119+
Name: "instance1",
120+
InitContainer: &v1beta1.InitContainerSpec{
121+
Image: "some-image",
122+
},
120123
Replicas: initialize.Int32(1),
121124
DataVolumeClaimSpec: testVolumeClaimSpec(),
122125
}},

internal/controller/postgrescluster/instance.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ import (
3737
"github.com/percona/percona-postgresql-operator/internal/pgbackrest"
3838
"github.com/percona/percona-postgresql-operator/internal/pki"
3939
"github.com/percona/percona-postgresql-operator/internal/postgres"
40+
"github.com/percona/percona-postgresql-operator/percona/k8s"
4041
"github.com/percona/percona-postgresql-operator/pkg/apis/postgres-operator.crunchydata.com/v1beta1"
4142
)
4243

@@ -1206,9 +1207,15 @@ func (r *Reconciler) reconcileInstance(
12061207
ctx, cluster, instanceCertificates, &instance.Spec.Template.Spec)
12071208
}
12081209

1210+
// K8SPG-708
1211+
initImage, err := k8s.InitImage(ctx, r.Client, cluster, spec)
1212+
if err != nil {
1213+
return errors.Wrap(err, "failed to determine initial init image")
1214+
}
1215+
12091216
err = patroni.InstancePod(
12101217
ctx, cluster, clusterConfigMap, clusterPodService, patroniLeaderService,
1211-
spec, instanceCertificates, instanceConfigMap, &instance.Spec.Template)
1218+
spec, instanceCertificates, instanceConfigMap, &instance.Spec.Template, initImage) // K8SPG-708
12121219
}
12131220

12141221
// Add pgMonitor resources to the instance Pod spec

0 commit comments

Comments
 (0)