mirror of
https://github.com/yannh/kubeconform.git
synced 2026-02-20 10:27:02 +00:00
feat: add origin gojsonschema error
This commit is contained in:
parent
b5f34caa70
commit
a0d26fa4f8
1 changed files with 7 additions and 4 deletions
|
|
@ -28,9 +28,10 @@ const (
|
||||||
|
|
||||||
// Result contains the details of the result of a resource validation
|
// Result contains the details of the result of a resource validation
|
||||||
type Result struct {
|
type Result struct {
|
||||||
Resource resource.Resource
|
Resource resource.Resource
|
||||||
Err error
|
Err error
|
||||||
Status Status
|
Status Status
|
||||||
|
GoJSONSchemaErrs []gojsonschema.ResultError
|
||||||
}
|
}
|
||||||
|
|
||||||
// Validator exposes multiple methods to validate your Kubernetes resources.
|
// Validator exposes multiple methods to validate your Kubernetes resources.
|
||||||
|
|
@ -175,7 +176,9 @@ func (val *v) ValidateResource(res resource.Resource) Result {
|
||||||
}
|
}
|
||||||
|
|
||||||
msg := ""
|
msg := ""
|
||||||
|
gojsonschemaErrs := make([]gojsonschema.ResultError, 0, 2)
|
||||||
for _, errMsg := range results.Errors() {
|
for _, errMsg := range results.Errors() {
|
||||||
|
gojsonschemaErrs = append(gojsonschemaErrs, errMsg)
|
||||||
if msg != "" {
|
if msg != "" {
|
||||||
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())
|
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
|
// ValidateWithContext validates resources found in r
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue