diff --git a/pkg/openapi/validation.go b/pkg/openapi/validation.go index 701b056c61..e11c33bbcc 100644 --- a/pkg/openapi/validation.go +++ b/pkg/openapi/validation.go @@ -216,23 +216,23 @@ func generateEmptyResource(kindSchema *openapi_v2.Schema) interface{} { case "integer": if kindSchema.GetDefault() != nil { val, _ := strconv.Atoi(string(kindSchema.GetDefault().Value.Value)) - return val + return int64(val) } if kindSchema.GetExample() != nil { val, _ := strconv.Atoi(string(kindSchema.GetExample().GetValue().Value)) - return val + return int64(val) } - return 0 + return int64(0) case "number": if kindSchema.GetDefault() != nil { val, _ := strconv.Atoi(string(kindSchema.GetDefault().Value.Value)) - return val + return int64(val) } if kindSchema.GetExample() != nil { val, _ := strconv.Atoi(string(kindSchema.GetExample().GetValue().Value)) - return val + return int64(val) } - return 0 + return int64(0) case "boolean": if kindSchema.GetDefault() != nil { return string(kindSchema.GetDefault().Value.Value) == "true" diff --git a/pkg/openapi/validation_test.go b/pkg/openapi/validation_test.go index 4c6c8ac2a6..6723c13b0c 100644 --- a/pkg/openapi/validation_test.go +++ b/pkg/openapi/validation_test.go @@ -8,10 +8,6 @@ import ( ) func Test_ValidateMutationPolicy(t *testing.T) { - err := setValidationGlobalState() - if err != nil { - t.Fatalf("Could not set global state") - } tcs := []struct { description string diff --git a/pkg/webhooks/mutation.go b/pkg/webhooks/mutation.go index 650fce8374..d6df3fcb34 100644 --- a/pkg/webhooks/mutation.go +++ b/pkg/webhooks/mutation.go @@ -3,6 +3,8 @@ package webhooks import ( "time" + "github.com/nirmata/kyverno/pkg/openapi" + "github.com/golang/glog" kyverno "github.com/nirmata/kyverno/pkg/api/kyverno/v1" "github.com/nirmata/kyverno/pkg/engine" @@ -101,6 +103,11 @@ func (ws *WebhookServer) HandleMutation(request *v1beta1.AdmissionRequest, resou glog.V(4).Infof("Failed to apply policy %s on resource %s/%s\n", policy.Name, resource.GetNamespace(), resource.GetName()) continue } + err := openapi.ValidateResource(engineResponse.PatchedResource.UnstructuredContent(), engineResponse.PatchedResource.GetKind()) + if err != nil { + glog.V(4).Infoln(err) + continue + } // gather patches patches = append(patches, engineResponse.GetPatches()...) glog.V(4).Infof("Mutation from policy %s has applied successfully to %s %s/%s", policy.Name, request.Kind.Kind, resource.GetNamespace(), resource.GetName())