Skip to content
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

feat(ui): Recursive Helm Values files detection (#15935) #15936

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 16 additions & 16 deletions reposerver/repository/repository.go
Original file line number Diff line number Diff line change
Expand Up @@ -1997,12 +1997,13 @@ func (s *Service) createGetAppDetailsCacheHandler(res *apiclient.RepoAppDetailsR

func populateHelmAppDetails(res *apiclient.RepoAppDetailsResponse, appPath string, repoRoot string, q *apiclient.RepoServerAppDetailsQuery, gitRepoPaths io.TempPaths) error {
var selectedValueFiles []string
var availableValueFiles []string

if q.Source.Helm != nil {
selectedValueFiles = q.Source.Helm.ValueFiles
}

availableValueFiles, err := findHelmValueFilesInPath(appPath)
err := filepath.Walk(appPath, walkHelmValueFilesInPath(appPath, &availableValueFiles))
if err != nil {
return err
}
Expand Down Expand Up @@ -2079,26 +2080,25 @@ func loadFileIntoIfExists(path pathutil.ResolvedFilePath, destination *string) e
return nil
}

func findHelmValueFilesInPath(path string) ([]string, error) {
var result []string
func walkHelmValueFilesInPath(root string, valueFiles *[]string) filepath.WalkFunc {
return func(path string, info os.FileInfo, err error) error {

files, err := os.ReadDir(path)
if err != nil {
return result, fmt.Errorf("error reading helm values file from %s: %w", path, err)
}

for _, f := range files {
if f.IsDir() {
continue
if err != nil {
return fmt.Errorf("error reading helm values file from %s: %w", path, err)
}
filename := f.Name()
fileNameExt := strings.ToLower(filepath.Ext(filename))

filename := info.Name()
fileNameExt := strings.ToLower(filepath.Ext(path))
if strings.Contains(filename, "values") && (fileNameExt == ".yaml" || fileNameExt == ".yml") {
result = append(result, filename)
relPath, err := filepath.Rel(root, path)
if err != nil {
return fmt.Errorf("error traversing path from %s to %s: %w", root, path, err)
}
*valueFiles = append(*valueFiles, relPath)
}
}

return result, nil
return nil
}
}

func populateKustomizeAppDetails(res *apiclient.RepoAppDetailsResponse, q *apiclient.RepoServerAppDetailsQuery, appPath string, reversion string, credsStore git.CredsStore) error {
Expand Down
21 changes: 16 additions & 5 deletions reposerver/repository/repository_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2663,16 +2663,27 @@ func runGit(t *testing.T, workDir string, args ...string) string {
return stringOut
}

func Test_findHelmValueFilesInPath(t *testing.T) {
func Test_walkHelmValueFilesInPath(t *testing.T) {
bagnaram marked this conversation as resolved.
Show resolved Hide resolved
t.Run("does not exist", func(t *testing.T) {
files, err := findHelmValueFilesInPath("/obviously/does/not/exist")
var files []string
root := "/obviously/does/not/exist"
err := filepath.Walk(root, walkHelmValueFilesInPath(root, &files))
assert.Error(t, err)
assert.Empty(t, files)
})
t.Run("values files", func(t *testing.T) {
files, err := findHelmValueFilesInPath("./testdata/values-files")
var files []string
root := "./testdata/values-files"
err := filepath.Walk(root, walkHelmValueFilesInPath(root, &files))
assert.NoError(t, err)
assert.Len(t, files, 4)
assert.Len(t, files, 5)
})
t.Run("unrelated root", func(t *testing.T) {
var files []string
root := "./testdata/values-files"
unrelated_root := "/different/root/path"
err := filepath.Walk(root, walkHelmValueFilesInPath(unrelated_root, &files))
assert.Error(t, err)
})
}

Expand All @@ -2690,7 +2701,7 @@ func Test_populateHelmAppDetails(t *testing.T) {
err = populateHelmAppDetails(&res, appPath, appPath, &q, emptyTempPaths)
require.NoError(t, err)
assert.Len(t, res.Helm.Parameters, 3)
assert.Len(t, res.Helm.ValueFiles, 4)
assert.Len(t, res.Helm.ValueFiles, 5)
}

func Test_populateHelmAppDetails_values_symlinks(t *testing.T) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
values: yaml
Loading