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

Vendor helm chart versions based on chartfile.yaml #420

Merged
Merged
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
34 changes: 30 additions & 4 deletions pkg/helm/charts.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,11 @@ type Charts struct {
Helm Helm
}

// chartManifest represents a Helm chart's Chart.yaml
type chartManifest struct {
Version string `yaml:"version"`
}

// ChartDir returns the directory pulled charts are saved in
func (c Charts) ChartDir() string {
return filepath.Join(c.projectRoot, c.Manifest.Directory)
Expand Down Expand Up @@ -95,12 +100,33 @@ func (c Charts) Vendor() error {
for _, r := range c.Manifest.Requires {
chartName := parseReqName(r.Chart)
chartPath := filepath.Join(dir, chartName)
if _, err := os.Stat(chartPath); err == nil {
log.Printf(" %s@%s exists", r.Chart, r.Version.String())
continue

_, err := os.Stat(chartPath)
if err == nil {
chartManifestPath := filepath.Join(chartPath, "Chart.yaml")
chartManifestBytes, err := ioutil.ReadFile(chartManifestPath)
if err != nil {
return fmt.Errorf("reading chart manifest: %w", err)
}
var chartYAML chartManifest
if err := yaml.Unmarshal(chartManifestBytes, &chartYAML); err != nil {
return fmt.Errorf("unmarshalling chart manifest: %w", err)
}

if chartYAML.Version == r.Version.String() {
log.Printf(" %s@%s exists", r.Chart, r.Version.String())
continue
} else {
log.Printf("Removing %s@%s", r.Chart, r.Version.String())
sh0rez marked this conversation as resolved.
Show resolved Hide resolved
if err := os.RemoveAll(chartPath); err != nil {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

RemoveAll is a bit scary. I'm reasonably happy that this code shouldn't delete anyone's entire project checkout (or home dir) unless they configure their chartfile directory to ".", or "../..", and that directory happens to contain a Chart.yaml. Perhaps it's still worth including a more stringent check? What do you reckon?

return err
}
}
} else if !os.IsNotExist(err) {
return err
}

err := c.Helm.Pull(r.Chart, r.Version.String(), PullOpts{
err = c.Helm.Pull(r.Chart, r.Version.String(), PullOpts{
Destination: dir,
Opts: Opts{Repositories: c.Manifest.Repositories},
})
Expand Down