Skip to content

Commit 4ebccea

Browse files
authored
Merge pull request #1100 from jimmidyson/healthz-readyz-paths
✨ Make individual readiness and liveness checks accessible
2 parents a3abd26 + bd04ba6 commit 4ebccea

File tree

2 files changed

+36
-4
lines changed

2 files changed

+36
-4
lines changed

pkg/manager/internal.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,8 @@ const (
5252
defaultRetryPeriod = 2 * time.Second
5353
defaultGracefulShutdownPeriod = 30 * time.Second
5454

55-
defaultReadinessEndpoint = "/readyz"
56-
defaultLivenessEndpoint = "/healthz"
55+
defaultReadinessEndpoint = "/readyz/"
56+
defaultLivenessEndpoint = "/healthz/"
5757
defaultMetricsEndpoint = "/metrics"
5858
)
5959

pkg/manager/manager_test.go

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,10 @@ import (
2424
"net"
2525
"net/http"
2626
"os"
27+
"path"
2728
rt "runtime"
2829
"runtime/pprof"
30+
"strings"
2931
"sync"
3032
"time"
3133

@@ -944,7 +946,8 @@ var _ = Describe("manger.Manager", func() {
944946
Expect(err).NotTo(HaveOccurred())
945947

946948
res := fmt.Errorf("not ready yet")
947-
err = m.AddReadyzCheck("check", func(_ *http.Request) error { return res })
949+
namedCheck := "check"
950+
err = m.AddReadyzCheck(namedCheck, func(_ *http.Request) error { return res })
948951
Expect(err).NotTo(HaveOccurred())
949952

950953
s := make(chan struct{})
@@ -967,6 +970,20 @@ var _ = Describe("manger.Manager", func() {
967970
resp, err = http.Get(readinessEndpoint)
968971
Expect(err).NotTo(HaveOccurred())
969972
Expect(resp.StatusCode).To(Equal(http.StatusOK))
973+
974+
// Check readiness path without trailing slash
975+
readinessEndpoint = fmt.Sprint("http://", listener.Addr().String(), strings.TrimSuffix(defaultReadinessEndpoint, "/"))
976+
res = nil
977+
resp, err = http.Get(readinessEndpoint)
978+
Expect(err).NotTo(HaveOccurred())
979+
Expect(resp.StatusCode).To(Equal(http.StatusOK))
980+
981+
// Check readiness path for individual check
982+
readinessEndpoint = fmt.Sprint("http://", listener.Addr().String(), path.Join(defaultReadinessEndpoint, namedCheck))
983+
res = nil
984+
resp, err = http.Get(readinessEndpoint)
985+
Expect(err).NotTo(HaveOccurred())
986+
Expect(resp.StatusCode).To(Equal(http.StatusOK))
970987
})
971988

972989
It("should serve liveness endpoint", func(done Done) {
@@ -975,7 +992,8 @@ var _ = Describe("manger.Manager", func() {
975992
Expect(err).NotTo(HaveOccurred())
976993

977994
res := fmt.Errorf("not alive")
978-
err = m.AddHealthzCheck("check", func(_ *http.Request) error { return res })
995+
namedCheck := "check"
996+
err = m.AddHealthzCheck(namedCheck, func(_ *http.Request) error { return res })
979997
Expect(err).NotTo(HaveOccurred())
980998

981999
s := make(chan struct{})
@@ -998,6 +1016,20 @@ var _ = Describe("manger.Manager", func() {
9981016
resp, err = http.Get(livenessEndpoint)
9991017
Expect(err).NotTo(HaveOccurred())
10001018
Expect(resp.StatusCode).To(Equal(http.StatusOK))
1019+
1020+
// Check liveness path without trailing slash
1021+
livenessEndpoint = fmt.Sprint("http://", listener.Addr().String(), strings.TrimSuffix(defaultLivenessEndpoint, "/"))
1022+
res = nil
1023+
resp, err = http.Get(livenessEndpoint)
1024+
Expect(err).NotTo(HaveOccurred())
1025+
Expect(resp.StatusCode).To(Equal(http.StatusOK))
1026+
1027+
// Check readiness path for individual check
1028+
livenessEndpoint = fmt.Sprint("http://", listener.Addr().String(), path.Join(defaultLivenessEndpoint, namedCheck))
1029+
res = nil
1030+
resp, err = http.Get(livenessEndpoint)
1031+
Expect(err).NotTo(HaveOccurred())
1032+
Expect(resp.StatusCode).To(Equal(http.StatusOK))
10011033
})
10021034
})
10031035

0 commit comments

Comments
 (0)