Skip to content

Commit 95c1eb5

Browse files
authored
feat: add health probes to node & go services (#174)
Until the next release of Quarkus in November, we'll need to have some special checks so that we don't add these probes to Quarkus based functions. In the meantime, we can at least set the liveness and readiness endpoints on the Node.js/Go functions to /health/liveness and /health/readiness respectively. Fixes: #169 Signed-off-by: Lance Ball <lball@redhat.com>
1 parent 5513319 commit 95c1eb5

File tree

1 file changed

+17
-2
lines changed

1 file changed

+17
-2
lines changed

knative/deployer.go

+17-2
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ func (d *Deployer) Deploy(f faas.Function) (err error) {
5757
if d.Verbose {
5858
fmt.Printf("Creating Knative Service: %v\n", serviceName)
5959
}
60-
err := client.CreateService(generateNewService(serviceName, f.Image))
60+
err := client.CreateService(generateNewService(serviceName, f.Image, f.Runtime != "quarkus"))
6161
if err != nil {
6262
err = fmt.Errorf("knative deployer failed to deploy the service: %v", err)
6363
return err
@@ -99,7 +99,17 @@ func (d *Deployer) Deploy(f faas.Function) (err error) {
9999
return nil
100100
}
101101

102-
func generateNewService(name, image string) *servingv1.Service {
102+
func probeFor(url string) *corev1.Probe {
103+
return &corev1.Probe{
104+
Handler: corev1.Handler{
105+
HTTPGet: &corev1.HTTPGetAction{
106+
Path: url,
107+
},
108+
},
109+
}
110+
}
111+
112+
func generateNewService(name, image string, healthChecks bool) *servingv1.Service {
103113
containers := []corev1.Container{
104114
{
105115
Image: image,
@@ -109,6 +119,11 @@ func generateNewService(name, image string) *servingv1.Service {
109119
},
110120
}
111121

122+
if healthChecks {
123+
containers[0].LivenessProbe = probeFor("/health/liveness")
124+
containers[0].ReadinessProbe = probeFor("/health/readiness")
125+
}
126+
112127
return &v1.Service{
113128
ObjectMeta: metav1.ObjectMeta{
114129
Name: name,

0 commit comments

Comments
 (0)