Skip to content

Commit 3bafb17

Browse files
leonardocegbartoliniarmruNiccoloFeimnencia
authored
feat: startup and readiness probes for replicas (cloudnative-pg#6623)
Extend the startup and readiness probes configured through the `.spec.probes.startup` and `.spec.probes.readiness` sections by adding two additional parameters: - `type`: Defines the criteria for considering the probe successful. Accepted values include: - `pg_isready`: This setting marks the probe as successful when the `pg_isready` command exits with a status of `0`. This is the default for both primary instances and replicas. - `query`: This setting marks the probe as successful when a basic query is executed locally on the `postgres` database. - `streaming`: This setting marks the probe successful when the replica starts streaming from its source and meets the specified lag requirements (details below). - `lag`: Specifies the maximum acceptable replication lag, measured in bytes (expressed using Kubernetes quantities). This parameter is applicable only when `type` is set to `streaming`. If the `lag` parameter is not specified, the replica is considered successfully started/ready as soon as it begins streaming. Consequently, the liveness probe has been streamlined to verify solely that the instance manager is operational, without monitoring the underlying PostgreSQL instance. Closes: cloudnative-pg#6621 ## Release Notes **Improved Startup and Readiness Probes for Replicas**: Enhanced support for Kubernetes startup and readiness probes in PostgreSQL instances, providing greater control over replicas based on the streaming lag. Signed-off-by: Leonardo Cecchi <leonardo.cecchi@enterprisedb.com> Signed-off-by: Gabriele Bartolini <gabriele.bartolini@enterprisedb.com> Signed-off-by: Leonardo Cecchi <leonardo.cecchi@gmail.com> Signed-off-by: Armando Ruocco <armando.ruocco@enterprisedb.com> Signed-off-by: Niccolò Fei <niccolo.fei@enterprisedb.com> Signed-off-by: Marco Nenciarini <marco.nenciarini@enterprisedb.com> Co-authored-by: Gabriele Bartolini <gabriele.bartolini@enterprisedb.com> Co-authored-by: Armando Ruocco <armando.ruocco@enterprisedb.com> Co-authored-by: Niccolò Fei <niccolo.fei@enterprisedb.com> Co-authored-by: Marco Nenciarini <marco.nenciarini@enterprisedb.com>
1 parent 82d09bf commit 3bafb17

33 files changed

+986
-203
lines changed

.wordlist-en-custom.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -343,7 +343,9 @@ PrimaryUpdateMethod
343343
PrimaryUpdateStrategy
344344
PriorityClass
345345
PriorityClassName
346+
ProbeStrategyType
346347
ProbeTerminationGracePeriod
348+
ProbeWithStrategy
347349
ProbesConfiguration
348350
ProjectedVolumeSource
349351
PublicationReclaimPolicy
@@ -442,6 +444,8 @@ SnapshotType
442444
Snapshotting
443445
Snyk
444446
Stackgres
447+
StartupProbe
448+
StartupStrategyType
445449
StatefulSets
446450
StorageClass
447451
StorageConfiguration
@@ -957,6 +961,7 @@ maxClientConnections
957961
maxParallel
958962
maxStandbyNamesFromCluster
959963
maxSyncReplicas
964+
maximumLag
960965
maxwait
961966
mcache
962967
md
@@ -1348,6 +1353,7 @@ tx
13481353
ubi
13491354
ui
13501355
uid
1356+
uint
13511357
ul
13521358
un
13531359
uncordon

api/v1/cluster_funcs.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1482,6 +1482,16 @@ func (p *Probe) ApplyInto(k8sProbe *corev1.Probe) {
14821482
}
14831483
}
14841484

