Skip to content

Commit af7cbea

Browse files
committed
Use pg_isready health checks for PostgreSQL
Add startup, liveness, and readiness probes to the lightspeed-postgres-server container using pg_isready. Signed-off-by: Lucas Alvares Gomes <lucasagomes@gmail.com>
1 parent a8a71f8 commit af7cbea

2 files changed

Lines changed: 32 additions & 1 deletion

File tree

internal/controller/constants.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,20 @@ const (
6767
PostgresVarRunVolumeMountPath = "/var/run/postgresql"
6868
TmpVolumeName = "tmp-writable-volume"
6969
TmpVolumeMountPath = "/tmp"
70+
// Health probe settings for the PostgreSQL container.
71+
// Startup probe allows up to 300s for initialization (e.g. WAL recovery).
72+
// Liveness uses a longer period/timeout to avoid killing a busy-but-healthy instance.
73+
// Readiness uses a shorter period to quickly pull the pod from traffic when not accepting connections.
74+
PostgresStartupProbeInitialDelaySeconds = int32(5)
75+
PostgresStartupProbePeriodSeconds = int32(10)
76+
PostgresStartupProbeTimeoutSeconds = int32(5)
77+
PostgresStartupProbeFailureThreshold = int32(30)
78+
PostgresLivenessProbePeriodSeconds = int32(30)
79+
PostgresLivenessProbeTimeoutSeconds = int32(10)
80+
PostgresLivenessProbeFailureThreshold = int32(3)
81+
PostgresReadinessProbePeriodSeconds = int32(10)
82+
PostgresReadinessProbeTimeoutSeconds = int32(5)
83+
PostgresReadinessProbeFailureThreshold = int32(3)
7084

7185
// LCore specific
7286
LlamaStackContainerPort = int32(8321)

internal/controller/postgres_deployment.go

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,10 @@ func buildPostgresPodTemplateSpec() corev1.PodTemplateSpec {
142142
AllowPrivilegeEscalation: &[]bool{false}[0],
143143
ReadOnlyRootFilesystem: &[]bool{true}[0],
144144
},
145-
VolumeMounts: volumeMounts,
145+
StartupProbe: buildPostgresProbe(PostgresStartupProbePeriodSeconds, PostgresStartupProbeTimeoutSeconds, PostgresStartupProbeFailureThreshold, PostgresStartupProbeInitialDelaySeconds),
146+
LivenessProbe: buildPostgresProbe(PostgresLivenessProbePeriodSeconds, PostgresLivenessProbeTimeoutSeconds, PostgresLivenessProbeFailureThreshold, 0),
147+
ReadinessProbe: buildPostgresProbe(PostgresReadinessProbePeriodSeconds, PostgresReadinessProbeTimeoutSeconds, PostgresReadinessProbeFailureThreshold, 0),
148+
VolumeMounts: volumeMounts,
146149
Resources: corev1.ResourceRequirements{
147150
Requests: corev1.ResourceList{
148151
corev1.ResourceCPU: resource.MustParse("30m"),
@@ -195,3 +198,17 @@ func buildPostgresPodTemplateSpec() corev1.PodTemplateSpec {
195198
},
196199
}
197200
}
201+
202+
func buildPostgresProbe(period, timeout, failure, initialDelay int32) *corev1.Probe {
203+
return &corev1.Probe{
204+
ProbeHandler: corev1.ProbeHandler{
205+
Exec: &corev1.ExecAction{
206+
Command: []string{"pg_isready", "-U", PostgresDefaultUser, "-d", PostgresDefaultDbName},
207+
},
208+
},
209+
InitialDelaySeconds: initialDelay,
210+
PeriodSeconds: period,
211+
TimeoutSeconds: timeout,
212+
FailureThreshold: failure,
213+
}
214+
}

0 commit comments

Comments
 (0)