Skip to content

Commit

Permalink
Validate Helm chart before creating release (#331)
Browse files Browse the repository at this point in the history
  • Loading branch information
divolgin authored Oct 4, 2023
1 parent f29a293 commit eb78b27
Showing 1 changed file with 13 additions and 5 deletions.
18 changes: 13 additions & 5 deletions cli/cmd/release_create.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (
"github.com/replicatedhq/replicated/pkg/logger"
"github.com/replicatedhq/replicated/pkg/types"
"github.com/spf13/cobra"
"helm.sh/helm/v3/pkg/chart/loader"
)

const (
Expand Down Expand Up @@ -393,7 +394,7 @@ func encodeKotsFile(prefix, path string, info os.FileInfo, err error) (*kotstype
return nil, nil
}

bytes, err := ioutil.ReadFile(path)
bytes, err := os.ReadFile(path)
if err != nil {
return nil, errors.Wrapf(err, "read file %s", path)
}
Expand Down Expand Up @@ -447,13 +448,20 @@ func makeReleaseFromDir(fileDir string) (string, error) {
}

func makeReleaseFromChart(chartFile string) (string, error) {
fileInfo, err := os.Stat(chartFile)
file, err := os.Open(chartFile)
if err != nil {
return "", errors.Wrapf(err, "stat %s", chartFile)
return "", errors.Wrapf(err, "open file")
}
defer file.Close()

if fileInfo.IsDir() {
return "", errors.Errorf("chart path %s is a directory", chartFile)
// Validate chart by loading it
if _, err := loader.LoadArchive(file); err != nil {
return "", errors.Wrapf(err, "load file")
}

fileInfo, err := file.Stat()
if err != nil {
return "", errors.Wrapf(err, "stat file")
}

dirName, _ := filepath.Split(chartFile)
Expand Down

0 comments on commit eb78b27

Please sign in to comment.