Skip to content

Commit

Permalink
Add Liveness Probe for EventListener Deployment
Browse files Browse the repository at this point in the history
Add a Liveness Probe for EventListener Deployment at URL /live
  • Loading branch information
khrm authored and tekton-robot committed Feb 18, 2020
1 parent 9a6839a commit d1d9340
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 1 deletion.
1 change: 1 addition & 0 deletions .errcheck.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
flag.Set
os.Setenv
logger.Sync
fmt.Fprint
fmt.Fprintf
fmt.Fprintln
(io.Closer).Close
Expand Down
5 changes: 5 additions & 0 deletions cmd/eventlistenersink/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,5 +97,10 @@ func main() {
// Listen and serve
logger.Infof("Listen and serve on port %s", sinkArgs.Port)
http.HandleFunc("/", r.HandleEvent)
// For handling Liveness Probe
http.HandleFunc("/live", func(w http.ResponseWriter, r *http.Request) {
w.WriteHeader(200)
fmt.Fprint(w, "ok")
})
logger.Fatal(http.ListenAndServe(fmt.Sprintf(":%s", sinkArgs.Port), nil))
}
4 changes: 3 additions & 1 deletion config/controller.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,9 @@ spec:
"-logtostderr",
"-stderrthreshold", "INFO",
"-el-image", "github.com/tektoncd/triggers/cmd/eventlistenersink",
"-el-port", "8080"
"-el-port", "8080",
"-period-seconds", "10",
"-failure-threshold", "1"
]
volumeMounts:
- name: config-logging
Expand Down
17 changes: 17 additions & 0 deletions pkg/reconciler/v1alpha1/eventlistener/eventlistener.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,12 @@ var (
// ElPort defines the port for the EventListener to listen on
ElPort = flag.Int("el-port", 8080,
"The container port for the EventListener to listen on.")
// PeriodSeconds defines Period Seconds for the EventListener Liveness Probe
PeriodSeconds = flag.Int("period-seconds", 10,
"The Period Seconds for the EventListener Liveness Probe.")
// FailureThreshold defines the Failure Threshold for the EventListener Liveness Probe
FailureThreshold = flag.Int("failure-threshold", 1,
"The Failure Threshold for the EventListener Liveness Probe.")
// StaticResourceLabels is a map with all the labels that should be on
// all resources generated by the EventListener
StaticResourceLabels = map[string]string{
Expand Down Expand Up @@ -260,6 +266,17 @@ func (c *Reconciler) reconcileDeployment(el *v1alpha1.EventListener) error {
ContainerPort: int32(*ElPort),
Protocol: corev1.ProtocolTCP,
}},
LivenessProbe: &corev1.Probe{
Handler: corev1.Handler{
HTTPGet: &corev1.HTTPGetAction{
Path: "/live",
Scheme: corev1.URISchemeHTTP,
Port: intstr.FromInt((*ElPort)),
},
},
PeriodSeconds: int32(*PeriodSeconds),
FailureThreshold: int32(*FailureThreshold),
},
Args: []string{
"-el-name", el.Name,
"-el-namespace", el.Namespace,
Expand Down
22 changes: 22 additions & 0 deletions pkg/reconciler/v1alpha1/eventlistener/eventlistener_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,17 @@ func Test_reconcileDeployment(t *testing.T) {
Protocol: corev1.ProtocolTCP,
},
},
LivenessProbe: &corev1.Probe{
Handler: corev1.Handler{
HTTPGet: &corev1.HTTPGetAction{
Path: "/live",
Scheme: corev1.URISchemeHTTP,
Port: intstr.FromInt((*ElPort)),
},
},
PeriodSeconds: int32(*PeriodSeconds),
FailureThreshold: int32(*FailureThreshold),
},
Args: []string{
"-el-name", eventListenerName,
"-el-namespace", namespace,
Expand Down Expand Up @@ -541,6 +552,17 @@ func TestReconcile(t *testing.T) {
ContainerPort: int32(*ElPort),
Protocol: corev1.ProtocolTCP,
}},
LivenessProbe: &corev1.Probe{
Handler: corev1.Handler{
HTTPGet: &corev1.HTTPGetAction{
Path: "/live",
Scheme: corev1.URISchemeHTTP,
Port: intstr.FromInt((*ElPort)),
},
},
PeriodSeconds: int32(*PeriodSeconds),
FailureThreshold: int32(*FailureThreshold),
},
Args: []string{
"-el-name", eventListenerName,
"-el-namespace", namespace,
Expand Down

0 comments on commit d1d9340

Please sign in to comment.