feat: extend charts resource with helm values (backport #644) (#655)

Signed-off-by: Zack Brady <zackbrady123@gmail.com>
Co-authored-by: Eric Klatzer <eric@klatzer.at>
Co-authored-by: Zack Brady <zackbrady123@gmail.com>
This commit is contained in:
mergify[bot]
2026-07-09 14:25:59 -04:00
committed by GitHub
co-authored by Eric Klatzer Zack Brady
parent a3543f6cf0
commit 581ea4c7e3
9 changed files with 36 additions and 10 deletions
+2
View File
@@ -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
+12 -4
View File
@@ -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
+6
View File
@@ -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,
+2 -2
View File
@@ -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")
+5 -4
View File
@@ -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"`
Binary file not shown.
@@ -0,0 +1,3 @@
---
labels:
product: "musl"
@@ -0,0 +1,2 @@
---
image: "ghcr.io/hauler-dev/library/busybox:musl"
+4
View File
@@ -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