Skip to content

Commit

Permalink
chore: initial implementation of Helm Chart overrides at deploy time (#…
Browse files Browse the repository at this point in the history
…2131)

## Description

This is an initial implementation for Helm Chart overrides on deploy as
library code.

## Related Issue

Fixes #2127 

## Type of change

- [ ] Bug fix (non-breaking change which fixes an issue)
- [x] New feature (non-breaking change which adds functionality)
- [ ] Other (security config, docs update, etc)

## Checklist before merging

- [x] Test, docs, adr added or updated as needed
- [x] [Contributor Guide
Steps](https://github.com/defenseunicorns/zarf/blob/main/CONTRIBUTING.md#developer-workflow)
followed
  • Loading branch information
Racer159 authored Nov 8, 2023
1 parent ce4e953 commit f145e3f
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 5 deletions.
6 changes: 3 additions & 3 deletions src/internal/packager/helm/chart.go
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@ func (h *Helm) GenerateChart(manifest types.ZarfManifest) error {
h.ChartOverride = tmpChart

// We don't have any values because we do not expose them in the zarf.yaml currently.
h.ValueOverride = map[string]any{}
h.ValuesOverrides = map[string]any{}

spinner.Success()

Expand Down Expand Up @@ -426,7 +426,7 @@ func (h *Helm) loadChartData() (*chart.Chart, chartutil.Values, error) {
err error
)

if h.ChartOverride == nil || h.ValueOverride == nil {
if h.ChartOverride == nil {
// If there is no override, get the chart and values info.
loadedChart, err = h.loadChartFromTarball()
if err != nil {
Expand All @@ -440,7 +440,7 @@ func (h *Helm) loadChartData() (*chart.Chart, chartutil.Values, error) {
} else {
// Otherwise, use the overrides instead.
loadedChart = h.ChartOverride
chartValues = h.ValueOverride
chartValues = h.ValuesOverrides
}

return loadedChart, chartValues, nil
Expand Down
2 changes: 1 addition & 1 deletion src/internal/packager/helm/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ type Helm struct {
ReleaseName string
ChartLoadOverride string
ChartOverride *chart.Chart
ValueOverride map[string]any
ValuesOverrides map[string]any
Component types.ZarfComponent
Cluster *cluster.Cluster
Cfg *types.PackagerConfig
Expand Down
8 changes: 7 additions & 1 deletion src/internal/packager/helm/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (

"github.com/defenseunicorns/zarf/src/pkg/layout"
"github.com/defenseunicorns/zarf/src/pkg/message"
"github.com/defenseunicorns/zarf/src/pkg/utils/helpers"
"helm.sh/helm/v3/pkg/action"
"helm.sh/helm/v3/pkg/chart"
"helm.sh/helm/v3/pkg/chartutil"
Expand Down Expand Up @@ -61,7 +62,12 @@ func (h *Helm) parseChartValues() (chartutil.Values, error) {
}

providers := getter.Providers{httpProvider}
return valueOpts.MergeValues(providers)
chartValues, err := valueOpts.MergeValues(providers)
if err != nil {
return chartValues, err
}

return helpers.MergeMapRecursive(chartValues, h.ValuesOverrides), nil
}

func (h *Helm) createActionConfig(namespace string, spinner *message.Spinner) error {
Expand Down
7 changes: 7 additions & 0 deletions src/pkg/packager/deploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -526,6 +526,13 @@ func (p *Packager) installChartAndManifests(componentPath *layout.ComponentPaths
Cluster: p.cluster,
}

// TODO (@WSTARR): Currently this logic is library-only and is untested while it is in an experimental state - it may eventually get added as shorthand in Zarf Variables though
if componentChartValuesOverrides, ok := p.cfg.DeployOpts.ValuesOverridesMap[component.Name]; ok {
if chartValuesOverrides, ok := componentChartValuesOverrides[chart.Name]; ok {
helmCfg.ValuesOverrides = chartValuesOverrides
}
}

addedConnectStrings, installedChartName, err := helmCfg.InstallOrUpgradeChart()
if err != nil {
return installedCharts, err
Expand Down
3 changes: 3 additions & 0 deletions src/types/runtime.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,9 @@ type ZarfFindImagesOptions struct {
type ZarfDeployOptions struct {
AdoptExistingResources bool `json:"adoptExistingResources" jsonschema:"description=Whether to adopt any pre-existing K8s resources into the Helm charts managed by Zarf"`
SkipWebhooks bool `json:"componentWebhooks" jsonschema:"description=Skip waiting for external webhooks to execute as each package component is deployed"`

// TODO (@WSTARR): This is a library only addition to Zarf and should be refactored in the future (potentially to utilize component composability). As is it should NOT be exposed directly on the CLI
ValuesOverridesMap map[string]map[string]map[string]interface{} `json:"valuesOverridesMap" jsonschema:"description=[Library Only] A map of component names to chart names containing Helm Chart values to override values on deploy"`
}

// ZarfMirrorOptions tracks the user-defined preferences during a package mirror.
Expand Down

0 comments on commit f145e3f

Please sign in to comment.