Skip to content

Commit d1d9340

Browse files
khrmtekton-robot
authored andcommitted
Add Liveness Probe for EventListener Deployment
Add a Liveness Probe for EventListener Deployment at URL /live
1 parent 9a6839a commit d1d9340

File tree

5 files changed

+48
-1
lines changed

5 files changed

+48
-1
lines changed

.errcheck.txt

+1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
flag.Set
33
os.Setenv
44
logger.Sync
5+
fmt.Fprint
56
fmt.Fprintf
67
fmt.Fprintln
78
(io.Closer).Close

cmd/eventlistenersink/main.go

+5
Original file line numberDiff line numberDiff line change
@@ -97,5 +97,10 @@ func main() {
9797
// Listen and serve
9898
logger.Infof("Listen and serve on port %s", sinkArgs.Port)
9999
http.HandleFunc("/", r.HandleEvent)
100+
// For handling Liveness Probe
101+
http.HandleFunc("/live", func(w http.ResponseWriter, r *http.Request) {
102+
w.WriteHeader(200)
103+
fmt.Fprint(w, "ok")
104+
})
100105
logger.Fatal(http.ListenAndServe(fmt.Sprintf(":%s", sinkArgs.Port), nil))
101106
}

config/controller.yaml

+3-1
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,9 @@ spec:
4545
"-logtostderr",
4646
"-stderrthreshold", "INFO",
4747
"-el-image", "github.com/tektoncd/triggers/cmd/eventlistenersink",
48-
"-el-port", "8080"
48+
"-el-port", "8080",
49+
"-period-seconds", "10",
50+
"-failure-threshold", "1"
4951
]
5052
volumeMounts:
5153
- name: config-logging

pkg/reconciler/v1alpha1/eventlistener/eventlistener.go

+17
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,12 @@ var (
6464
// ElPort defines the port for the EventListener to listen on
6565
ElPort = flag.Int("el-port", 8080,
6666
"The container port for the EventListener to listen on.")
67+
// PeriodSeconds defines Period Seconds for the EventListener Liveness Probe
68+
PeriodSeconds = flag.Int("period-seconds", 10,
69+
"The Period Seconds for the EventListener Liveness Probe.")
70+
// FailureThreshold defines the Failure Threshold for the EventListener Liveness Probe
71+
FailureThreshold = flag.Int("failure-threshold", 1,
72+
"The Failure Threshold for the EventListener Liveness Probe.")
6773
// StaticResourceLabels is a map with all the labels that should be on
6874
// all resources generated by the EventListener
6975
StaticResourceLabels = map[string]string{
@@ -260,6 +266,17 @@ func (c *Reconciler) reconcileDeployment(el *v1alpha1.EventListener) error {
260266
ContainerPort: int32(*ElPort),
261267
Protocol: corev1.ProtocolTCP,
262268
}},
269+
LivenessProbe: &corev1.Probe{
270+
Handler: corev1.Handler{
271+
HTTPGet: &corev1.HTTPGetAction{
272+
Path: "/live",
273+
Scheme: corev1.URISchemeHTTP,
274+
Port: intstr.FromInt((*ElPort)),
275+
},
276+
},
277+
PeriodSeconds: int32(*PeriodSeconds),
278+
FailureThreshold: int32(*FailureThreshold),
279+
},
263280
Args: []string{
264281
"-el-name", el.Name,
265282
"-el-namespace", el.Namespace,

pkg/reconciler/v1alpha1/eventlistener/eventlistener_test.go

+22
Original file line numberDiff line numberDiff line change
@@ -284,6 +284,17 @@ func Test_reconcileDeployment(t *testing.T) {
284284
Protocol: corev1.ProtocolTCP,
285285
},
286286
},
287+
LivenessProbe: &corev1.Probe{
288+
Handler: corev1.Handler{
289+
HTTPGet: &corev1.HTTPGetAction{
290+
Path: "/live",
291+
Scheme: corev1.URISchemeHTTP,
292+
Port: intstr.FromInt((*ElPort)),
293+
},
294+
},
295+
PeriodSeconds: int32(*PeriodSeconds),
296+
FailureThreshold: int32(*FailureThreshold),
297+
},
287298
Args: []string{
288299
"-el-name", eventListenerName,
289300
"-el-namespace", namespace,
@@ -541,6 +552,17 @@ func TestReconcile(t *testing.T) {
541552
ContainerPort: int32(*ElPort),
542553
Protocol: corev1.ProtocolTCP,
543554
}},
555+
LivenessProbe: &corev1.Probe{
556+
Handler: corev1.Handler{
557+
HTTPGet: &corev1.HTTPGetAction{
558+
Path: "/live",
559+
Scheme: corev1.URISchemeHTTP,
560+
Port: intstr.FromInt((*ElPort)),
561+
},
562+
},
563+
PeriodSeconds: int32(*PeriodSeconds),
564+
FailureThreshold: int32(*FailureThreshold),
565+
},
544566
Args: []string{
545567
"-el-name", eventListenerName,
546568
"-el-namespace", namespace,

0 commit comments

Comments
 (0)