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..87b6bb1 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,22 @@ 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 76f8107..91a38fe 100644 Binary files a/testdata/chart-with-file-dependency-chart-1.0.0.tgz and b/testdata/chart-with-file-dependency-chart-1.0.0.tgz differ 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