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 16, 2023
1 parent 8f9abb8 commit 9a36769
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion 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 @@ -97,8 +98,12 @@ func (kcv *KubeconformValidator) Filter(rlItems []*yaml.RNode) ([]*yaml.RNode, e
cfg, out := kc.configure(&kcv.Spec)

// Run Kubeconform validate.
// and convert kc.IO stream to YAML.
// kc.IO stream is a JSON stream.
// kc.IO does not have method Bytes() so we need to convert it 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 9a36769

Please sign in to comment.