Skip to content

Commit

Permalink
🐛 set status in conversion response
Browse files Browse the repository at this point in the history
We need to set "success" status in conversion response when we successfully convert the object.
kube-apiserver rejects it if the status is not set.
  • Loading branch information
Mengqi Yu committed May 24, 2019
1 parent 96b67f2 commit 272bacc
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
6 changes: 5 additions & 1 deletion pkg/webhook/conversion/conversion.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,10 +75,11 @@ func (wh *Webhook) ServeHTTP(w http.ResponseWriter, r *http.Request) {
if err != nil {
log.Error(err, "failed to convert", "request", convertReview.Request.UID)
convertReview.Response = errored(err)
convertReview.Response.UID = convertReview.Request.UID
} else {
convertReview.Response = resp
}
convertReview.Response.UID = convertReview.Request.UID
convertReview.Request = nil

err = json.NewEncoder(w).Encode(convertReview)
if err != nil {
Expand Down Expand Up @@ -112,6 +113,9 @@ func (wh *Webhook) handleConvertRequest(req *apix.ConversionRequest) (*apix.Conv
return &apix.ConversionResponse{
UID: req.UID,
ConvertedObjects: objects,
Result: metav1.Status{
Status: metav1.StatusSuccess,
},
}, nil
}

Expand Down
1 change: 1 addition & 0 deletions pkg/webhook/conversion/conversion_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ var _ = Describe("Conversion Webhook", func() {
convReview := doRequest(convReq)

Expect(convReview.Response.ConvertedObjects).To(HaveLen(1))
Expect(convReview.Response.Result.Status).To(BeIdenticalTo(metav1.StatusSuccess))
got, _, err := decoder.Decode(convReview.Response.ConvertedObjects[0].Raw)
Expect(err).NotTo(HaveOccurred())
Expect(got).To(Equal(expected))
Expand Down

0 comments on commit 272bacc

Please sign in to comment.