Skip to content

Commit f98f373

Browse files
committed
perf: add readiness and health probes
1 parent 8ccf757 commit f98f373

File tree

5 files changed

+70
-0
lines changed

5 files changed

+70
-0
lines changed

cmd/kar-controllers/app/server.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ import (
3838
"github.com/project-codeflare/multi-cluster-app-dispatcher/cmd/kar-controllers/app/options"
3939
"github.com/project-codeflare/multi-cluster-app-dispatcher/pkg/controller/queuejob"
4040
"github.com/project-codeflare/multi-cluster-app-dispatcher/pkg/health"
41+
ready "github.com/project-codeflare/multi-cluster-app-dispatcher/pkg/ready"
4142

4243
_ "k8s.io/client-go/plugin/pkg/client/auth/gcp"
4344
)
@@ -79,10 +80,12 @@ func Run(opt *options.ServerOption) error {
7980
func listenHealthProbe(opt *options.ServerOption) error {
8081
handler := http.NewServeMux()
8182
handler.Handle("/healthz", &health.Handler{})
83+
handler.Handle("/readyz", &ready.Handler{})
8284
err := http.ListenAndServe(opt.HealthProbeListenAddr, handler)
8385
if err != nil {
8486
return err
8587
}
8688

8789
return nil
8890
}
91+

deployment/mcad-controller/templates/deployment.yaml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -357,6 +357,18 @@ spec:
357357
- name: agent-config-vol
358358
mountPath: /root/kubernetes
359359
#{{ end }}
360+
livesnessProbe:
361+
httpGet:
362+
path: /healthz
363+
port: 8081
364+
initialDelaySeconds: 30
365+
timeoutSeconds: 5
366+
readinessProbe:
367+
httpGet:
368+
path: /readyz
369+
port: 8081
370+
initialDelaySeconds: 30
371+
timeoutSeconds: 5
360372
#{{ if .Values.configMap.name }}
361373
envFrom:
362374
- configMapRef:

pkg/quotaplugins/quota-forest/quota-manager/main.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,3 +82,17 @@ func main() {
8282

8383
fmt.Println(quotaManager)
8484
}
85+
86+
87+
// Starts the health probe listener
88+
func listenHealthProbe(opt *options.ServerOption) error {
89+
handler := http.NewServeMux()
90+
handler.Handle("/healthz", &health.Handler{})
91+
handler.Handle("/readyz", &ready.Handler{})
92+
err := http.ListenAndServe(opt.HealthProbeListenAddr, handler)
93+
if err != nil {
94+
return err
95+
}
96+
97+
return nil
98+
}

pkg/ready/readiness.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
package readiness
2+
3+
import (
4+
"fmt"
5+
"net/http"
6+
)
7+
8+
type Handler struct {
9+
}
10+
11+
func (h *Handler) ServeHTTP(resp http.ResponseWriter, req *http.Request) {
12+
fmt.Fprint(resp, "ok")
13+
}
14+

pkg/ready/readiness_test.go

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
package readiness
2+
3+
import (
4+
"net/http"
5+
"net/http/httptest"
6+
"testing"
7+
)
8+
9+
func TestReadinessProbe(t *testing.T) {
10+
req, err := http.NewRequest("GET", "/readyz", nil)
11+
if err != nil {
12+
t.Fatal(err)
13+
}
14+
15+
rr := httptest.NewRecorder()
16+
handler := Handler{}
17+
handler.ServeHTTP(rr, req)
18+
if status := rr.Code; status != http.StatusOK {
19+
t.Errorf("handler returned unexpected status: %v", status)
20+
}
21+
22+
expected := "ok"
23+
if rr.Body.String() != expected {
24+
t.Errorf("handler returned unexpected body: got %v expected %v",
25+
rr.Body.String(), expected)
26+
}
27+
}

0 commit comments

Comments
 (0)