diff --git a/pkg/admission/server.go b/pkg/admission/server.go index e54807ea22..dea626443a 100644 --- a/pkg/admission/server.go +++ b/pkg/admission/server.go @@ -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", @@ -64,6 +69,7 @@ func ServeHTTP(w http.ResponseWriter, r *http.Request) { if err != nil { log500(w,err) } + return } var ( @@ -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 {