Skip to content

fix(helm): Check prior vendoring of helm charts #402

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

Merged
merged 1 commit into from
Oct 24, 2020
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
16 changes: 15 additions & 1 deletion pkg/helm/charts.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,13 @@ func (c Charts) Vendor() error {

log.Println("Pulling Charts ...")
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 := c.Helm.Pull(r.Chart, r.Version.String(), PullOpts{
Destination: dir,
Opts: Opts{Repositories: c.Manifest.Repositories},
Expand All @@ -101,7 +108,7 @@ func (c Charts) Vendor() error {
return err
}

log.Printf(" %s@%s", r.Chart, r.Version.String())
log.Printf(" %s@%s downloaded", r.Chart, r.Version.String())
}

return nil
Expand Down Expand Up @@ -199,3 +206,10 @@ func parseReq(s string) (*Requirement, error) {
Version: *ver,
}, nil
}

// parseReqName parses a name from a string of the format `repo/name`
func parseReqName(s string) string {
Copy link
Member

Choose a reason for hiding this comment

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

It seems like parseReqName is only ever called with an argument of the form name@repo as r.Chart looks like this.

Any reason this function also handles plain name?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm just being defensive in the case a chart name didn't have a repo/ prefix, I'm not sure how the helm community does it across the board.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@sh0rez Does that make sense? I'm happy to simplify it if that case won't happen. Just let me know.

Copy link
Member

Choose a reason for hiding this comment

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

The use of repo/name promotes making a clear distinction which Chart one refers to, I would be in favor of enforcing this.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Gotcha. I removed the check.

Copy link
Member

Choose a reason for hiding this comment

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

Thanks @justinwalz!

elems := strings.Split(s, "/")
name := elems[1]
return name
}