From 9a36769be182eb01b42ed1ca922c5bcbf36fc52b Mon Sep 17 00:00:00 2001 From: Abdalaziz Ali Date: Tue, 16 May 2023 05:58:37 +0200 Subject: [PATCH] feat: convert the output error to yaml --- main.go | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/main.go b/main.go index 335dc70..b4ea644 100644 --- a/main.go +++ b/main.go @@ -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" ) // @@ -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