kubeval icon indicating copy to clipboard operation
kubeval copied to clipboard

OutputManager handles error output

Open mbaum0 opened this issue 2 years ago • 0 comments

This pull request corrects output inconsistencies when errors are found before the configuration hits the schema validator. See: #332

If one specifies the output type of json -o json and the config is missing 'apiversion' or 'kind' fields, the error output takes the form of a standard string.

Error handling currently bypasses the OutputManager and dumps errors to stdout as regular strings. This update redirects error output to OutputManager. Kubeval still fails fast when a config is loaded that is missing the necessary fields.

Example of config output with and without changes:

# test.yaml

# apiVersion: apps/v1
kind: Deployment
metadata:
  name: moda-sandbox

Current output:

$ go run main.go -d test.yaml -o json
ERR  - test.yaml: Missing 'apiVersion' key
null

With updates:

[
        {
                "filename": "test.yaml",
                "kind": "",
                "status": "invalid",
                "errors": [
                        "apiVersion: apiVersion key is required"
                ]
        }
]

mbaum0 avatar Mar 01 '22 15:03 mbaum0