Skip to content

Commit aa7d500

Browse files
committed
Remove glog from admission internals/fix return
This returns glog from the admission internals. It also fixes a case where we fail to marshal a response, and then try and write that empty marshalled response anyway.
1 parent cb23743 commit aa7d500

File tree

1 file changed

+11
-5
lines changed

1 file changed

+11
-5
lines changed

pkg/internal/admission/http.go

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,14 @@ import (
2121
"io/ioutil"
2222
"net/http"
2323

24-
"github.com/golang/glog"
2524
"k8s.io/api/admission/v1beta1"
2625
"k8s.io/apimachinery/pkg/runtime"
26+
logf "sigs.k8s.io/controller-runtime/pkg/runtime/log"
27+
)
28+
29+
var (
30+
// TODO(directxman12): this shouldn't be a global log
31+
log = logf.KBLog.WithName("admission").WithName("http-handler")
2732
)
2833

2934
func (h httpHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
@@ -37,15 +42,15 @@ func (h httpHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
3742
// verify the content type is accurate
3843
contentType := r.Header.Get("Content-Type")
3944
if contentType != "application/json" {
40-
glog.Errorf("contentType=%s, expect application/json", contentType)
45+
log.Error(nil, "invalid content type, expected application/json", "context type", contentType)
4146
return
4247
}
4348

4449
var reviewResponse *v1beta1.AdmissionResponse
4550
ar := v1beta1.AdmissionReview{}
4651
deserializer := codecs.UniversalDeserializer()
4752
if _, _, err := deserializer.Decode(body, nil, &ar); err != nil {
48-
glog.Error(err)
53+
log.Error(err, "unable to decode request body")
4954
reviewResponse = ErrorResponse(err)
5055
} else {
5156
reviewResponse = h.admit(ar)
@@ -62,10 +67,11 @@ func (h httpHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
6267

6368
resp, err := json.Marshal(response)
6469
if err != nil {
65-
glog.Error(err)
70+
log.Error(err, "unable to marshal response")
71+
return
6672
}
6773
if _, err := w.Write(resp); err != nil {
68-
glog.Error(err)
74+
log.Error(err, "unable to write response")
6975
}
7076
}
7177

0 commit comments

Comments
 (0)