1485+
// ApplyInto applies the content of the probe configuration in a Kubernetes
1486+
// probe
1487+
func (p *ProbeWithStrategy) ApplyInto(k8sProbe *corev1.Probe) {
1488+
if p == nil {
1489+
return
1490+
}
1491+
1492+
p.Probe.ApplyInto(k8sProbe)
1493+
}
1494+
14851495
// GetEnabledWALArchivePluginName returns the name of the enabled backup plugin or an empty string
14861496
// if no backup plugin is enabled
14871497
func (cluster *Cluster) GetEnabledWALArchivePluginName() string {

api/v1/cluster_types.go

Lines changed: 36 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -487,15 +487,49 @@ type ClusterSpec struct {
487487
// to be injected in the PostgreSQL Pods
488488
type ProbesConfiguration struct {
489489
// The startup probe configuration
490-
Startup *Probe `json:"startup,omitempty"`
490+
Startup *ProbeWithStrategy `json:"startup,omitempty"`
491491

492492
// The liveness probe configuration
493493
Liveness *Probe `json:"liveness,omitempty"`
494494

495495
// The readiness probe configuration
496-
Readiness *Probe `json:"readiness,omitempty"`
496+
Readiness *ProbeWithStrategy `json:"readiness,omitempty"`
497497
}
498498

499+
// ProbeWithStrategy is the configuration of the startup probe
500+
type ProbeWithStrategy struct {
501+
// Probe is the standard probe configuration
502+
Probe `json:",inline"`
503+
504+
// The probe strategy
505+
// +kubebuilder:validation:Enum=pg_isready;streaming;query
506+
// +optional
507+
Type ProbeStrategyType `json:"type,omitempty"`
508+
509+
// Lag limit. Used only for `streaming` strategy
510+
// +optional
511+
MaximumLag *resource.Quantity `json:"maximumLag,omitempty"`
512+
}
513+
514+
// ProbeStrategyType is the type of the strategy used to declare a PostgreSQL instance
515+
// ready
516+
type ProbeStrategyType string
517+
518+
const (
519+
// ProbeStrategyPgIsReady means that the pg_isready tool is used to determine
520+
// whether PostgreSQL is started up
521+
ProbeStrategyPgIsReady ProbeStrategyType = "pg_isready"
522+
523+
// ProbeStrategyStreaming means that pg_isready is positive and the replica is
524+
// connected via streaming replication to the current primary and the lag is, if specified,
525+
// within the limit.
526+
ProbeStrategyStreaming ProbeStrategyType = "streaming"
527+
528+
// ProbeStrategyQuery means that the server is able to connect to the superuser database
529+
// and able to execute a simple query like "-- ping"
530+
ProbeStrategyQuery ProbeStrategyType = "query"
531+
)
532+
499533
// Probe describes a health check to be performed against a container to determine whether it is
500534
// alive or ready to receive traffic.
501535
type Probe struct {

api/v1/zz_generated.deepcopy.go

Lines changed: 23 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

config/crd/bases/postgresql.cnpg.io_clusters.yaml

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4302,6 +4302,13 @@ spec:
43024302
More info: https://kubernetes.io/docs/concepts/workloads/pods/pod-lifecycle#container-probes
43034303
format: int32
43044304
type: integer
4305+
maximumLag:
4306+
anyOf:
4307+
- type: integer
4308+
- type: string
4309+
description: Lag limit. Used only for `streaming` strategy
4310+
pattern: ^(\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))(([KMGTPE]i)|[numkMGTPE]|([eE](\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))))?$
4311+
x-kubernetes-int-or-string: true
43054312
periodSeconds:
43064313
description: |-
43074314
How often (in seconds) to perform the probe.
@@ -4335,6 +4342,13 @@ spec:
43354342
More info: https://kubernetes.io/docs/concepts/workloads/pods/pod-lifecycle#container-probes
43364343
format: int32
43374344
type: integer
4345+
type:
4346+
description: The probe strategy
4347+
enum:
4348+
- pg_isready
4349+
- streaming
4350+
- query
4351+
type: string
43384352
type: object
43394353
startup:
43404354
description: The startup probe configuration
@@ -4351,6 +4365,13 @@ spec:
43514365
More info: https://kubernetes.io/docs/concepts/workloads/pods/pod-lifecycle#container-probes
43524366
format: int32
43534367
type: integer
4368+
maximumLag:
4369+
anyOf:
4370+
- type: integer
4371+
- type: string
4372+
description: Lag limit. Used only for `streaming` strategy
4373+
pattern: ^(\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))(([KMGTPE]i)|[numkMGTPE]|([eE](\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))))?$
4374+
x-kubernetes-int-or-string: true
43544375
periodSeconds:
43554376
description: |-
43564377
How often (in seconds) to perform the probe.
@@ -4384,6 +4405,13 @@ spec:
43844405
More info: https://kubernetes.io/docs/concepts/workloads/pods/pod-lifecycle#container-probes
43854406
format: int32
43864407
type: integer
4408+
type:
4409+
description: The probe strategy
4410+
enum:
4411+
- pg_isready
4412+
- streaming
4413+
- query
4414+
type: string
43874415
type: object
43884416
type: object
43894417
projectedVolumeTemplate:

