Skip to content

Commit

Permalink
feat: convert the output error to yaml
Browse files Browse the repository at this point in the history
  • Loading branch information
abdalazizmoh committed May 17, 2023
1 parent 8f9abb8 commit 477feb4
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import (
"sigs.k8s.io/kustomize/kyaml/kio"
"sigs.k8s.io/kustomize/kyaml/resid"
"sigs.k8s.io/kustomize/kyaml/yaml"
yamltojson "sigs.k8s.io/yaml"
)

//
Expand Down Expand Up @@ -96,9 +97,11 @@ func (kcv *KubeconformValidator) Filter(rlItems []*yaml.RNode) ([]*yaml.RNode, e
kc.loadResourceListItems(rlItems)
cfg, out := kc.configure(&kcv.Spec)

// Run Kubeconform validate.
// Run Kubeconform validate
// and convert kc.IO stream to YAML.
if err := kubeconform.Validate(cfg, out); err != nil {
return nil, errors.Wrap(errors.Errorf("Kubeconform validation output: %s", kc.IO))
outYAML, _ := yamltojson.JSONToYAML(kc.IO.(*bytes.Buffer).Bytes())
return nil, errors.WrapPrefixf(err, "Kubeconform validation failed: %s", string(outYAML))
}

return rlItems, nil
Expand Down

0 comments on commit 477feb4

Please sign in to comment.