diff --git a/src/internal/packager/helm/repo.go b/src/internal/packager/helm/repo.go index 5816d7e5cb..351f070f7b 100644 --- a/src/internal/packager/helm/repo.go +++ b/src/internal/packager/helm/repo.go @@ -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" @@ -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) { + // 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) + +} diff --git a/src/pkg/packager/create.go b/src/pkg/packager/create.go index fb31a11590..22f5f3d238 100755 --- a/src/pkg/packager/create.go +++ b/src/pkg/packager/create.go @@ -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@`) + // check if the chart is a git url with a ref isGitURL := re.MatchString(chart.URL) helmCfg := helm.Helm{ Chart: chart, @@ -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()) } diff --git a/src/pkg/packager/prepare.go b/src/pkg/packager/prepare.go index d6e9926f49..c16f92e2cb 100644 --- a/src/pkg/packager/prepare.go +++ b/src/pkg/packager/prepare.go @@ -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, @@ -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) }