From 707b30d30db35a62c752c5a86d43b1ff0c3e0cfd Mon Sep 17 00:00:00 2001 From: Josh Wolf Date: Fri, 12 Nov 2021 14:50:26 -0700 Subject: [PATCH] fix bug packaging thick charts --- cmd/hauler/cli/store/sync.go | 4 ++-- pkg/collection/chart/chart.go | 32 +++++++++++++++++++++++++++++++- 2 files changed, 33 insertions(+), 3 deletions(-) diff --git a/cmd/hauler/cli/store/sync.go b/cmd/hauler/cli/store/sync.go index a5a9d01..8188568 100644 --- a/cmd/hauler/cli/store/sync.go +++ b/cmd/hauler/cli/store/sync.go @@ -11,7 +11,7 @@ import ( "k8s.io/apimachinery/pkg/util/yaml" "github.com/rancherfederal/hauler/pkg/apis/hauler.cattle.io/v1alpha1" - "github.com/rancherfederal/hauler/pkg/collection/chart" + tchart "github.com/rancherfederal/hauler/pkg/collection/chart" "github.com/rancherfederal/hauler/pkg/collection/k3s" "github.com/rancherfederal/hauler/pkg/content" "github.com/rancherfederal/hauler/pkg/log" @@ -134,7 +134,7 @@ func SyncCmd(ctx context.Context, o *SyncOpts, s *store.Store) error { } for _, cfg := range cfg.Spec.Charts { - tc, err := chart.NewChart(cfg.Name, cfg.RepoURL, cfg.Version) + tc, err := tchart.NewChart(cfg.Name, cfg.RepoURL, cfg.Version) if err != nil { return err } diff --git a/pkg/collection/chart/chart.go b/pkg/collection/chart/chart.go index 47ab8fc..9ee9c6b 100644 --- a/pkg/collection/chart/chart.go +++ b/pkg/collection/chart/chart.go @@ -12,7 +12,10 @@ var _ artifact.Collection = (*tchart)(nil) // tchart is a thick chart that includes all the dependent images as well as the chart itself type tchart struct { - chart *chart.Chart + name string + repo string + version string + chart *chart.Chart computed bool contents map[gname.Reference]artifact.OCI @@ -25,6 +28,9 @@ func NewChart(name, repo, version string) (artifact.Collection, error) { } return &tchart{ + name: name, + repo: repo, + version: version, chart: o, contents: make(map[gname.Reference]artifact.OCI), }, nil @@ -46,10 +52,34 @@ func (c *tchart) compute() error { return err } + if err := c.chartContents(); err != nil { + return err + } + c.computed = true return nil } +func (c *tchart) chartContents() error { + oci, err := chart.NewChart(c.name, c.repo, c.version) + if err != nil { + return err + } + + tag := c.version + if tag == "" { + tag = gname.DefaultTag + } + + ref, err := gname.ParseReference(c.name, gname.WithDefaultRegistry(""), gname.WithDefaultTag(tag)) + if err != nil { + return err + } + + c.contents[ref] = oci + return nil +} + func (c *tchart) dependentImages() error { ch, err := c.chart.Load() if err != nil {