Skip to content

Commit d931671

Browse files
eklatzerzackbradys
andauthored
feat: extend charts resource with helm values (#644)
Signed-off-by: Eric Klatzer <eric@klatzer.at> Co-authored-by: Zack Brady <zackbrady123@gmail.com>
1 parent cbf07f0 commit d931671

9 files changed

Lines changed: 40 additions & 10 deletions

File tree

.github/workflows/tests.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -314,6 +314,8 @@ jobs:
314314
hauler store sync --help
315315
# verify via sync
316316
hauler store sync --filename testdata/hauler-manifest-pipeline.yaml
317+
# verify images are present
318+
hauler store info | grep 'musl'
317319
# verify via sync with multiple files
318320
hauler store sync --filename testdata/hauler-manifest-pipeline.yaml --filename testdata/hauler-manifest.yaml
319321
# need more tests here

cmd/hauler/cli/store/add.go

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package store
22

33
import (
4+
"bytes"
45
"context"
56
"fmt"
67
"os"
@@ -14,6 +15,7 @@ import (
1415
"helm.sh/helm/v4/pkg/chart/common"
1516
commonutil "helm.sh/helm/v4/pkg/chart/common/util"
1617
helmchart "helm.sh/helm/v4/pkg/chart/v2"
18+
"helm.sh/helm/v4/pkg/chart/v2/loader"
1719
"helm.sh/helm/v4/pkg/chart/v2/util"
1820
"helm.sh/helm/v4/pkg/engine"
1921
"k8s.io/apimachinery/pkg/util/yaml"
@@ -484,12 +486,22 @@ func storeChart(ctx context.Context, s *store.Layout, cfg v1.Chart, opts *flags.
484486

485487
// add-images
486488
if opts.AddImages {
487-
userValues := common.Values{}
488-
if opts.HelmValues != "" {
489-
userValues, err = common.ReadValuesFile(opts.HelmValues)
489+
userValues := map[string]any{}
490+
491+
for _, valuesFile := range opts.ValuesFiles {
492+
l.Debugf("loading values for chart [%s]", valuesFile)
493+
494+
valuesContent, err := os.ReadFile(valuesFile)
495+
if err != nil {
496+
return fmt.Errorf("failed to read values file [%s]: %w", valuesFile, err)
497+
}
498+
499+
vals, err := loader.LoadValues(bytes.NewReader(valuesContent))
490500
if err != nil {
491-
return fmt.Errorf("failed to read helm values file [%s]: %w", opts.HelmValues, err)
501+
return fmt.Errorf("failed to read helm values file [%s]: %w", valuesFile, err)
492502
}
503+
504+
userValues = loader.MergeMaps(userValues, vals)
493505
}
494506

495507
// set helm default capabilities

cmd/hauler/cli/store/sync.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -496,6 +496,11 @@ func processContent(ctx context.Context, fi *os.File, o *flags.SyncOpts, s *stor
496496
excludeExtras = ch.ExcludeExtras
497497
}
498498

499+
var valuesFiles []string
500+
for _, path := range ch.ValuesFiles {
501+
valuesFiles = append(valuesFiles, filepath.Join(filepath.Dir(fi.Name()), path))
502+
}
503+
499504
if err := storeChart(ctx, s, ch,
500505
&flags.AddChartOpts{
501506
ChartOpts: &action.ChartPathOptions{
@@ -507,6 +512,7 @@ func processContent(ctx context.Context, fi *os.File, o *flags.SyncOpts, s *stor
507512
ExcludeExtras: excludeExtras,
508513
Registry: registry,
509514
Platform: o.Platform,
515+
ValuesFiles: valuesFiles,
510516
},
511517
rso, ro,
512518
cfg.Spec.Charts[i].Rewrite,

internal/flags/add.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ type AddChartOpts struct {
5454
AddDependencies bool
5555
AddImages bool
5656
ExcludeExtras bool
57-
HelmValues string
57+
ValuesFiles []string
5858
Platform string
5959
Registry string
6060
KubeVersion string
@@ -80,7 +80,7 @@ func (o *AddChartOpts) AddFlags(cmd *cobra.Command) {
8080
cmd.Flags().BoolVar(&o.AddDependencies, "add-dependencies", false, "(Optional) Fetch dependent helm charts")
8181
f.BoolVar(&o.AddImages, "add-images", false, "(Optional) Fetch images referenced in helm charts")
8282
f.BoolVar(&o.ExcludeExtras, "exclude-extras", false, "(Optional) Exclude cosign signatures, attestations, SBOMs, and OCI referrers when pulling images discovered via --add-images")
83-
f.StringVar(&o.HelmValues, "values", "", "(Optional) Specify helm chart values when fetching images")
83+
f.StringArrayVar(&o.ValuesFiles, "values", []string{}, "(Optional) Specify helm chart values when fetching images")
8484
f.StringVarP(&o.Platform, "platform", "p", "", "(Optional) Specify the platform of the image, e.g. linux/amd64")
8585
f.StringVarP(&o.Registry, "registry", "g", "", "(Optional) Specify the registry of the image for images that do not alredy define one")
8686
f.StringVar(&o.KubeVersion, "kube-version", "v1.34.1", "(Optional) Override the kubernetes version for helm template rendering")

pkg/apis/hauler.cattle.io/v1/chart.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,11 @@ type ChartSpec struct {
1616
}
1717

1818
type Chart struct {
19-
Name string `json:"name,omitempty"`
20-
RepoURL string `json:"repoURL,omitempty"`
21-
Version string `json:"version,omitempty"`
22-
Rewrite string `json:"rewrite,omitempty"`
19+
Name string `json:"name,omitempty"`
20+
RepoURL string `json:"repoURL,omitempty"`
21+
Version string `json:"version,omitempty"`
22+
Rewrite string `json:"rewrite,omitempty"`
23+
ValuesFiles []string `json:"valuesFiles,omitempty"`
2324

2425
AddImages bool `json:"add-images,omitempty"`
2526
AddDependencies bool `json:"add-dependencies,omitempty"`
109 Bytes
Binary file not shown.
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
---
2+
labels:
3+
product: "musl"
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
---
2+
image: "ghcr.io/hauler-dev/library/busybox:musl"

testdata/hauler-manifest-pipeline.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,10 @@ spec:
4141
- name: chart-with-file-dependency-chart-1.0.0.tgz
4242
repoURL: testdata
4343
add-dependencies: true
44+
add-images: true
45+
valuesFiles:
46+
- "chart-with-file-dependency-chart-required-values-2.yaml"
47+
- "chart-with-file-dependency-chart-required-values.yaml"
4448
---
4549
apiVersion: content.hauler.cattle.io/v1
4650
kind: Files

0 commit comments

Comments
 (0)