Skip to content

Commit

Permalink
fix: correctly handle kubeconform not being executed
Browse files Browse the repository at this point in the history
  • Loading branch information
shivjm committed Feb 14, 2024
1 parent c8c211b commit 52c4151
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package main

import (
"bytes"
"encoding/json"
"errors"
"io/fs"
"os"
Expand Down Expand Up @@ -128,7 +129,16 @@ func run(cfg Config, additionalSchemaPaths []string, updateDependencies bool) er
// <https://github.com/yannh/kubeconform/blob/dcc77ac3a39ed1fb538b54fab57bbe87d1ece490/cmd/kubeconform/main.go#L47>,
// so instead we shell out to it
output, err := runKubeconform(manifests, cfg.Kubeconform.path, cfg.Strict, additionalSchemaPaths, cfg.KubernetesVersion)
logger.Err(err).RawJSON("kubeconform", output).Msg("")

// if kubeconform could not be executed, the output will not be
// in JSON format
var js json.RawMessage
if json.Unmarshal([]byte(output), &js) == nil {
logger.Err(err).RawJSON("kubeconform", output).Msg("")
} else {
logger.Err(err).Msgf("kubeconform failed: %s", output)
}

if err != nil {
validationsErrors = append(validationsErrors, err)
}
Expand All @@ -143,6 +153,7 @@ func run(cfg Config, additionalSchemaPaths []string, updateDependencies bool) er
if validationsErrors != nil {
return errors.New("Validation failed")
}

return nil
}

Expand Down

0 comments on commit 52c4151

Please sign in to comment.