Skip to content

Commit

Permalink
Merge pull request #45 from defenseunicorns/hotfix/helm-chart-naming-…
Browse files Browse the repository at this point in the history
…inconsistencies-breaks-some-charts

Fixes #41, ensure standard naming for downloaded helm charts
  • Loading branch information
jeff-mccoy committed Sep 16, 2021
2 parents a74caba + b9363c8 commit 6effd13
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 9 deletions.
47 changes: 40 additions & 7 deletions cli/internal/helm/charts.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,12 @@ import (
"helm.sh/helm/v3/pkg/cli"
"repo1.dso.mil/platform-one/big-bang/apps/product-tools/zarf/cli/config"
"repo1.dso.mil/platform-one/big-bang/apps/product-tools/zarf/cli/internal/git"

"strings"

"helm.sh/helm/v3/pkg/downloader"
"helm.sh/helm/v3/pkg/getter"
"helm.sh/helm/v3/pkg/repo"
)

func DownloadChartFromGit(chart config.ZarfChart, destination string) {
Expand Down Expand Up @@ -41,13 +47,40 @@ func DownloadPublishedChart(chart config.ZarfChart, destination string) {
})

logContext.Info("Processing published helm chart")
client := action.NewPull()
client.Settings = cli.New()
client.DestDir = destination
client.Version = chart.Version
client.RepoURL = chart.Url
_, err := client.Run(chart.Name)

var out strings.Builder

// Setup the helm pull config
pull := action.NewPull()
pull.Settings = cli.New()

// Setup the chart downloader
downloader := downloader.ChartDownloader{
Out: &out,
Verify: downloader.VerifyNever,
Getters: getter.All(pull.Settings),
}

// @todo: process OCI-based charts

// Perform simple chart download
chartURL, err := repo.FindChartInRepoURL(chart.Url, chart.Name, chart.Version, pull.CertFile, pull.KeyFile, pull.CaFile, getter.All(pull.Settings))
if err != nil {
logContext.Fatal("Unable to pull the helm chart")
}

// Download the file (we don't control what name helm creates here)
saved, _, err := downloader.DownloadTo(chartURL, pull.Version, destination)
if err != nil {
logContext.Fatal("Unable to load the helm chart")
logContext.Fatal("Unable to download the helm chart")
}

// Ensure the name is consistent for deployments
destinationTarball := StandardName(destination, chart)
os.Rename(saved, destinationTarball)
}

// StandardName generates a predictable full path for a helm chart for Zarf
func StandardName(destintation string, chart config.ZarfChart) string {
return destintation + "/" + chart.Name + "-" + chart.Version + ".tgz"
}
6 changes: 4 additions & 2 deletions cli/internal/packager/deploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"github.com/sirupsen/logrus"
"repo1.dso.mil/platform-one/big-bang/apps/product-tools/zarf/cli/config"
"repo1.dso.mil/platform-one/big-bang/apps/product-tools/zarf/cli/internal/git"
"repo1.dso.mil/platform-one/big-bang/apps/product-tools/zarf/cli/internal/helm"
"repo1.dso.mil/platform-one/big-bang/apps/product-tools/zarf/cli/internal/images"
"repo1.dso.mil/platform-one/big-bang/apps/product-tools/zarf/cli/internal/k8s"
"repo1.dso.mil/platform-one/big-bang/apps/product-tools/zarf/cli/internal/utils"
Expand Down Expand Up @@ -160,8 +161,9 @@ func deployLocalAssets(tempPath tempPaths, assets config.ZarfFeature) {
if len(assets.Charts) > 0 {
logrus.Info("Loading charts for local install")
for _, chart := range assets.Charts {
target := "/" + chart.Name + "-" + chart.Version + ".tgz"
utils.CreatePathAndCopy(tempPath.localCharts+target, config.K3sChartPath+target)
sourceTarball := helm.StandardName(tempPath.localCharts, chart)
destinationTarball := helm.StandardName(config.K3sChartPath, chart)
utils.CreatePathAndCopy(sourceTarball, destinationTarball)
}
}

Expand Down

0 comments on commit 6effd13

Please sign in to comment.