Skip to content

Commit

Permalink
feat(PL-2834): support mappings per chart and release
Browse files Browse the repository at this point in the history
  • Loading branch information
davidmdm committed Jul 25, 2024
1 parent 83a0638 commit 6c78b3e
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 10 deletions.
9 changes: 5 additions & 4 deletions api/v1alpha1/release.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,11 @@ type ReleaseMetadata struct {
}

type ReleaseChart struct {
Ref string `yaml:"ref,omitempty" json:"ref,omitempty"`
Version string `yaml:"version,omitempty" json:"version,omitempty"`
Name string `yaml:"name,omitempty" json:"name,omitempty"`
RepoUrl string `yaml:"repoUrl,omitempty" json:"repoUrl,omitempty"`
Ref string `yaml:"ref,omitempty" json:"ref,omitempty"`
Version string `yaml:"version,omitempty" json:"version,omitempty"`
Name string `yaml:"name,omitempty" json:"name,omitempty"`
RepoUrl string `yaml:"repoUrl,omitempty" json:"repoUrl,omitempty"`
Mappings map[string]string `yaml:"mappings,omitempty" json:"mappings,omitempty"`
}

func (chart ReleaseChart) Validate(validRefs []string) error {
Expand Down
4 changes: 4 additions & 0 deletions internal/release/render/render.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,10 @@ func HydrateValues(release *v1alpha1.Release, chart *helm.ChartFS, mappings *con
return nil, fmt.Errorf("hydrating object values: %w", err)
}

for key, value := range chart.Mappings {
setInMap(values, splitIntoPathSegments(key), value)
}

if mappings != nil && !slices.Contains(mappings.ReleaseIgnoreList, release.Name) {
for mapping, value := range mappings.Mappings {
setInMap(values, splitIntoPathSegments(mapping), value)
Expand Down
22 changes: 16 additions & 6 deletions pkg/helm/cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"context"
"errors"
"fmt"
"maps"
"net/url"
"os"
"path"
Expand All @@ -24,9 +25,10 @@ type ChartCache struct {
}

type Chart struct {
RepoURL string `yaml:"repoUrl"`
Name string `yaml:"name"`
Version string `yaml:"version"`
RepoURL string `yaml:"repoUrl"`
Name string `yaml:"name"`
Version string `yaml:"version"`
Mappings map[string]string `yaml:"mappings"`
}

func (chart Chart) ToURL() (*url.URL, error) {
Expand Down Expand Up @@ -54,9 +56,10 @@ type ChartFS struct {
func (cache ChartCache) GetReleaseChart(release *v1alpha1.Release) (Chart, error) {
if repoURL := release.Spec.Chart.RepoUrl; repoURL != "" {
return Chart{
RepoURL: repoURL,
Name: release.Spec.Chart.Name,
Version: release.Spec.Chart.Version,
RepoURL: repoURL,
Name: release.Spec.Chart.Name,
Version: release.Spec.Chart.Version,
Mappings: release.Spec.Chart.Mappings,
}, nil
}

Expand All @@ -70,6 +73,13 @@ func (cache ChartCache) GetReleaseChart(release *v1alpha1.Release) (Chart, error
chart.Version,
)

chart.Mappings = func() map[string]string {
mappings := make(map[string]string)
maps.Copy(mappings, chart.Mappings)
maps.Copy(mappings, release.Spec.Chart.Mappings)
return mappings
}()

return chart, nil
}

Expand Down

0 comments on commit 6c78b3e

Please sign in to comment.