1
0
Fork 0
mirror of https://github.com/kyverno/kyverno.git synced 2025-03-07 00:17:13 +00:00
kyverno/pkg/webhooks/policyvalidation.go

30 lines
889 B
Go
Raw Normal View History

2019-07-15 16:07:56 -07:00
package webhooks
import (
2020-01-25 14:53:12 +05:30
policyvalidate "github.com/nirmata/kyverno/pkg/policy"
2020-03-06 03:00:18 +05:30
2019-07-15 16:07:56 -07:00
v1beta1 "k8s.io/api/admission/v1beta1"
2019-07-15 16:07:56 -07:00
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)
//HandlePolicyValidation performs the validation check on policy resource
2020-04-10 23:24:54 +05:30
func (ws *WebhookServer) policyValidation(request *v1beta1.AdmissionRequest) *v1beta1.AdmissionResponse {
//TODO: can this happen? wont this be picked by OpenAPI spec schema ?
2020-03-29 09:09:26 +05:30
if err := policyvalidate.Validate(request.Object.Raw, ws.client, false, ws.openAPIController); err != nil {
return &v1beta1.AdmissionResponse{
Allowed: false,
Result: &metav1.Status{
Message: err.Error(),
},
}
}
// if the policy contains mutating & validation rules and it config does not exist we create one
// queue the request
ws.resourceWebhookWatcher.RegisterResourceWebhook()
return &v1beta1.AdmissionResponse{
Allowed: true,
2019-09-04 13:43:12 -07:00
}
2019-07-15 16:07:56 -07:00
}