Skip to content

Commit 827c67f

Browse files
committed
add more loggings
1 parent 96b67f2 commit 827c67f

File tree

3 files changed

+10
-1
lines changed

3 files changed

+10
-1
lines changed

pkg/webhook/admission/http.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ func (wh *Webhook) ServeHTTP(w http.ResponseWriter, r *http.Request) {
4848
var reviewResponse Response
4949
if r.Body != nil {
5050
if body, err = ioutil.ReadAll(r.Body); err != nil {
51-
wh.log.Error(err, "unable to read the body from the incoming request")
51+
wh.log.Error(err, "unable to read the body from the incoming request", "request", r)
5252
reviewResponse = Errored(http.StatusBadRequest, err)
5353
wh.writeResponse(w, reviewResponse)
5454
return
@@ -97,5 +97,7 @@ func (wh *Webhook) writeResponse(w io.Writer, response Response) {
9797
if err != nil {
9898
wh.log.Error(err, "unable to encode the response")
9999
wh.writeResponse(w, Errored(http.StatusInternalServerError, err))
100+
} else {
101+
wh.log.V(1).Info("encoded response", "admission response", responseAdmissionReview)
100102
}
101103
}

pkg/webhook/admission/http_test.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ import (
2929
"sigs.k8s.io/controller-runtime/pkg/runtime/inject"
3030

3131
admissionv1beta1 "k8s.io/api/admission/v1beta1"
32+
logf "sigs.k8s.io/controller-runtime/pkg/internal/log"
3233
)
3334

3435
var _ = Describe("Admission Webhooks", func() {
@@ -87,6 +88,7 @@ var _ = Describe("Admission Webhooks", func() {
8788
}
8889
webhook := &Webhook{
8990
Handler: &fakeHandler{},
91+
log: logf.RuntimeLog.WithName("webhook"),
9092
}
9193

9294
expected := []byte(`{"response":{"uid":"","allowed":true,"status":{"metadata":{},"code":200}}}

pkg/webhook/server.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,8 @@ func (s *Server) Start(stop <-chan struct{}) error {
119119
s.defaultingOnce.Do(s.setDefaults)
120120

121121
baseHookLog := log.WithName("webhooks")
122+
baseHookLog.Info("starting webhook server")
123+
122124
// inject fields here as opposed to in Register so that we're certain to have our setFields
123125
// function available.
124126
for hookPath, webhook := range s.webhooks {
@@ -132,6 +134,7 @@ func (s *Server) Start(stop <-chan struct{}) error {
132134
if _, err := inject.LoggerInto(baseHookLog.WithValues("webhook", hookPath), webhook); err != nil {
133135
return err
134136
}
137+
baseHookLog.Info("loaded webhook in", "webhook path", hookPath)
135138
}
136139

137140
certPath := filepath.Join(s.CertDir, certName)
@@ -171,13 +174,15 @@ func (s *Server) Start(stop <-chan struct{}) error {
171174
// Error from closing listeners, or context timeout
172175
log.Error(err, "error shutting down the HTTP server")
173176
}
177+
log.Info("shutting down webhook server")
174178
close(idleConnsClosed)
175179
}()
176180

177181
err = srv.Serve(listener)
178182
if err != nil && err != http.ErrServerClosed {
179183
return err
180184
}
185+
log.Info("webhook server is serving at ", "host", s.Host, "port", s.Port)
181186

182187
<-idleConnsClosed
183188
return nil

0 commit comments

Comments
 (0)