Skip to content

Commit

Permalink
added load chart from FS: wip
Browse files Browse the repository at this point in the history
  • Loading branch information
davidmdm committed Feb 25, 2024
1 parent c5133ef commit 70b3cee
Showing 1 changed file with 47 additions and 0 deletions.
47 changes: 47 additions & 0 deletions pkg/helm/helm.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"archive/tar"
"bytes"
"compress/gzip"
"embed"
"encoding/json"
"fmt"
"io"
Expand Down Expand Up @@ -68,6 +69,52 @@ func LoadChartFromZippedArchive(data []byte) (chart *Chart, err error) {
return &Chart{underlyingChart}, nil
}

func LoadChartFromFS(fs embed.FS) (*Chart, error) {
files, err := getAllFilesFromDir(fs, ".")
if err != nil {
return nil, fmt.Errorf("failed to get files from FS: %w", err)
}

underlyingChart, err := loader.LoadFiles(files)
if err != nil {
return nil, err
}

return &Chart{underlyingChart}, nil
}

func getAllFilesFromDir(fs embed.FS, p string) ([]*loader.BufferedFile, error) {
entries, err := fs.ReadDir(p)
if err != nil {
return nil, fmt.Errorf("failed to read dir at %s: %w", p, err)
}

var results []*loader.BufferedFile
for _, entry := range entries {
filepath := path.Join(p, entry.Name())
if entry.IsDir() {
subEntries, err := getAllFilesFromDir(fs, filepath)
if err != nil {
return nil, err
}
results = append(results, subEntries...)
continue
}

content, err := fs.ReadFile(filepath)
if err != nil {
return nil, fmt.Errorf("failed to read file at %s: %w", filepath, err)
}

results = append(results, &loader.BufferedFile{
Name: path.Join(p, entry.Name()),
Data: content,
})
}

return results, nil
}

type Chart struct {
*chart.Chart
}
Expand Down

0 comments on commit 70b3cee

Please sign in to comment.