From a0d26fa4f8bd29c2a139e76e973bba0c9439253c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=B8=81=E6=96=87=E6=B1=9F?= Date: Tue, 26 Apr 2022 00:04:34 +0800 Subject: [PATCH] feat: add origin gojsonschema error --- pkg/validator/validator.go | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/pkg/validator/validator.go b/pkg/validator/validator.go index ffa224d..185f25d 100644 --- a/pkg/validator/validator.go +++ b/pkg/validator/validator.go @@ -28,9 +28,10 @@ const ( // Result contains the details of the result of a resource validation type Result struct { - Resource resource.Resource - Err error - Status Status + Resource resource.Resource + Err error + Status Status + GoJSONSchemaErrs []gojsonschema.ResultError } // Validator exposes multiple methods to validate your Kubernetes resources. @@ -175,7 +176,9 @@ func (val *v) ValidateResource(res resource.Resource) Result { } msg := "" + gojsonschemaErrs := make([]gojsonschema.ResultError, 0, 2) for _, errMsg := range results.Errors() { + gojsonschemaErrs = append(gojsonschemaErrs, errMsg) if msg != "" { msg += " - " } @@ -183,7 +186,7 @@ func (val *v) ValidateResource(res resource.Resource) Result { msg += fmt.Sprintf("For field %s: %s", details["field"].(string), errMsg.Description()) } - return Result{Resource: res, Status: Invalid, Err: fmt.Errorf("%s", msg)} + return Result{Resource: res, Status: Invalid, Err: fmt.Errorf("%s", msg), GoJSONSchemaErrs: gojsonschemaErrs} } // ValidateWithContext validates resources found in r