-
Notifications
You must be signed in to change notification settings - Fork 481
/
Copy pathprobes.go
63 lines (54 loc) · 1.66 KB
/
probes.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
// License: OpenFaaS Community Edition (CE) EULA
// Copyright (c) 2017,2019-2024 OpenFaaS Author(s)
package k8s
import (
"path/filepath"
types "github.com/openfaas/faas-provider/types"
corev1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/util/intstr"
)
type FunctionProbes struct {
Liveness *corev1.Probe
Readiness *corev1.Probe
}
// MakeProbes returns the liveness and readiness probes
// by default the health check runs `cat /tmp/.lock` every ten seconds
func (f *FunctionFactory) MakeProbes(r types.FunctionDeployment) (*FunctionProbes, error) {
var handler corev1.ProbeHandler
if f.Config.HTTPProbe {
handler = corev1.ProbeHandler{
HTTPGet: &corev1.HTTPGetAction{
Path: "/_/health",
Port: intstr.IntOrString{
Type: intstr.Int,
IntVal: int32(f.Config.RuntimeHTTPPort),
},
},
}
} else {
path := filepath.Join("/tmp/", ".lock")
handler = corev1.ProbeHandler{
Exec: &corev1.ExecAction{
Command: []string{"cat", path},
},
}
}
probes := FunctionProbes{}
probes.Readiness = &corev1.Probe{
ProbeHandler: handler,
InitialDelaySeconds: f.Config.ReadinessProbe.InitialDelaySeconds,
TimeoutSeconds: int32(f.Config.ReadinessProbe.TimeoutSeconds),
PeriodSeconds: int32(f.Config.ReadinessProbe.PeriodSeconds),
SuccessThreshold: 1,
FailureThreshold: 3,
}
probes.Liveness = &corev1.Probe{
ProbeHandler: handler,
InitialDelaySeconds: f.Config.LivenessProbe.InitialDelaySeconds,
TimeoutSeconds: int32(f.Config.LivenessProbe.TimeoutSeconds),
PeriodSeconds: int32(f.Config.LivenessProbe.PeriodSeconds),
SuccessThreshold: 1,
FailureThreshold: 3,
}
return &probes, nil
}