Skip to content

Commit 292353f

Browse files
committed
added liveness probe for postgres-container
1 parent 2c0588c commit 292353f

File tree

5 files changed

+26
-0
lines changed

5 files changed

+26
-0
lines changed

pkg/apis/cpo.opensource.cybertec.at/v1/operator_configuration_type.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@ type KubernetesMetaConfiguration struct {
102102
PodManagementPolicy string `json:"pod_management_policy,omitempty"`
103103
PersistentVolumeClaimRetentionPolicy map[string]string `json:"persistent_volume_claim_retention_policy,omitempty"`
104104
EnableReadinessProbe bool `json:"enable_readiness_probe,omitempty"`
105+
EnableLivenessProbe bool `json:"enable_liveness_probe,omitempty"`
105106
EnableCrossNamespaceSecret bool `json:"enable_cross_namespace_secret,omitempty"`
106107
}
107108

pkg/cluster/cluster.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -676,6 +676,8 @@ func (c *Cluster) compareContainers(description string, setA, setB []v1.Containe
676676
func(a, b v1.Container) bool { return a.Name != b.Name }),
677677
newCheck("new statefulset %s's %s (index %d) readiness probe does not match the current one",
678678
func(a, b v1.Container) bool { return !reflect.DeepEqual(a.ReadinessProbe, b.ReadinessProbe) }),
679+
newCheck("new statefulset %s's %s (index %d) liveness probe does not match the current one",
680+
func(a, b v1.Container) bool { return !reflect.DeepEqual(a.LivenessProbe, b.LivenessProbe) }),
679681
newCheck("new statefulset %s's %s (index %d) ports do not match the current one",
680682
func(a, b v1.Container) bool { return !comparePorts(a.Ports, b.Ports) }),
681683
newCheck("new statefulset %s's %s (index %d) resources do not match the current ones",

pkg/cluster/k8sres.go

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1292,6 +1292,23 @@ func generateSpiloReadinessProbe() *v1.Probe {
12921292
}
12931293
}
12941294

1295+
func generatePatroniLivenessProbe() *v1.Probe {
1296+
return &v1.Probe{
1297+
FailureThreshold: 6,
1298+
ProbeHandler: v1.ProbeHandler{
1299+
HTTPGet: &v1.HTTPGetAction{
1300+
Path: "/health",
1301+
Port: intstr.IntOrString{IntVal: patroni.ApiPort},
1302+
Scheme: v1.URISchemeHTTP,
1303+
},
1304+
},
1305+
InitialDelaySeconds: 30,
1306+
PeriodSeconds: 10,
1307+
TimeoutSeconds: 5,
1308+
SuccessThreshold: 1,
1309+
}
1310+
}
1311+
12951312
func (c *Cluster) generateStatefulSet(spec *cpov1.PostgresSpec) (*appsv1.StatefulSet, error) {
12961313

12971314
var (
@@ -1451,6 +1468,10 @@ func (c *Cluster) generateStatefulSet(spec *cpov1.PostgresSpec) (*appsv1.Statefu
14511468
if c.OpConfig.EnableReadinessProbe {
14521469
spiloContainer.ReadinessProbe = generateSpiloReadinessProbe()
14531470
}
1471+
//
1472+
if c.OpConfig.EnableLivenessProbe {
1473+
spiloContainer.LivenessProbe = generatePatroniLivenessProbe()
1474+
}
14541475

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

pkg/controller/operator_config.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,7 @@ func (c *Controller) importConfigurationFromCRD(fromCRD *cpov1.OperatorConfigura
121121
result.PodManagementPolicy = util.Coalesce(fromCRD.Kubernetes.PodManagementPolicy, "ordered_ready")
122122
result.PersistentVolumeClaimRetentionPolicy = fromCRD.Kubernetes.PersistentVolumeClaimRetentionPolicy
123123
result.EnableReadinessProbe = fromCRD.Kubernetes.EnableReadinessProbe
124+
result.EnableLivenessProbe = fromCRD.Kubernetes.EnableLivenessProbe
124125
result.MasterPodMoveTimeout = util.CoalesceDuration(time.Duration(fromCRD.Kubernetes.MasterPodMoveTimeout), "10m")
125126
result.EnablePodAntiAffinity = fromCRD.Kubernetes.EnablePodAntiAffinity
126127
result.PodAntiAffinityTopologyKey = util.Coalesce(fromCRD.Kubernetes.PodAntiAffinityTopologyKey, "kubernetes.io/hostname")

pkg/util/config/config.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,7 @@ type Config struct {
248248
PodTerminateGracePeriod time.Duration `name:"pod_terminate_grace_period" default:"5m"`
249249
PodManagementPolicy string `name:"pod_management_policy" default:"ordered_ready"`
250250
EnableReadinessProbe bool `name:"enable_readiness_probe" default:"false"`
251+
EnableLivenessProbe bool `name:"enable_liveness_probe" default:"true"`
251252
ProtectedRoles []string `name:"protected_role_names" default:"admin,cron_admin"`
252253
PostgresSuperuserTeams []string `name:"postgres_superuser_teams" default:""`
253254
SetMemoryRequestToLimit bool `name:"set_memory_request_to_limit" default:"false"`

0 commit comments

Comments
 (0)