-
Notifications
You must be signed in to change notification settings - Fork 36
feat: improve kustomization walk for helmCharts section #367
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Temporary image deleted. |
Mergecat's ReviewClick to read mergecats review!😼 Mergecat review of pkg/kustomize/process.go@@ -44,7 +44,7 @@ func processDir(sourceFS fs.FS, relBase string) (files []string, dirs []string,
var filesOrDirectories []string
filesOrDirectories = append(filesOrDirectories, kust.Bases...) // nolint:staticcheck // deprecated doesn't mean unused
filesOrDirectories = append(filesOrDirectories, kust.Resources...)
-
+ filesOrDirectories = append(filesOrDirectories, getValuesFromKustomizationHelm(&kust)...)
var directories []string
directories = append(directories, kust.Components...)
@@ -154,3 +154,11 @@ func isRemoteResource(resource string) bool {
return false
}
+
+// getValuesFromKustomizationHelm will parse the helmCharts sections' valueFile field and return them as a slice of strings.
+func getValuesFromKustomizationHelm(kust *types.Kustomization) (files []string) {
+ for _, helm := range kust.HelmCharts {
+ files = append(files, helm.ValuesFile)
+ }
+ return files
+} Feedback & Suggestions:
😼 Mergecat review of pkg/kustomize/process_test.go@@ -12,6 +12,7 @@ import (
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
+ "sigs.k8s.io/kustomize/api/types"
_ "sigs.k8s.io/kustomize/api/types"
)
@@ -203,4 +204,70 @@ resources:
assert.Error(t, err)
assert.Contains(t, err.Error(), "failed to stat testdir/missing-resource.yaml")
})
+ t.Run("helmChart", func(t *testing.T) {
+ kustContent := `
+helmCharts:
+ - name: dummy
+ repo: https://dummy.local/repo
+ version: 1.2.3
+ releaseName: dummy
+ namespace: dummy
+ includeCRDs: true
+ valuesFile: values-dummy.yaml
+`
+ valueContent := `
+dummy:
+ labels:
+ release: dummy
+`
+ sourceFS := fstest.MapFS{
+ "testdir/kustomization.yaml": &fstest.MapFile{
+ Data: []byte(kustContent),
+ },
+ "testdir/values-dummy.yaml": &fstest.MapFile{
+ Data: []byte(valueContent),
+ },
+ }
+
+ files, _, err := processDir(sourceFS, "testdir")
+ assert.NoError(t, err)
+ assert.Contains(t, files, "testdir/values-dummy.yaml")
+ })
+}
+
+func Test_getValuesFromKustomizationHelm(t *testing.T) {
+ type args struct {
+ kust *types.Kustomization
+ }
+ tests := []struct {
+ name string
+ args args
+ wantFiles []string
+ }{
+ {
+ name: "normal",
+ args: args{
+ kust: &types.Kustomization{
+ HelmCharts: []types.HelmChart{
+ {Name: "dummy", ValuesFile: "values-dummy.yaml"},
+ },
+ },
+ },
+ wantFiles: []string{"values-dummy.yaml"},
+ },
+ {
+ name: "helmChart is nil.",
+ args: args{
+ kust: &types.Kustomization{
+ HelmCharts: nil,
+ },
+ },
+ wantFiles: nil,
+ },
+ }
+ for _, tt := range tests {
+ t.Run(tt.name, func(t *testing.T) {
+ assert.Equalf(t, tt.wantFiles, getValuesFromKustomizationHelm(tt.args.kust), "getValuesFromKustomizationHelm(%v)", tt.args.kust)
+ })
+ }
} Feedback & Suggestions:
Dependency ReviewClick to read mergecats review!No suggestions found |
current kustomization.yaml walk does not parse the helmCharts section.
This PR is to add ability to add these values file per chart and send to the argo-cd-repo server.