Skip to content

Commit

Permalink
admission: only post requests are handled and return correctly
Browse files Browse the repository at this point in the history
Signed-off-by: Christopher M. Luciano <cmluciano@us.ibm.com>
  • Loading branch information
Christopher M. Luciano committed Jan 4, 2021
1 parent c67eaf3 commit 8015c4b
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions pkg/admission/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,11 @@ func log500(w http.ResponseWriter, err error) {
// ServeHTTP parses AdmissionReview requests and responds back
// with the validation result of the entity.
func ServeHTTP(w http.ResponseWriter, r *http.Request) {
if r.Method != http.MethodPost {
w.WriteHeader(http.StatusMethodNotAllowed)
klog.Errorf("webhook cannot handle %s method", r.Method)
http.Error(w, fmt.Sprintf("invalid method %s, only POST requests are allowed", r.Method), http.StatusMethodNotAllowed)
}
if r.Body == nil {
klog.Errorf("received request with empty body")
http.Error(w, "admission review object is missing",
Expand Down Expand Up @@ -64,6 +69,7 @@ func ServeHTTP(w http.ResponseWriter, r *http.Request) {
if err != nil {
log500(w,err)
}
return
}

var (
Expand All @@ -72,11 +78,6 @@ var (
Version: v1alpha1.SchemeGroupVersion.Version,
Resource: "httproutes",
}
gateway = meta.GroupVersionResource{
Group: v1alpha1.SchemeGroupVersion.Group,
Version: v1alpha1.SchemeGroupVersion.Version,
Resource: "gateway",
}
)

func routesEqual(new v1alpha1.HTTPRoute, old v1alpha1.HTTPRoute) bool {
Expand Down

0 comments on commit 8015c4b

Please sign in to comment.