Skip to content

Commit

Permalink
address comments
Browse files Browse the repository at this point in the history
  • Loading branch information
grac3gao committed Jan 9, 2021
1 parent e9f1d46 commit 57a8063
Showing 1 changed file with 16 additions and 8 deletions.
24 changes: 16 additions & 8 deletions pkg/kncloudevents/message_receiver.go
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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
}
}

Expand Down

0 comments on commit 57a8063

Please sign in to comment.