PR feedback

This commit is contained in:
Dave Protasowski 2025-07-07 11:36:34 -04:00
parent 0a03e55731
commit 8daeb7fd29
2 changed files with 13 additions and 9 deletions

View File

@ -101,15 +101,17 @@ func admissionHandler(wh *Webhook, c AdmissionController, synced <-chan struct{}
labeler, _ := otelhttp.LabelerFromContext(r.Context())
defer func() {
// otelhttp doesn't add labeler attributes to spans
// so we have to do it manually
span.SetAttributes(labeler.Get()...)
}()
var review admissionv1.AdmissionReview
bodyBuffer := bytes.Buffer{}
if err := json.NewDecoder(io.TeeReader(r.Body, &bodyBuffer)).Decode(&review); err != nil {
err := fmt.Sprint("could not decode body:", err)
span.SetStatus(codes.Error, err)
http.Error(w, err, http.StatusBadRequest)
msg := fmt.Sprint("could not decode body:", err)
span.SetStatus(codes.Error, msg)
http.Error(w, msg, http.StatusBadRequest)
return
}
r.Body = io.NopCloser(&bodyBuffer)

View File

@ -56,22 +56,24 @@ func conversionHandler(wh *Webhook, c ConversionController) http.HandlerFunc {
labeler, _ := otelhttp.LabelerFromContext(r.Context())
defer func() {
// otelhttp doesn't add labeler attributes to spans
// so we have to do it manually
span.SetAttributes(labeler.Get()...)
}()
var review apixv1.ConversionReview
if err := json.NewDecoder(r.Body).Decode(&review); err != nil {
err := fmt.Sprint("could not decode body:", err)
span.SetStatus(codes.Error, err)
http.Error(w, err, http.StatusBadRequest)
msg := fmt.Sprint("could not decode body:", err)
span.SetStatus(codes.Error, msg)
http.Error(w, msg, http.StatusBadRequest)
return
}
gv, err := parseAPIVersion(review.Request.DesiredAPIVersion)
if err != nil {
err := fmt.Sprint("could parse desired api version:", err)
span.SetStatus(codes.Error, err)
http.Error(w, err, http.StatusBadRequest)
msg := fmt.Sprint("could parse desired api version:", err)
span.SetStatus(codes.Error, msg)
http.Error(w, msg, http.StatusBadRequest)
return
}