Skip to content

Commit

Permalink
Fix panic in conversion webhook
Browse files Browse the repository at this point in the history
  • Loading branch information
Tomy2e committed Aug 8, 2022
1 parent bcde6f0 commit 7d2e5fe
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions pkg/webhook/conversion/conversion.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/runtime/schema"
"k8s.io/apimachinery/pkg/types"
"sigs.k8s.io/controller-runtime/pkg/conversion"
logf "sigs.k8s.io/controller-runtime/pkg/log"
)
Expand Down Expand Up @@ -69,16 +70,21 @@ func (wh *Webhook) ServeHTTP(w http.ResponseWriter, r *http.Request) {
return
}

var uid types.UID
if convertReview.Request != nil {
uid = convertReview.Request.UID
}

// TODO(droot): may be move the conversion logic to a separate module to
// decouple it from the http layer ?
resp, err := wh.handleConvertRequest(convertReview.Request)
if err != nil {
log.Error(err, "failed to convert", "request", convertReview.Request.UID)
log.Error(err, "failed to convert", "request", uid)
convertReview.Response = errored(err)
} else {
convertReview.Response = resp
}
convertReview.Response.UID = convertReview.Request.UID
convertReview.Response.UID = uid
convertReview.Request = nil

err = json.NewEncoder(w).Encode(convertReview)
Expand Down

0 comments on commit 7d2e5fe

Please sign in to comment.