Pull charts
This commit is contained in:
@ -3,6 +3,7 @@ package helmhelper
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
"path/filepath"
|
||||
|
||||
"github.com/sirupsen/logrus"
|
||||
"gopkg.in/yaml.v2"
|
||||
@ -11,9 +12,7 @@ import (
|
||||
"helm.sh/helm/v3/pkg/chartutil"
|
||||
"helm.sh/helm/v3/pkg/cli"
|
||||
"helm.sh/helm/v3/pkg/engine"
|
||||
"helm.sh/helm/v3/pkg/getter"
|
||||
"helm.sh/helm/v3/pkg/registry"
|
||||
"helm.sh/helm/v3/pkg/repo"
|
||||
)
|
||||
|
||||
type Helm struct{}
|
||||
@ -27,8 +26,7 @@ func getDownloadDirPath(workdirPath string) string {
|
||||
}
|
||||
|
||||
func getChartDirPath(downloadDirPath string, release *ReleaseData) string {
|
||||
return fmt.Sprintf("%s/%s-%s-%s", downloadDirPath, release.RepositoryName, release.Chart, release.Version)
|
||||
|
||||
return fmt.Sprintf("%s/%s-%s", downloadDirPath, release.Chart, release.Name)
|
||||
}
|
||||
|
||||
func (h *Helm) PullChart(workdirPath string, release *ReleaseData) (path string, err error) {
|
||||
@ -53,29 +51,21 @@ func (h *Helm) PullChart(workdirPath string, release *ReleaseData) (path string,
|
||||
return "", err
|
||||
}
|
||||
|
||||
client := action.NewPullWithOpts(action.WithConfig(config))
|
||||
var path string
|
||||
var chartRemote string
|
||||
// Download the chart to the workdir
|
||||
if release.RepositoryKind != "oci" {
|
||||
r, err := repo.NewChartRepository(&repo.Entry{
|
||||
Name: release.RepositoryName,
|
||||
URL: release.RepositoryURL,
|
||||
}, getter.All(cl))
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
path = r.Config.Name
|
||||
|
||||
client.RepoURL = release.RepositoryURL
|
||||
chartRemote = fmt.Sprintf(release.Chart)
|
||||
} else {
|
||||
path = release.RepositoryURL
|
||||
}
|
||||
|
||||
client := action.NewPullWithOpts(action.WithConfig(config))
|
||||
chartRemote = fmt.Sprintf("%s/%s", path, release.Chart)
|
||||
client.SetRegistryClient(registry)
|
||||
client.DestDir = chartDir
|
||||
}
|
||||
client.Settings = cl
|
||||
|
||||
chartRemote := fmt.Sprintf("%s/%s", path, release.Chart)
|
||||
logrus.Infof("trying to pull: %s", chartRemote)
|
||||
client.Untar = true
|
||||
client.UntarDir = chartDir
|
||||
if _, err = client.Run(chartRemote); err != nil {
|
||||
return "", err
|
||||
}
|
||||
@ -160,7 +150,17 @@ func (h *Helm) RenderChart(workdirPath string, release *ReleaseData) error {
|
||||
}
|
||||
|
||||
func getChartPathFromDir(downloadDir string) (file string, err error) {
|
||||
filesRM, err := filepath.Glob(fmt.Sprintf("%s/*.tgz", downloadDir))
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
for _, f := range filesRM {
|
||||
if err := os.Remove(f); err != nil {
|
||||
return "", err
|
||||
}
|
||||
}
|
||||
files, err := os.ReadDir(downloadDir)
|
||||
|
||||
if err != nil {
|
||||
return "", err
|
||||
} else if len(files) == 0 {
|
||||
|
Reference in New Issue
Block a user