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

[TASK] TransformGitURL helm helper #1886

Closed
wants to merge 1 commit into from
Closed
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
16 changes: 16 additions & 0 deletions src/internal/packager/helm/repo.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"github.com/defenseunicorns/zarf/src/config"
"github.com/defenseunicorns/zarf/src/internal/packager/git"
"github.com/defenseunicorns/zarf/src/pkg/message"
"github.com/defenseunicorns/zarf/src/pkg/transform"
"helm.sh/helm/v3/pkg/action"
"helm.sh/helm/v3/pkg/cli"
"helm.sh/helm/v3/pkg/registry"
Expand Down Expand Up @@ -165,3 +166,18 @@ func (h *Helm) DownloadChartFromGitToTemp(spinner *message.Spinner) (string, err

return gitCfg.GitPath, nil
}

// Helper function src/pkg/packager/prepare.goL118 src/pkg/packager/create.goL328
func (h *Helm) TransformGitURL(charts string) (string, error) {
cmwylie19 marked this conversation as resolved.
Show resolved Hide resolved
// calling GitTransformURLSplitRef() to see if refPlain is empty
_, refPlain, _ := transform.GitTransformURLSplitRef(h.Chart.URL)

// if it is append chart version as if its a tag
if refPlain == "" {
h.Chart.URL = fmt.Sprintf("%s@%s", h.Chart.URL, h.Chart.Version)
}

// reduce code duplication
return h.PackageChartFromGit(charts)

}
7 changes: 5 additions & 2 deletions src/pkg/packager/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 +326,9 @@ func (p *Packager) addComponent(index int, component types.ZarfComponent, isSkel

// If any helm charts are defined, process them.
for chartIdx, chart := range component.Charts {
re := regexp.MustCompile(`\.git$`)
// https://regex101.com/r/jYLoUy/1
re := regexp.MustCompile(`\.git@`)
cmwylie19 marked this conversation as resolved.
Show resolved Hide resolved
// check if the chart is a git url with a ref
isGitURL := re.MatchString(chart.URL)
helmCfg := helm.Helm{
Chart: chart,
Expand All @@ -344,7 +346,8 @@ func (p *Packager) addComponent(index int, component types.ZarfComponent, isSkel

p.cfg.Pkg.Components[index].Charts[chartIdx].LocalPath = rel
} else if isGitURL {
_, err = helmCfg.PackageChartFromGit(componentPath.Charts)
_, err = helmCfg.TransformGitURL(componentPath.Charts)
// _, err = helmCfg.PackageChartFromGit(componentPath.Charts)
if err != nil {
return fmt.Errorf("error creating chart archive, unable to pull the chart from git: %s", err.Error())
}
Expand Down
7 changes: 5 additions & 2 deletions src/pkg/packager/prepare.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,9 +113,11 @@ func (p *Packager) FindImages(baseDir, repoHelmChartPath string, kubeVersionOver
if len(component.Charts) > 0 {
_ = utils.CreateDirectory(componentPath.Charts, 0700)
_ = utils.CreateDirectory(componentPath.Values, 0700)
re := regexp.MustCompile(`\.git$`)
// https://regex101.com/r/jYLoUy/1
re := regexp.MustCompile(`\.git@`)

for _, chart := range component.Charts {
// check if the chart is a git url with a ref
isGitURL := re.MatchString(chart.URL)
helmCfg := helm.Helm{
Chart: chart,
Expand All @@ -124,7 +126,8 @@ func (p *Packager) FindImages(baseDir, repoHelmChartPath string, kubeVersionOver

helmCfg.Cfg.State = types.ZarfState{}
if isGitURL {
path, err := helmCfg.PackageChartFromGit(componentPath.Charts)
path, err := helmCfg.TransformGitURL(componentPath.Charts)
// path, err := helmCfg.PackageChartFromGit(componentPath.Charts)
if err != nil {
return fmt.Errorf("unable to download chart from git repo (%s): %w", chart.URL, err)
}
Expand Down