Skip to content

Commit 4f63c32

Browse files
authored
refactor: improve instance manager liveness probe readability (cloudnative-pg#880)
Closes cloudnative-pg#879 Signed-off-by: Marco Nenciarini <marco.nenciarini@enterprisedb.com>
1 parent e9e0839 commit 4f63c32

File tree

1 file changed

+12
-12
lines changed

1 file changed

+12
-12
lines changed

pkg/management/postgres/webserver/remote.go

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -73,31 +73,31 @@ func (ws *remoteWebserverEndpoints) isServerHealthy(w http.ResponseWriter, r *ht
7373
// If `pg_rewind` is running the Pod is starting up.
7474
// We need to report it healthy to avoid being killed by the kubelet.
7575
// Same goes for instances with fencing on.
76-
if !ws.instance.PgRewindIsRunning && !ws.instance.MightBeUnavailable() {
77-
err := ws.instance.IsServerHealthy()
78-
if err != nil {
79-
log.Info("Liveness probe failing", "err", err.Error())
80-
http.Error(w, err.Error(), http.StatusInternalServerError)
81-
return
82-
}
83-
log.Trace("Liveness probe succeeding")
84-
} else {
76+
if ws.instance.PgRewindIsRunning || ws.instance.MightBeUnavailable() {
8577
log.Trace("Liveness probe skipped")
78+
_, _ = fmt.Fprint(w, "Skipped")
79+
}
80+
81+
err := ws.instance.IsServerHealthy()
82+
if err != nil {
83+
log.Info("Liveness probe failing", "err", err.Error())
84+
http.Error(w, err.Error(), http.StatusInternalServerError)
85+
return
8686
}
87+
88+
log.Trace("Liveness probe succeeding")
8789
_, _ = fmt.Fprint(w, "OK")
8890
}
8991

9092
// This is the readiness probe
9193
func (ws *remoteWebserverEndpoints) isServerReady(w http.ResponseWriter, r *http.Request) {
92-
err := ws.instance.IsServerReady()
93-
if err != nil {
94+
if err := ws.instance.IsServerReady(); err != nil {
9495
log.Info("Readiness probe failing", "err", err.Error())
9596
http.Error(w, err.Error(), http.StatusInternalServerError)
9697
return
9798
}
9899

99100
log.Trace("Readiness probe succeeding")
100-
101101
_, _ = fmt.Fprint(w, "OK")
102102
}
103103

0 commit comments

Comments
 (0)