diff --git a/internal/controller/controller.go b/internal/controller/controller.go index 06ab203..399a0dc 100644 --- a/internal/controller/controller.go +++ b/internal/controller/controller.go @@ -15,6 +15,7 @@ import ( "git.badhouseplants.net/allanger/shoebill/pkg/config" "git.badhouseplants.net/allanger/shoebill/pkg/lockfile" "git.badhouseplants.net/allanger/shoebill/pkg/release" + "github.com/go-logr/logr" ) func ReadTheConfig(path string) (*config.Config, error) { @@ -36,6 +37,11 @@ type SyncOptions struct { type SyncController struct{} func Sync(ctx context.Context, opts *SyncOptions) error { + log, err := logr.FromContext(ctx) + if err != nil { + return err + } + // Start by creating a directory where everything should be happening configPath := filepath.Dir(opts.Config.ConfigPath) // Prepare helm repositories @@ -109,7 +115,12 @@ func Sync(ctx context.Context, opts *SyncOptions) error { releaseObj := release.FindReleaseByNames(cluster.Releases, opts.Config.Releases) cluster.PopulateReleases(releaseObj) - + for _, oneRelease := range releaseObj { + log.Info("Pullin a helm chart to the git repo", "chart", oneRelease.Chart) + if _, err := hh.PullChart(clusterWorkdirPath, oneRelease.ToHelmReleaseData()); err != nil { + return err + } + } releasesCurrent, err := release.ReleasesFromLockfile(lockfileData, opts.Config.Repositories) if err != nil { return err diff --git a/internal/utils/helmhelper/helm.go b/internal/utils/helmhelper/helm.go index 1676250..2e66022 100644 --- a/internal/utils/helmhelper/helm.go +++ b/internal/utils/helmhelper/helm.go @@ -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 { diff --git a/pkg/release/release.go b/pkg/release/release.go index ca24dfb..203856a 100644 --- a/pkg/release/release.go +++ b/pkg/release/release.go @@ -100,6 +100,7 @@ func (r *Release) VersionHandler(dir string, hh helmhelper.Helmhelper) error { if err != nil { return err } + logrus.Info(version) r.Version = version } diff --git a/shoebill.yaml b/shoebill.yaml index 13370ba..585aca4 100644 --- a/shoebill.yaml +++ b/shoebill.yaml @@ -64,6 +64,7 @@ clusters: - age: - age1hcpgy4yy4psp6y2jt8waemzgg7crtlpxf3a48l6jvl6zmxll3vjsxj75vu provider: flux + reconcileRef: main releases: - metrics-server - istio-base