Skip to content
This repository has been archived by the owner on Oct 2, 2024. It is now read-only.

Commit

Permalink
fix: return error when kustomize build fails (#10)
Browse files Browse the repository at this point in the history
needed for the Github action to fail when the config is invalid

Signed-off-by: Xavier Coulon <[email protected]>
  • Loading branch information
xcoulon authored May 6, 2024
1 parent 1bae955 commit c99fab5
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 23 deletions.
5 changes: 3 additions & 2 deletions pkg/validation/components.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package validation

import (
"fmt"
"io/fs"
"path/filepath"

Expand Down Expand Up @@ -30,12 +31,12 @@ func CheckComponents(logger Logger, afs afero.Afero, baseDir string, components
// look for a Kustomization file in the directory
if kp, found := lookupKustomizationFile(logger, afs, path); found {
if err := checkKustomizeResources(logger, afs, kp); err != nil {
logger.Error("invalid resources", "path", path, "err", err)
return fmt.Errorf("invalid resources at %s: %w", path, err)
}
if d.Name() != "base" {
logger.Debug("checking Kustomization build ", "path", path)
if err := checkBuild(logger, fsys, path); err != nil {
logger.Error("invalid resources", "path", path, "err", err)
return fmt.Errorf("invalid resources at %s: %w", path, err)
}
}
}
Expand Down
25 changes: 4 additions & 21 deletions pkg/validation/components_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package validation_test

import (
"fmt"
"os"
"testing"

Expand Down Expand Up @@ -54,16 +53,8 @@ apiVersion: kustomize.config.k8s.io/v1beta1`)
err = validation.CheckComponents(logger, afs, "/path/to", "components")

// then
require.NoError(t, err)
assert.Equal(t, []LogRecord{
{
Msg: "invalid resources",
KeyVals: []any{
"path", "/path/to/components",
"err", fmt.Errorf("kustomization.yaml is empty"),
},
},
}, logger.Errors())
require.Error(t, err, "invalid resources at /path/to/components: kustomization.yaml is empty")
assert.Empty(t, logger.Errors())
assert.Empty(t, logger.Warnings())
})

Expand Down Expand Up @@ -328,16 +319,8 @@ data:
err = validation.CheckComponents(logger, afs, "/path/to", "components")

// then
require.NoError(t, err)
assert.Equal(t, []LogRecord{
{
Msg: "invalid resources",
KeyVals: []any{
"path", "/path/to/components",
"err", fmt.Errorf("kustomization.yaml is empty"),
},
},
}, logger.Errors())
require.Error(t, err, "invalid resources at /path/to/components: kustomization.yaml is empty")
assert.Empty(t, logger.Errors())
assert.Contains(t, logger.Warnings(), LogRecord{
Msg: "resource is not referenced",
KeyVals: []interface{}{
Expand Down

0 comments on commit c99fab5

Please sign in to comment.