From 581ea4c7e39d5b82cc3c70b5f626675bcc77d2ec Mon Sep 17 00:00:00 2001 From: "mergify[bot]" <37929162+mergify[bot]@users.noreply.github.com> Date: Thu, 9 Jul 2026 14:25:59 -0400 Subject: [PATCH] feat: extend charts resource with helm values (backport #644) (#655) Signed-off-by: Zack Brady Co-authored-by: Eric Klatzer Co-authored-by: Zack Brady --- .github/workflows/tests.yaml | 2 ++ cmd/hauler/cli/store/add.go | 16 ++++++++++++---- cmd/hauler/cli/store/sync.go | 6 ++++++ internal/flags/add.go | 4 ++-- pkg/apis/hauler.cattle.io/v1/chart.go | 9 +++++---- .../chart-with-file-dependency-chart-1.0.0.tgz | Bin 774 -> 883 bytes ...file-dependency-chart-required-values-2.yaml | 3 +++ ...h-file-dependency-chart-required-values.yaml | 2 ++ testdata/hauler-manifest-pipeline.yaml | 4 ++++ 9 files changed, 36 insertions(+), 10 deletions(-) create mode 100644 testdata/chart-with-file-dependency-chart-required-values-2.yaml create mode 100644 testdata/chart-with-file-dependency-chart-required-values.yaml diff --git a/.github/workflows/tests.yaml b/.github/workflows/tests.yaml index f9df603..ad3dde9 100644 --- a/.github/workflows/tests.yaml +++ b/.github/workflows/tests.yaml @@ -314,6 +314,8 @@ jobs: hauler store sync --help # verify via sync hauler store sync --filename testdata/hauler-manifest-pipeline.yaml + # verify images are present + hauler store info | grep 'musl' # verify via sync with multiple files hauler store sync --filename testdata/hauler-manifest-pipeline.yaml --filename testdata/hauler-manifest.yaml # need more tests here diff --git a/cmd/hauler/cli/store/add.go b/cmd/hauler/cli/store/add.go index a281131..b2867b7 100644 --- a/cmd/hauler/cli/store/add.go +++ b/cmd/hauler/cli/store/add.go @@ -1,6 +1,7 @@ package store import ( + "bytes" "context" "fmt" "os" @@ -14,6 +15,7 @@ import ( "helm.sh/helm/v4/pkg/chart/common" commonutil "helm.sh/helm/v4/pkg/chart/common/util" helmchart "helm.sh/helm/v4/pkg/chart/v2" + "helm.sh/helm/v4/pkg/chart/v2/loader" "helm.sh/helm/v4/pkg/chart/v2/util" "helm.sh/helm/v4/pkg/engine" "k8s.io/apimachinery/pkg/util/yaml" @@ -484,12 +486,18 @@ func storeChart(ctx context.Context, s *store.Layout, cfg v1.Chart, opts *flags. // add-images if opts.AddImages { - userValues := common.Values{} - if opts.HelmValues != "" { - userValues, err = common.ReadValuesFile(opts.HelmValues) + userValues := map[string]any{} + for _, valuesFile := range opts.ValuesFiles { + l.Debugf("loading values for chart [%s]", valuesFile) + valuesContent, err := os.ReadFile(valuesFile) if err != nil { - return fmt.Errorf("failed to read helm values file [%s]: %w", opts.HelmValues, err) + return fmt.Errorf("failed to read values file [%s]: %w", valuesFile, err) } + vals, err := loader.LoadValues(bytes.NewReader(valuesContent)) + if err != nil { + return fmt.Errorf("failed to read helm values file [%s]: %w", valuesFile, err) + } + userValues = loader.MergeMaps(userValues, vals) } // set helm default capabilities diff --git a/cmd/hauler/cli/store/sync.go b/cmd/hauler/cli/store/sync.go index c4e73c8..d3d5404 100644 --- a/cmd/hauler/cli/store/sync.go +++ b/cmd/hauler/cli/store/sync.go @@ -496,6 +496,11 @@ func processContent(ctx context.Context, fi *os.File, o *flags.SyncOpts, s *stor excludeExtras = ch.ExcludeExtras } + var valuesFiles []string + for _, path := range ch.ValuesFiles { + valuesFiles = append(valuesFiles, filepath.Join(filepath.Dir(fi.Name()), path)) + } + if err := storeChart(ctx, s, ch, &flags.AddChartOpts{ ChartOpts: &action.ChartPathOptions{ @@ -507,6 +512,7 @@ func processContent(ctx context.Context, fi *os.File, o *flags.SyncOpts, s *stor ExcludeExtras: excludeExtras, Registry: registry, Platform: o.Platform, + ValuesFiles: valuesFiles, }, rso, ro, cfg.Spec.Charts[i].Rewrite, diff --git a/internal/flags/add.go b/internal/flags/add.go index 9c8f45b..06c92a6 100644 --- a/internal/flags/add.go +++ b/internal/flags/add.go @@ -54,7 +54,7 @@ type AddChartOpts struct { AddDependencies bool AddImages bool ExcludeExtras bool - HelmValues string + ValuesFiles []string Platform string Registry string KubeVersion string @@ -80,7 +80,7 @@ func (o *AddChartOpts) AddFlags(cmd *cobra.Command) { cmd.Flags().BoolVar(&o.AddDependencies, "add-dependencies", false, "(Optional) Fetch dependent helm charts") f.BoolVar(&o.AddImages, "add-images", false, "(Optional) Fetch images referenced in helm charts") f.BoolVar(&o.ExcludeExtras, "exclude-extras", false, "(Optional) Exclude cosign signatures, attestations, SBOMs, and OCI referrers when pulling images discovered via --add-images") - f.StringVar(&o.HelmValues, "values", "", "(Optional) Specify helm chart values when fetching images") + f.StringArrayVar(&o.ValuesFiles, "values", []string{}, "(Optional) Specify helm chart values when fetching images") f.StringVarP(&o.Platform, "platform", "p", "", "(Optional) Specify the platform of the image, e.g. linux/amd64") f.StringVarP(&o.Registry, "registry", "g", "", "(Optional) Specify the registry of the image for images that do not alredy define one") f.StringVar(&o.KubeVersion, "kube-version", "v1.34.1", "(Optional) Override the kubernetes version for helm template rendering") diff --git a/pkg/apis/hauler.cattle.io/v1/chart.go b/pkg/apis/hauler.cattle.io/v1/chart.go index c87897a..ba63ad2 100644 --- a/pkg/apis/hauler.cattle.io/v1/chart.go +++ b/pkg/apis/hauler.cattle.io/v1/chart.go @@ -16,10 +16,11 @@ type ChartSpec struct { } type Chart struct { - Name string `json:"name,omitempty"` - RepoURL string `json:"repoURL,omitempty"` - Version string `json:"version,omitempty"` - Rewrite string `json:"rewrite,omitempty"` + Name string `json:"name,omitempty"` + RepoURL string `json:"repoURL,omitempty"` + Version string `json:"version,omitempty"` + Rewrite string `json:"rewrite,omitempty"` + ValuesFiles []string `json:"valuesFiles,omitempty"` AddImages bool `json:"add-images,omitempty"` AddDependencies bool `json:"add-dependencies,omitempty"` diff --git a/testdata/chart-with-file-dependency-chart-1.0.0.tgz b/testdata/chart-with-file-dependency-chart-1.0.0.tgz index 76f8107c69d39b8bebb5daf4929eea09ba9bd03e..91a38fed0f98416db7ab3b023126fd8a6ae0e891 100644 GIT binary patch delta 837 zcmV-L1G@Z%2J;4xJAYYCkE2Eq^_gGM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Qg&^?x~1V-e?NbcXX+z9l4XzO5Z7JeY9EHKA@7p{J^eH-ZKgsarE*n41(K{} zVXy$wRDb2UFq(1=Mj=U|GKrNInJy4AFbbS@6{)XirCQYg`RJ1|#jV{7Ea@LiI@3Sb zf^Yi22ebTt6WQNL+GAqpU(qDqSj~s@zcLFf`oB^${YxX$P5<{`rTm3QlZd|fL8z_S0#xlsQbB{u!vgMaq_vo_uc0Al;q_CMic z`d=3SmiPa&|NlaPfldGSV6Fd8?)f?ZoC`jc0H&_jM1ZTOZy8`?V`F21zXAXN|NnBK JCv^ZI001PQbwmIF diff --git a/testdata/chart-with-file-dependency-chart-required-values-2.yaml b/testdata/chart-with-file-dependency-chart-required-values-2.yaml new file mode 100644 index 0000000..dbd1b21 --- /dev/null +++ b/testdata/chart-with-file-dependency-chart-required-values-2.yaml @@ -0,0 +1,3 @@ +--- +labels: + product: "musl" \ No newline at end of file diff --git a/testdata/chart-with-file-dependency-chart-required-values.yaml b/testdata/chart-with-file-dependency-chart-required-values.yaml new file mode 100644 index 0000000..1e19b46 --- /dev/null +++ b/testdata/chart-with-file-dependency-chart-required-values.yaml @@ -0,0 +1,2 @@ +--- +image: "ghcr.io/hauler-dev/library/busybox:musl" diff --git a/testdata/hauler-manifest-pipeline.yaml b/testdata/hauler-manifest-pipeline.yaml index 35ffcb7..64e738b 100755 --- a/testdata/hauler-manifest-pipeline.yaml +++ b/testdata/hauler-manifest-pipeline.yaml @@ -41,6 +41,10 @@ spec: - name: chart-with-file-dependency-chart-1.0.0.tgz repoURL: testdata add-dependencies: true + add-images: true + valuesFiles: + - "chart-with-file-dependency-chart-required-values-2.yaml" + - "chart-with-file-dependency-chart-required-values.yaml" --- apiVersion: content.hauler.cattle.io/v1 kind: Files