diff --git a/pkg/kncloudevents/message_receiver.go b/pkg/kncloudevents/message_receiver.go index f52652d34c0..f947313ad68 100644 --- a/pkg/kncloudevents/message_receiver.go +++ b/pkg/kncloudevents/message_receiver.go @@ -32,6 +32,9 @@ const ( DefaultShutdownTimeout = time.Minute * 1 ) +// HTTPMessageReceiverOption enables further configuration of a HTTPMessageReceiver. +type HTTPMessageReceiverOption func(*HTTPMessageReceiver) + type HTTPMessageReceiver struct { port int @@ -41,18 +44,23 @@ type HTTPMessageReceiver struct { checker http.HandlerFunc } -func NewHTTPMessageReceiver(port int) *HTTPMessageReceiver { - return &HTTPMessageReceiver{ +func NewHTTPMessageReceiver(port int, o ...HTTPMessageReceiverOption) *HTTPMessageReceiver { + h := &HTTPMessageReceiver{ port: port, } + for _, opt := range o { + opt(h) + } + return h } -// NewHTTPMessageReceiverWithChecker takes a handler func, -// which runs as an additional health check in Drainer. -func NewHTTPMessageReceiverWithChecker(port int, checker http.HandlerFunc) *HTTPMessageReceiver { - return &HTTPMessageReceiver{ - port: port, - checker: checker, +// WithChecker takes a handler func which will run as an additional health check in Drainer. +// kncloudevents HTTPMessageReceiver uses Drainer to perform health check. +// By default, Drainer directly writes StatusOK to kubelet probe if the Pod is not draining. +// Users can configure customized liveness and readiness check logic by defining checker here. +func WithChecker(checker http.HandlerFunc) HTTPMessageReceiverOption { + return func(h *HTTPMessageReceiver) { + h.checker = checker } }