docs/src/cloudnative-pg.v1.md

Lines changed: 57 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4216,6 +4216,8 @@ the primary server of the cluster as part of rolling updates</p>
42164216

42174217
**Appears in:**
42184218

4219+
- [ProbeWithStrategy](#postgresql-cnpg-io-v1-ProbeWithStrategy)
4220+
42194221
- [ProbesConfiguration](#postgresql-cnpg-io-v1-ProbesConfiguration)
42204222

42214223

@@ -4286,6 +4288,59 @@ Minimum value is 1. spec.terminationGracePeriodSeconds is used if unset.</p>
42864288
</tbody>
42874289
</table>
42884290

4291+
## ProbeStrategyType {#postgresql-cnpg-io-v1-ProbeStrategyType}
4292+
4293+
(Alias of `string`)
4294+
4295+
**Appears in:**
4296+
4297+
- [ProbeWithStrategy](#postgresql-cnpg-io-v1-ProbeWithStrategy)
4298+
4299+
4300+
<p>ProbeStrategyType is the type of the strategy used to declare a PostgreSQL instance
4301+
ready</p>
4302+
4303+
4304+
4305+
4306+
## ProbeWithStrategy {#postgresql-cnpg-io-v1-ProbeWithStrategy}
4307+
4308+
4309+
**Appears in:**
4310+
4311+
- [ProbesConfiguration](#postgresql-cnpg-io-v1-ProbesConfiguration)
4312+
4313+
4314+
<p>ProbeWithStrategy is the configuration of the startup probe</p>
4315+
4316+
4317+
<table class="table">
4318+
<thead><tr><th width="30%">Field</th><th>Description</th></tr></thead>
4319+
<tbody>
4320+
<tr><td><code>Probe</code><br/>
4321+
<a href="#postgresql-cnpg-io-v1-Probe"><i>Probe</i></a>
4322+
</td>
4323+
<td>(Members of <code>Probe</code> are embedded into this type.)
4324+
<p>Probe is the standard probe configuration</p>
4325+
</td>
4326+
</tr>
4327+
<tr><td><code>type</code><br/>
4328+
<a href="#postgresql-cnpg-io-v1-ProbeStrategyType"><i>ProbeStrategyType</i></a>
4329+
</td>
4330+
<td>
4331+
<p>The probe strategy</p>
4332+
</td>
4333+
</tr>
4334+
<tr><td><code>maximumLag</code><br/>
4335+
<a href="https://pkg.go.dev/k8s.io/apimachinery/pkg/api/resource#Quantity"><i>k8s.io/apimachinery/pkg/api/resource.Quantity</i></a>
4336+
</td>
4337+
<td>
4338+
<p>Lag limit. Used only for <code>streaming</code> strategy</p>
4339+
</td>
4340+
</tr>
4341+
</tbody>
4342+
</table>
4343+
42894344
## ProbesConfiguration {#postgresql-cnpg-io-v1-ProbesConfiguration}
42904345

42914346

@@ -4302,7 +4357,7 @@ to be injected in the PostgreSQL Pods</p>
43024357
<thead><tr><th width="30%">Field</th><th>Description</th></tr></thead>
43034358
<tbody>
43044359
<tr><td><code>startup</code> <B>[Required]</B><br/>
4305-
<a href="#postgresql-cnpg-io-v1-Probe"><i>Probe</i></a>
4360+
<a href="#postgresql-cnpg-io-v1-ProbeWithStrategy"><i>ProbeWithStrategy</i></a>
43064361
</td>
43074362
<td>
43084363
<p>The startup probe configuration</p>
@@ -4316,7 +4371,7 @@ to be injected in the PostgreSQL Pods</p>
43164371
</td>
43174372
</tr>
43184373
<tr><td><code>readiness</code> <B>[Required]</B><br/>
4319-
<a href="#postgresql-cnpg-io-v1-Probe"><i>Probe</i></a>
4374+
<a href="#postgresql-cnpg-io-v1-ProbeWithStrategy"><i>ProbeWithStrategy</i></a>
43204375
</td>
43214376
<td>
43224377
<p>The readiness probe configuration</p>

0 commit comments

Comments
 (0)