Skip to content

Commit 2e817ae

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

File tree

5 files changed

+81
-0
lines changed

5 files changed

+81
-0
lines changed

cmd/kar-controllers/app/options/options.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ type ServerOption struct {
5656
QuotaRestURL string
5757
HealthProbeListenAddr string
5858
DispatchResourceReservationTimeout int64
59+
ReadinessProbeListenAddr string
5960
}
6061

6162
// NewServerOption creates a new CMServer with a default config.

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: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -322,6 +322,18 @@ spec:
322322
imagePullPolicy: {{ .Values.httpServerImage.pullPolicy }}
323323
ports:
324324
- containerPort: 80
325+
livesnessProbe:
326+
httpGet:
327+
path: /healthz
328+
port: 80
329+
initialDelaySeconds: 30
330+
timeoutSeconds: 5
331+
readinessProbe:
332+
httpGet:
333+
path: /readyz
334+
port: 80
335+
initialDelaySeconds: 30
336+
timeoutSeconds: 5
325337
- name: "quota-management"
326338
image: "{{ .Values.httpImage.repository }}:{{ .Values.httpImage.tag }}"
327339
imagePullPolicy: {{ .Values.httpImage.pullPolicy }}
@@ -333,6 +345,18 @@ spec:
333345
#{{ if .Values.volumes.hostPath }}
334346
- name: agent-config-vol
335347
mountPath: /root/kubernetes
348+
livesnessProbe:
349+
httpGet:
350+
path: /healthz
351+
port: 80
352+
initialDelaySeconds: 30
353+
timeoutSeconds: 5
354+
readinessProbe:
355+
httpGet:
356+
path: /readyz
357+
port: 80
358+
initialDelaySeconds: 30
359+
timeoutSeconds: 5
336360
#{{ end }}
337361
#{{ end }}
338362
- name: {{ .Chart.Name }}
@@ -357,6 +381,18 @@ spec:
357381
- name: agent-config-vol
358382
mountPath: /root/kubernetes
359383
#{{ end }}
384+
livesnessProbe:
385+
httpGet:
386+
path: /healthz
387+
port: 80
388+
initialDelaySeconds: 30
389+
timeoutSeconds: 5
390+
readinessProbe:
391+
httpGet:
392+
path: /readyz
393+
port: 80
394+
initialDelaySeconds: 30
395+
timeoutSeconds: 5
360396
#{{ if .Values.configMap.name }}
361397
envFrom:
362398
- configMapRef:

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)