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

Commit

Permalink
fix(cmd): fail when resource file is not referenced (#15)
Browse files Browse the repository at this point in the history
a warning message is not enough, the GH action would succeed and we would miss the problem

Signed-off-by: Xavier Coulon <[email protected]>
  • Loading branch information
xcoulon authored May 30, 2024
1 parent 8cda939 commit abf5d69
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 14 deletions.
29 changes: 16 additions & 13 deletions pkg/validation/components_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -304,13 +304,24 @@ setRoleBindingSubjects: defaultOnly
err := afs.Mkdir("/path/to/components", os.ModeDir)
require.NoError(t, err)
err = addFile(afs, "/path/to/components/kustomization.yaml", `kind: Kustomization
apiVersion: kustomize.config.k8s.io/v1beta1`)
apiVersion: kustomize.config.k8s.io/v1beta1
resources:
- configmap1.yaml`)
require.NoError(t, err)
err = addFile(afs, "/path/to/components/configmap.yaml", `apiVersion: v1
err = addFile(afs, "/path/to/components/configmap1.yaml", `apiVersion: v1
kind: ConfigMap
metadata:
namespace: test
name: secret
name: config1
data:
cookie: yummy`)
require.NoError(t, err)
err = addFile(afs, "/path/to/components/configmap2.yaml", `apiVersion: v1
kind: ConfigMap
metadata:
namespace: test
name: config2
data:
cookie: yummy`)
require.NoError(t, err)
Expand All @@ -319,17 +330,9 @@ data:
err = validation.CheckComponents(logger, afs, "/path/to", "components")

// then
require.Error(t, err, "invalid resources at /path/to/components: kustomization.yaml is empty")
require.Error(t, err, "resource is not referenced: /path/to/components/configmap2.yaml")
assert.Empty(t, logger.Errors())
assert.Contains(t, logger.Warnings(), LogRecord{
Msg: "resource is not referenced",
KeyVals: []interface{}{
"path",
"/path/to/components/kustomization.yaml",
"resource",
"configmap.yaml",
},
})
assert.Empty(t, logger.Warnings())
})
})
}
3 changes: 2 additions & 1 deletion pkg/validation/resources.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package validation

import (
"fmt"
"path/filepath"
"strings"

Expand Down Expand Up @@ -85,7 +86,7 @@ entries:
continue entries
}
}
logger.Warn("resource is not referenced", "path", path, "resource", e.Name())
return fmt.Errorf("resource is not referenced: %s", filepath.Join(path, e.Name()))
}
return nil
}

0 comments on commit abf5d69

Please sign in to comment.