instanceProbes adds Patroni liveness and readiness probes to container.
(cluster *v1beta1.PostgresCluster, container *corev1.Container)
| 143 | |
| 144 | // instanceProbes adds Patroni liveness and readiness probes to container. |
| 145 | func instanceProbes(cluster *v1beta1.PostgresCluster, container *corev1.Container) { |
| 146 | |
| 147 | // Patroni uses a watchdog to ensure that PostgreSQL does not accept commits |
| 148 | // after the leader lock expires, even if Patroni becomes unresponsive. |
| 149 | // - https://github.com/zalando/patroni/blob/v2.0.1/docs/watchdog.rst |
| 150 | // |
| 151 | // Similar functionality is provided by a liveness probe. When the probe |
| 152 | // finally fails, kubelet will send a SIGTERM to the Patroni process. |
| 153 | // If the process does not stop, kubelet will send a SIGKILL after the pod's |
| 154 | // TerminationGracePeriodSeconds. |
| 155 | // - https://docs.k8s.io/concepts/workloads/pods/pod-lifecycle/ |
| 156 | // |
| 157 | // TODO(cbandy): Consider TerminationGracePeriodSeconds' impact here. |
| 158 | // TODO(cbandy): Consider if a PreStop hook is necessary. |
| 159 | container.LivenessProbe = probeTiming(cluster.Spec.Patroni) |
| 160 | container.LivenessProbe.InitialDelaySeconds = 3 |
| 161 | container.LivenessProbe.HTTPGet = &corev1.HTTPGetAction{ |
| 162 | Path: "/liveness", |
| 163 | Port: intstr.FromInt(int(*cluster.Spec.Patroni.Port)), |
| 164 | Scheme: corev1.URISchemeHTTPS, |
| 165 | } |
| 166 | |
| 167 | // Readiness is reflected in the controlling object's status (e.g. ReadyReplicas) |
| 168 | // and allows our controller to react when Patroni bootstrap completes. |
| 169 | // |
| 170 | // When using Endpoints for DCS, this probe does not affect the availability |
| 171 | // of the leader Pod in the leader Service. |
| 172 | container.ReadinessProbe = probeTiming(cluster.Spec.Patroni) |
| 173 | container.ReadinessProbe.InitialDelaySeconds = 3 |
| 174 | container.ReadinessProbe.HTTPGet = &corev1.HTTPGetAction{ |
| 175 | Path: "/readiness", |
| 176 | Port: intstr.FromInt(int(*cluster.Spec.Patroni.Port)), |
| 177 | Scheme: corev1.URISchemeHTTPS, |
| 178 | } |
| 179 | } |
| 180 | |
| 181 | // PodIsPrimary returns whether or not pod is currently acting as the leader with |
| 182 | // the "primary" role. |
no test coverage detected