diff --git a/documentation/testing-policies.md b/documentation/testing-policies.md index 15a91d9219..e97ee2ea64 100644 --- a/documentation/testing-policies.md +++ b/documentation/testing-policies.md @@ -12,14 +12,14 @@ To do this you should [install Kyverno to the cluster](installation.md). For example, to test the simplest Kyverno policy for `ConfigMap`, create the policy and then the resource itself via `kubectl`: ````bash -cd test/ConfigMap -kubectl create -f policy-CM.yaml -kubectl create -f CM.yaml +cd test +kubectl create -f policy/policy-CM.yaml +kubectl create -f resources/CM.yaml ```` Then compare the original resource definition in `CM.yaml` with the actual one: ````bash -kubectl get -f CM.yaml -o yaml +kubectl get -f resources/CM.yaml -o yaml ```` ## Test using Kyverno CLI diff --git a/go.mod b/go.mod index f5ba937e12..f8dcbdf549 100644 --- a/go.mod +++ b/go.mod @@ -12,6 +12,7 @@ require ( github.com/imdario/mergo v0.3.8 // indirect github.com/jmespath/go-jmespath v0.0.0-20180206201540-c2b33e8439af github.com/json-iterator/go v1.1.9 // indirect + github.com/julienschmidt/httprouter v1.3.0 github.com/minio/minio v0.0.0-20200114012931-30922148fbb5 github.com/spf13/cobra v0.0.5 github.com/tevino/abool v0.0.0-20170917061928-9b9efcf221b5 diff --git a/go.sum b/go.sum index 99c5af7f3b..a8e3e37eb8 100644 --- a/go.sum +++ b/go.sum @@ -516,6 +516,8 @@ github.com/jstemmer/go-junit-report v0.0.0-20190106144839-af01ea7f8024/go.mod h1 github.com/jtolds/gls v4.2.1+incompatible/go.mod h1:QJZ7F/aHp+rZTRtaJ1ow/lLfFfVYBRgL+9YlvaHOwJU= github.com/jtolds/gls v4.20.0+incompatible/go.mod h1:QJZ7F/aHp+rZTRtaJ1ow/lLfFfVYBRgL+9YlvaHOwJU= github.com/julienschmidt/httprouter v1.2.0/go.mod h1:SYymIcj16QtmaHHD7aYtjjsJG7VTCxuUUipMqKk8s4w= +github.com/julienschmidt/httprouter v1.3.0 h1:U0609e9tgbseu3rBINet9P48AI/D3oJs4dN7jwJOQ1U= +github.com/julienschmidt/httprouter v1.3.0/go.mod h1:JR6WtHb+2LUe8TCKY3cZOxFyyO8IZAc4RVcycCCAKdM= github.com/karrick/godirwalk v1.7.5/go.mod h1:2c9FRhkDxdIbgkOnCEvnSWs71Bhugbl46shStcFDJ34= github.com/karrick/godirwalk v1.7.7/go.mod h1:2c9FRhkDxdIbgkOnCEvnSWs71Bhugbl46shStcFDJ34= github.com/karrick/godirwalk v1.7.8/go.mod h1:2c9FRhkDxdIbgkOnCEvnSWs71Bhugbl46shStcFDJ34= diff --git a/pkg/webhooks/server.go b/pkg/webhooks/server.go index 839677d5be..6935322d56 100644 --- a/pkg/webhooks/server.go +++ b/pkg/webhooks/server.go @@ -10,6 +10,8 @@ import ( "net/http" "time" + "github.com/julienschmidt/httprouter" + v1 "github.com/nirmata/kyverno/pkg/api/kyverno/v1" context2 "github.com/nirmata/kyverno/pkg/engine/context" @@ -133,12 +135,12 @@ func NewWebhookServer( log: log, openAPIController: openAPIController, } - mux := http.NewServeMux() - mux.HandleFunc(config.MutatingWebhookServicePath, ws.handlerFunc(ws.resourceMutation, true)) - mux.HandleFunc(config.ValidatingWebhookServicePath, ws.handlerFunc(ws.resourceValidation, true)) - mux.HandleFunc(config.PolicyMutatingWebhookServicePath, ws.handlerFunc(ws.policyMutation, true)) - mux.HandleFunc(config.PolicyValidatingWebhookServicePath, ws.handlerFunc(ws.policyValidation, true)) - mux.HandleFunc(config.VerifyMutatingWebhookServicePath, ws.handlerFunc(ws.verifyHandler, false)) + mux := httprouter.New() + mux.HandlerFunc("POST", config.MutatingWebhookServicePath, ws.handlerFunc(ws.resourceMutation, true)) + mux.HandlerFunc("POST", config.ValidatingWebhookServicePath, ws.handlerFunc(ws.resourceValidation, true)) + mux.HandlerFunc("POST", config.PolicyMutatingWebhookServicePath, ws.handlerFunc(ws.policyMutation, true)) + mux.HandlerFunc("POST", config.PolicyValidatingWebhookServicePath, ws.handlerFunc(ws.policyValidation, true)) + mux.HandlerFunc("POST", config.VerifyMutatingWebhookServicePath, ws.handlerFunc(ws.verifyHandler, false)) ws.server = http.Server{ Addr: ":443", // Listen on port for HTTPS requests TLSConfig: &tlsConfig,