Skip to content

Commit a119772

Browse files
authored
add toggle to turn off readiness probes (zalando#2004)
* add toggle to turn off readiness probes * include PodManagementPolicy and ReadinessProbe in stateful set comparison * add URI scheme to generated readiness probe
1 parent b48034d commit a119772

File tree

12 files changed

+39
-5
lines changed

12 files changed

+39
-5
lines changed

charts/postgres-operator/crds/operatorconfigurations.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,9 @@ spec:
214214
enable_pod_disruption_budget:
215215
type: boolean
216216
default: true
217+
enable_readiness_probe:
218+
type: boolean
219+
default: false
217220
enable_sidecars:
218221
type: boolean
219222
default: true

charts/postgres-operator/values.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,8 @@ configKubernetes:
129129
enable_pod_antiaffinity: false
130130
# toggles PDB to set to MinAvailabe 0 or 1
131131
enable_pod_disruption_budget: true
132+
# toogles readiness probe for database pods
133+
enable_readiness_probe: false
132134
# enables sidecar containers to run alongside Spilo in the same pod
133135
enable_sidecars: true
134136

docs/reference/operator_parameters.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -489,6 +489,14 @@ configuration they are grouped under the `kubernetes` key.
489489
of stateful sets of PG clusters. The default is `ordered_ready`, the second
490490
possible value is `parallel`.
491491

492+
* **enable_readiness_probe**
493+
the operator can set a readiness probe on the statefulset for the database
494+
pods with `InitialDelaySeconds: 6`, `PeriodSeconds: 10`, `TimeoutSeconds: 5`,
495+
`SuccessThreshold: 1` and `FailureThreshold: 3`. When enabling readiness
496+
probes it is recommended to switch the `pod_management_policy` to `parallel`
497+
to avoid unneccesary waiting times in case of multiple instances failing.
498+
The default is `false`.
499+
492500
* **storage_resize_mode**
493501
defines how operator handles the difference between the requested volume size and
494502
the actual size. Available options are:

manifests/configmap.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ data:
5252
# enable_pod_disruption_budget: "true"
5353
# enable_postgres_team_crd: "false"
5454
# enable_postgres_team_crd_superusers: "false"
55+
enable_readiness_probe: "false"
5556
enable_replica_load_balancer: "false"
5657
enable_replica_pooler_load_balancer: "false"
5758
# enable_shm_volume: "true"

manifests/operatorconfiguration.crd.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,9 @@ spec:
212212
enable_pod_disruption_budget:
213213
type: boolean
214214
default: true
215+
enable_readiness_probe:
216+
type: boolean
217+
default: false
215218
enable_sidecars:
216219
type: boolean
217220
default: true

manifests/postgresql-operator-default-configuration.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ configuration:
6060
enable_init_containers: true
6161
enable_pod_antiaffinity: false
6262
enable_pod_disruption_budget: true
63+
enable_readiness_probe: false
6364
enable_sidecars: true
6465
# ignored_annotations:
6566
# - k8s.v1.cni.cncf.io/network-status

pkg/apis/acid.zalan.do/v1/crds.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1275,6 +1275,9 @@ var OperatorConfigCRDResourceValidation = apiextv1.CustomResourceValidation{
12751275
"enable_pod_disruption_budget": {
12761276
Type: "boolean",
12771277
},
1278+
"enable_readiness_probe": {
1279+
Type: "boolean",
1280+
},
12781281
"enable_sidecars": {
12791282
Type: "boolean",
12801283
},

pkg/apis/acid.zalan.do/v1/operator_configuration_type.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@ type KubernetesMetaConfiguration struct {
9898
EnablePodAntiAffinity bool `json:"enable_pod_antiaffinity,omitempty"`
9999
PodAntiAffinityTopologyKey string `json:"pod_antiaffinity_topology_key,omitempty"`
100100
PodManagementPolicy string `json:"pod_management_policy,omitempty"`
101+
EnableReadinessProbe bool `json:"enable_readiness_probe,omitempty"`
101102
EnableCrossNamespaceSecret bool `json:"enable_cross_namespace_secret,omitempty"`
102103
}
103104

pkg/cluster/cluster.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -389,6 +389,11 @@ func (c *Cluster) compareStatefulSetWith(statefulSet *appsv1.StatefulSet) *compa
389389
needsReplace = true
390390
reasons = append(reasons, "new statefulset's annotations do not match: "+reason)
391391
}
392+
if c.Statefulset.Spec.PodManagementPolicy != statefulSet.Spec.PodManagementPolicy {
393+
match = false
394+
needsReplace = true
395+
reasons = append(reasons, "new statefulset's pod management policy do not match")
396+
}
392397

393398
needsRollUpdate, reasons = c.compareContainers("initContainers", c.Statefulset.Spec.Template.Spec.InitContainers, statefulSet.Spec.Template.Spec.InitContainers, needsRollUpdate, reasons)
394399
needsRollUpdate, reasons = c.compareContainers("containers", c.Statefulset.Spec.Template.Spec.Containers, statefulSet.Spec.Template.Spec.Containers, needsRollUpdate, reasons)
@@ -528,6 +533,8 @@ func (c *Cluster) compareContainers(description string, setA, setB []v1.Containe
528533
checks := []containerCheck{
529534
newCheck("new statefulset %s's %s (index %d) name does not match the current one",
530535
func(a, b v1.Container) bool { return a.Name != b.Name }),
536+
newCheck("new statefulset %s's %s (index %d) readiness probe does not match the current one",
537+
func(a, b v1.Container) bool { return !reflect.DeepEqual(a.ReadinessProbe, b.ReadinessProbe) }),
531538
newCheck("new statefulset %s's %s (index %d) ports do not match the current one",
532539
func(a, b v1.Container) bool { return !comparePorts(a.Ports, b.Ports) }),
533540
newCheck("new statefulset %s's %s (index %d) resources do not match the current ones",

pkg/cluster/k8sres.go

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1119,17 +1119,18 @@ func extractPgVersionFromBinPath(binPath string, template string) (string, error
11191119

11201120
func generateSpiloReadinessProbe() *v1.Probe {
11211121
return &v1.Probe{
1122+
FailureThreshold: 3,
11221123
Handler: v1.Handler{
11231124
HTTPGet: &v1.HTTPGetAction{
1124-
Path: "/readiness",
1125-
Port: intstr.IntOrString{IntVal: patroni.ApiPort},
1125+
Path: "/readiness",
1126+
Port: intstr.IntOrString{IntVal: patroni.ApiPort},
1127+
Scheme: v1.URISchemeHTTP,
11261128
},
11271129
},
11281130
InitialDelaySeconds: 6,
11291131
PeriodSeconds: 10,
1130-
TimeoutSeconds: 5,
11311132
SuccessThreshold: 1,
1132-
FailureThreshold: 3,
1133+
TimeoutSeconds: 5,
11331134
}
11341135
}
11351136

@@ -1280,7 +1281,9 @@ func (c *Cluster) generateStatefulSet(spec *acidv1.PostgresSpec) (*appsv1.Statef
12801281
)
12811282

12821283
// Patroni responds 200 to probe only if it either owns the leader lock or postgres is running and DCS is accessible
1283-
spiloContainer.ReadinessProbe = generateSpiloReadinessProbe()
1284+
if c.OpConfig.EnableReadinessProbe {
1285+
spiloContainer.ReadinessProbe = generateSpiloReadinessProbe()
1286+
}
12841287

12851288
// generate container specs for sidecars specified in the cluster manifest
12861289
clusterSpecificSidecars := []v1.Container{}

0 commit comments

Comments
 (0)