refactor: Move chartutil release code to releaseutil

Signed-off-by: George Jenkins <gvjenkins@gmail.com>
pull/13598/head
George Jenkins 9 months ago
parent a142da0811
commit 07d58b5c1c

@ -30,10 +30,10 @@ import (
"helm.sh/helm/v4/internal/test"
"helm.sh/helm/v4/pkg/action"
"helm.sh/helm/v4/pkg/chartutil"
"helm.sh/helm/v4/pkg/cli"
kubefake "helm.sh/helm/v4/pkg/kube/fake"
"helm.sh/helm/v4/pkg/release"
"helm.sh/helm/v4/pkg/releaseutil"
"helm.sh/helm/v4/pkg/storage"
"helm.sh/helm/v4/pkg/storage/driver"
"helm.sh/helm/v4/pkg/time"
@ -93,7 +93,7 @@ func executeActionCommandStdinC(store *storage.Storage, in *os.File, cmd string)
actionConfig := &action.Configuration{
Releases: store,
KubeClient: &kubefake.PrintingKubeClient{Out: io.Discard},
Capabilities: chartutil.DefaultCapabilities,
Capabilities: releaseutil.DefaultCapabilities,
Log: func(_ string, _ ...interface{}) {},
}

@ -27,10 +27,10 @@ import (
"github.com/spf13/cobra"
"helm.sh/helm/v4/pkg/action"
"helm.sh/helm/v4/pkg/chartutil"
"helm.sh/helm/v4/pkg/cli/values"
"helm.sh/helm/v4/pkg/getter"
"helm.sh/helm/v4/pkg/lint/support"
"helm.sh/helm/v4/pkg/releaseutil"
)
var longLintHelp = `
@ -58,7 +58,7 @@ func newLintCmd(out io.Writer) *cobra.Command {
}
if kubeVersion != "" {
parsedKubeVersion, err := chartutil.ParseKubeVersion(kubeVersion)
parsedKubeVersion, err := releaseutil.ParseKubeVersion(kubeVersion)
if err != nil {
return fmt.Errorf("invalid kube version '%s': %s", kubeVersion, err)
}

@ -30,9 +30,9 @@ import (
"helm.sh/helm/v4/cmd/helm/require"
"helm.sh/helm/v4/pkg/action"
"helm.sh/helm/v4/pkg/chartutil"
"helm.sh/helm/v4/pkg/cli/output"
"helm.sh/helm/v4/pkg/release"
"helm.sh/helm/v4/pkg/releaseutil"
)
// NOTE: Keep the list of statuses up-to-date with pkg/release/status.go.
@ -194,7 +194,7 @@ func (s statusPrinter) WriteTable(out io.Writer) error {
// Print an extra newline
_, _ = fmt.Fprintln(out)
cfg, err := chartutil.CoalesceValues(s.release.Chart, s.release.Config)
cfg, err := releaseutil.CoalesceValues(s.release.Chart, s.release.Config)
if err != nil {
return err
}

@ -34,7 +34,6 @@ import (
"helm.sh/helm/v4/cmd/helm/require"
"helm.sh/helm/v4/pkg/action"
"helm.sh/helm/v4/pkg/chartutil"
"helm.sh/helm/v4/pkg/cli/values"
"helm.sh/helm/v4/pkg/releaseutil"
)
@ -67,7 +66,7 @@ func newTemplateCmd(cfg *action.Configuration, out io.Writer) *cobra.Command {
},
RunE: func(_ *cobra.Command, args []string) error {
if kubeVersion != "" {
parsedKubeVersion, err := chartutil.ParseKubeVersion(kubeVersion)
parsedKubeVersion, err := releaseutil.ParseKubeVersion(kubeVersion)
if err != nil {
return fmt.Errorf("invalid kube version '%s': %s", kubeVersion, err)
}
@ -91,7 +90,7 @@ func newTemplateCmd(cfg *action.Configuration, out io.Writer) *cobra.Command {
client.ReleaseName = "release-name"
client.Replace = true // Skip the name check
client.ClientOnly = !validate
client.APIVersions = chartutil.VersionSet(extraAPIs)
client.APIVersions = releaseutil.VersionSet(extraAPIs)
client.IncludeCRDs = includeCrds
rel, err := runInstall(args, client, valueOpts, out)

@ -33,7 +33,6 @@ import (
"k8s.io/client-go/rest"
"helm.sh/helm/v4/pkg/chart"
"helm.sh/helm/v4/pkg/chartutil"
"helm.sh/helm/v4/pkg/engine"
"helm.sh/helm/v4/pkg/kube"
"helm.sh/helm/v4/pkg/postrender"
@ -92,7 +91,7 @@ type Configuration struct {
RegistryClient *registry.Client
// Capabilities describes the capabilities of the Kubernetes cluster.
Capabilities *chartutil.Capabilities
Capabilities *releaseutil.Capabilities
Log func(string, ...interface{})
}
@ -103,7 +102,7 @@ type Configuration struct {
// TODO: As part of the refactor the duplicate code in cmd/helm/template.go should be removed
//
// This code has to do with writing files to disk.
func (cfg *Configuration) renderResources(ch *chart.Chart, values chartutil.Values, releaseName, outputDir string, subNotes, useReleaseName, includeCrds bool, pr postrender.PostRenderer, interactWithRemote, enableDNS, hideSecret bool) ([]*release.Hook, *bytes.Buffer, string, error) {
func (cfg *Configuration) renderResources(ch *chart.Chart, values releaseutil.Values, releaseName, outputDir string, subNotes, useReleaseName, includeCrds bool, pr postrender.PostRenderer, interactWithRemote, enableDNS, hideSecret bool) ([]*release.Hook, *bytes.Buffer, string, error) {
hs := []*release.Hook{}
b := bytes.NewBuffer(nil)
@ -113,7 +112,7 @@ func (cfg *Configuration) renderResources(ch *chart.Chart, values chartutil.Valu
}
if ch.Metadata.KubeVersion != "" {
if !chartutil.IsCompatibleRange(ch.Metadata.KubeVersion, caps.KubeVersion.String()) {
if !releaseutil.IsCompatibleRange(ch.Metadata.KubeVersion, caps.KubeVersion.String()) {
return hs, b, "", errors.Errorf("chart requires kubeVersion: %s which is incompatible with Kubernetes %s", ch.Metadata.KubeVersion, caps.KubeVersion.String())
}
}
@ -243,7 +242,7 @@ type RESTClientGetter interface {
type DebugLog func(format string, v ...interface{})
// capabilities builds a Capabilities from discovery information.
func (cfg *Configuration) getCapabilities() (*chartutil.Capabilities, error) {
func (cfg *Configuration) getCapabilities() (*releaseutil.Capabilities, error) {
if cfg.Capabilities != nil {
return cfg.Capabilities, nil
}
@ -272,14 +271,14 @@ func (cfg *Configuration) getCapabilities() (*chartutil.Capabilities, error) {
}
}
cfg.Capabilities = &chartutil.Capabilities{
cfg.Capabilities = &releaseutil.Capabilities{
APIVersions: apiVersions,
KubeVersion: chartutil.KubeVersion{
KubeVersion: releaseutil.KubeVersion{
Version: kubeVersion.GitVersion,
Major: kubeVersion.Major,
Minor: kubeVersion.Minor,
},
HelmVersion: chartutil.DefaultCapabilities.HelmVersion,
HelmVersion: releaseutil.DefaultCapabilities.HelmVersion,
}
return cfg.Capabilities, nil
}
@ -303,7 +302,7 @@ func (cfg *Configuration) Now() time.Time {
}
func (cfg *Configuration) releaseContent(name string, version int) (*release.Release, error) {
if err := chartutil.ValidateReleaseName(name); err != nil {
if err := releaseutil.ValidateReleaseName(name); err != nil {
return nil, errors.Errorf("releaseContent: Release name is invalid: %s", name)
}
@ -315,10 +314,10 @@ func (cfg *Configuration) releaseContent(name string, version int) (*release.Rel
}
// GetVersionSet retrieves a set of available k8s API versions
func GetVersionSet(client discovery.ServerResourcesInterface) (chartutil.VersionSet, error) {
func GetVersionSet(client discovery.ServerResourcesInterface) (releaseutil.VersionSet, error) {
groups, resources, err := client.ServerGroupsAndResources()
if err != nil && !discovery.IsGroupDiscoveryFailedError(err) {
return chartutil.DefaultVersionSet, errors.Wrap(err, "could not get apiVersions from Kubernetes")
return releaseutil.DefaultVersionSet, errors.Wrap(err, "could not get apiVersions from Kubernetes")
}
// FIXME: The Kubernetes test fixture for cli appears to always return nil
@ -326,7 +325,7 @@ func GetVersionSet(client discovery.ServerResourcesInterface) (chartutil.Version
// return the default API list. This is also a safe value to return in any
// other odd-ball case.
if len(groups) == 0 && len(resources) == 0 {
return chartutil.DefaultVersionSet, nil
return releaseutil.DefaultVersionSet, nil
}
versionMap := make(map[string]interface{})
@ -359,7 +358,7 @@ func GetVersionSet(client discovery.ServerResourcesInterface) (chartutil.Version
versions = append(versions, k)
}
return chartutil.VersionSet(versions), nil
return releaseutil.VersionSet(versions), nil
}
// recordRelease with an update operation in case reuse has been set.

@ -25,10 +25,10 @@ import (
fakeclientset "k8s.io/client-go/kubernetes/fake"
"helm.sh/helm/v4/pkg/chart"
"helm.sh/helm/v4/pkg/chartutil"
kubefake "helm.sh/helm/v4/pkg/kube/fake"
"helm.sh/helm/v4/pkg/registry"
"helm.sh/helm/v4/pkg/release"
"helm.sh/helm/v4/pkg/releaseutil"
"helm.sh/helm/v4/pkg/storage"
"helm.sh/helm/v4/pkg/storage/driver"
"helm.sh/helm/v4/pkg/time"
@ -47,7 +47,7 @@ func actionConfigFixture(t *testing.T) *Configuration {
return &Configuration{
Releases: storage.Init(driver.NewMemory()),
KubeClient: &kubefake.FailingKubeClient{PrintingKubeClient: kubefake.PrintingKubeClient{Out: io.Discard}},
Capabilities: chartutil.DefaultCapabilities,
Capabilities: releaseutil.DefaultCapabilities,
RegistryClient: registryClient,
Log: func(format string, v ...interface{}) {
t.Helper()

@ -16,9 +16,7 @@ limitations under the License.
package action
import (
"helm.sh/helm/v4/pkg/chartutil"
)
import "helm.sh/helm/v4/pkg/releaseutil"
// GetValues is the action for checking a given release's values.
//
@ -50,7 +48,7 @@ func (g *GetValues) Run(name string) (map[string]interface{}, error) {
// If the user wants all values, compute the values and return.
if g.AllValues {
cfg, err := chartutil.CoalesceValues(rel.Chart, rel.Config)
cfg, err := releaseutil.CoalesceValues(rel.Chart, rel.Config)
if err != nil {
return nil, err
}

@ -19,8 +19,8 @@ package action
import (
"github.com/pkg/errors"
"helm.sh/helm/v4/pkg/chartutil"
"helm.sh/helm/v4/pkg/release"
"helm.sh/helm/v4/pkg/releaseutil"
)
// History is the action for checking the release's ledger.
@ -49,7 +49,7 @@ func (h *History) Run(name string) ([]*release.Release, error) {
return nil, err
}
if err := chartutil.ValidateReleaseName(name); err != nil {
if err := releaseutil.ValidateReleaseName(name); err != nil {
return nil, errors.Errorf("release name is invalid: %s", name)
}

@ -40,7 +40,6 @@ import (
"sigs.k8s.io/yaml"
"helm.sh/helm/v4/pkg/chart"
"helm.sh/helm/v4/pkg/chartutil"
"helm.sh/helm/v4/pkg/cli"
"helm.sh/helm/v4/pkg/downloader"
"helm.sh/helm/v4/pkg/getter"
@ -101,8 +100,8 @@ type Install struct {
// KubeVersion allows specifying a custom kubernetes version to use and
// APIVersions allows a manual set of supported API Versions to be passed
// (for things like templating). These are ignored if ClientOnly is false
KubeVersion *chartutil.KubeVersion
APIVersions chartutil.VersionSet
KubeVersion *releaseutil.KubeVersion
APIVersions releaseutil.VersionSet
// Used by helm template to render charts with .Release.IsUpgrade. Ignored if Dry-Run is false
IsUpgrade bool
// Enable DNS lookups when rendering templates
@ -249,7 +248,7 @@ func (i *Install) RunWithContext(ctx context.Context, chrt *chart.Chart, vals ma
return nil, errors.Wrap(err, "release name check failed")
}
if err := chartutil.ProcessDependencies(chrt, vals); err != nil {
if err := releaseutil.ProcessDependencies(chrt, vals); err != nil {
i.cfg.Log(fmt.Sprintf("ERROR: Processing chart dependencies failed: %v", err))
return nil, errors.Wrap(err, "chart dependencies processing failed")
}
@ -273,7 +272,7 @@ func (i *Install) RunWithContext(ctx context.Context, chrt *chart.Chart, vals ma
if i.ClientOnly {
// Add mock objects in here so it doesn't use Kube API server
// NOTE(bacongobbler): used for `helm template`
i.cfg.Capabilities = chartutil.DefaultCapabilities.Copy()
i.cfg.Capabilities = releaseutil.DefaultCapabilities.Copy()
if i.KubeVersion != nil {
i.cfg.Capabilities.KubeVersion = *i.KubeVersion
}
@ -298,14 +297,14 @@ func (i *Install) RunWithContext(ctx context.Context, chrt *chart.Chart, vals ma
// special case for helm template --is-upgrade
isUpgrade := i.IsUpgrade && i.isDryRun()
options := chartutil.ReleaseOptions{
options := releaseutil.ReleaseOptions{
Name: i.ReleaseName,
Namespace: i.Namespace,
Revision: 1,
IsInstall: !isUpgrade,
IsUpgrade: isUpgrade,
}
valuesToRender, err := chartutil.ToRenderValuesWithSchemaValidation(chrt, vals, options, caps, i.SkipSchemaValidation)
valuesToRender, err := releaseutil.ToRenderValuesWithSchemaValidation(chrt, vals, options, caps, i.SkipSchemaValidation)
if err != nil {
return nil, err
}
@ -530,7 +529,7 @@ func (i *Install) failRelease(rel *release.Release, err error) (*release.Release
func (i *Install) availableName() error {
start := i.ReleaseName
if err := chartutil.ValidateReleaseName(start); err != nil {
if err := releaseutil.ValidateReleaseName(start); err != nil {
return errors.Wrapf(err, "release name %q", start)
}
// On dry run, bail here

@ -33,9 +33,9 @@ import (
"helm.sh/helm/v4/internal/test"
"helm.sh/helm/v4/pkg/chart"
"helm.sh/helm/v4/pkg/chartutil"
kubefake "helm.sh/helm/v4/pkg/kube/fake"
"helm.sh/helm/v4/pkg/release"
"helm.sh/helm/v4/pkg/releaseutil"
"helm.sh/helm/v4/pkg/storage/driver"
helmtime "helm.sh/helm/v4/pkg/time"
)
@ -132,7 +132,7 @@ func TestInstallReleaseClientOnly(t *testing.T) {
instAction.ClientOnly = true
instAction.Run(buildChart(), nil) // disregard output
is.Equal(instAction.cfg.Capabilities, chartutil.DefaultCapabilities)
is.Equal(instAction.cfg.Capabilities, releaseutil.DefaultCapabilities)
is.Equal(instAction.cfg.KubeClient, &kubefake.PrintingKubeClient{Out: io.Discard})
}

@ -26,6 +26,7 @@ import (
"helm.sh/helm/v4/pkg/chartutil"
"helm.sh/helm/v4/pkg/lint"
"helm.sh/helm/v4/pkg/lint/support"
"helm.sh/helm/v4/pkg/releaseutil"
)
// Lint is the action for checking that the semantics of a chart are well-formed.
@ -37,7 +38,7 @@ type Lint struct {
WithSubcharts bool
Quiet bool
SkipSchemaValidation bool
KubeVersion *chartutil.KubeVersion
KubeVersion *releaseutil.KubeVersion
}
// LintResult is the result of Lint
@ -87,7 +88,7 @@ func HasWarningsOrErrors(result *LintResult) bool {
return len(result.Errors) > 0
}
func lintChart(path string, vals map[string]interface{}, namespace string, kubeVersion *chartutil.KubeVersion, skipSchemaValidation bool) (support.Linter, error) {
func lintChart(path string, vals map[string]interface{}, namespace string, kubeVersion *releaseutil.KubeVersion, skipSchemaValidation bool) (support.Linter, error) {
var chartPath string
linter := support.Linter{}

@ -26,8 +26,8 @@ import (
"github.com/pkg/errors"
v1 "k8s.io/api/core/v1"
"helm.sh/helm/v4/pkg/chartutil"
"helm.sh/helm/v4/pkg/release"
"helm.sh/helm/v4/pkg/releaseutil"
)
const (
@ -61,7 +61,7 @@ func (r *ReleaseTesting) Run(name string) (*release.Release, error) {
return nil, err
}
if err := chartutil.ValidateReleaseName(name); err != nil {
if err := releaseutil.ValidateReleaseName(name); err != nil {
return nil, errors.Errorf("releaseTest: Release name is invalid: %s", name)
}

@ -24,8 +24,8 @@ import (
"github.com/pkg/errors"
"helm.sh/helm/v4/pkg/chartutil"
"helm.sh/helm/v4/pkg/release"
"helm.sh/helm/v4/pkg/releaseutil"
helmtime "helm.sh/helm/v4/pkg/time"
)
@ -92,7 +92,7 @@ func (r *Rollback) Run(name string) error {
// prepareRollback finds the previous release and prepares a new release object with
// the previous release's configuration
func (r *Rollback) prepareRollback(name string) (*release.Release, *release.Release, error) {
if err := chartutil.ValidateReleaseName(name); err != nil {
if err := releaseutil.ValidateReleaseName(name); err != nil {
return nil, nil, errors.Errorf("prepareRollback: Release name is invalid: %s", name)
}

@ -24,7 +24,6 @@ import (
v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"helm.sh/helm/v4/pkg/chartutil"
"helm.sh/helm/v4/pkg/kube"
"helm.sh/helm/v4/pkg/release"
"helm.sh/helm/v4/pkg/releaseutil"
@ -69,7 +68,7 @@ func (u *Uninstall) Run(name string) (*release.UninstallReleaseResponse, error)
return &release.UninstallReleaseResponse{Release: r}, nil
}
if err := chartutil.ValidateReleaseName(name); err != nil {
if err := releaseutil.ValidateReleaseName(name); err != nil {
return nil, errors.Errorf("uninstall: Release name is invalid: %s", name)
}

@ -29,7 +29,6 @@ import (
"k8s.io/cli-runtime/pkg/resource"
"helm.sh/helm/v4/pkg/chart"
"helm.sh/helm/v4/pkg/chartutil"
"helm.sh/helm/v4/pkg/kube"
"helm.sh/helm/v4/pkg/postrender"
"helm.sh/helm/v4/pkg/registry"
@ -157,7 +156,7 @@ func (u *Upgrade) RunWithContext(ctx context.Context, name string, chart *chart.
// the user doesn't have to specify both
u.Wait = u.Wait || u.Atomic
if err := chartutil.ValidateReleaseName(name); err != nil {
if err := releaseutil.ValidateReleaseName(name); err != nil {
return nil, errors.Errorf("release name is invalid: %s", name)
}
@ -243,7 +242,7 @@ func (u *Upgrade) prepareUpgrade(name string, chart *chart.Chart, vals map[strin
return nil, nil, err
}
if err := chartutil.ProcessDependencies(chart, vals); err != nil {
if err := releaseutil.ProcessDependencies(chart, vals); err != nil {
return nil, nil, err
}
@ -251,7 +250,7 @@ func (u *Upgrade) prepareUpgrade(name string, chart *chart.Chart, vals map[strin
// the release object.
revision := lastRelease.Version + 1
options := chartutil.ReleaseOptions{
options := releaseutil.ReleaseOptions{
Name: name,
Namespace: currentRelease.Namespace,
Revision: revision,
@ -262,7 +261,7 @@ func (u *Upgrade) prepareUpgrade(name string, chart *chart.Chart, vals map[strin
if err != nil {
return nil, nil, err
}
valuesToRender, err := chartutil.ToRenderValuesWithSchemaValidation(chart, vals, options, caps, u.SkipSchemaValidation)
valuesToRender, err := releaseutil.ToRenderValuesWithSchemaValidation(chart, vals, options, caps, u.SkipSchemaValidation)
if err != nil {
return nil, nil, err
}
@ -561,12 +560,12 @@ func (u *Upgrade) reuseValues(chart *chart.Chart, current *release.Release, newV
u.cfg.Log("reusing the old release's values")
// We have to regenerate the old coalesced values:
oldVals, err := chartutil.CoalesceValues(current.Chart, current.Config)
oldVals, err := releaseutil.CoalesceValues(current.Chart, current.Config)
if err != nil {
return nil, errors.Wrap(err, "failed to rebuild old values")
}
newVals = chartutil.CoalesceTables(newVals, current.Config)
newVals = releaseutil.CoalesceTables(newVals, current.Config)
chart.Values = oldVals
@ -577,7 +576,7 @@ func (u *Upgrade) reuseValues(chart *chart.Chart, current *release.Release, newV
if u.ResetThenReuseValues {
u.cfg.Log("merging values from old release to new values")
newVals = chartutil.CoalesceTables(newVals, current.Config)
newVals = releaseutil.CoalesceTables(newVals, current.Config)
return newVals, nil
}

@ -30,7 +30,7 @@ import (
"k8s.io/client-go/rest"
"helm.sh/helm/v4/pkg/chart"
"helm.sh/helm/v4/pkg/chartutil"
"helm.sh/helm/v4/pkg/releaseutil"
)
// Engine is an implementation of the Helm rendering implementation for templates.
@ -73,21 +73,21 @@ func New(config *rest.Config) Engine {
// that section of the values will be passed into the "foo" chart. And if that
// section contains a value named "bar", that value will be passed on to the
// bar chart during render time.
func (e Engine) Render(chrt *chart.Chart, values chartutil.Values) (map[string]string, error) {
func (e Engine) Render(chrt *chart.Chart, values releaseutil.Values) (map[string]string, error) {
tmap := allTemplates(chrt, values)
return e.render(tmap)
}
// Render takes a chart, optional values, and value overrides, and attempts to
// render the Go templates using the default options.
func Render(chrt *chart.Chart, values chartutil.Values) (map[string]string, error) {
func Render(chrt *chart.Chart, values releaseutil.Values) (map[string]string, error) {
return new(Engine).Render(chrt, values)
}
// RenderWithClient takes a chart, optional values, and value overrides, and attempts to
// render the Go templates using the default options. This engine is client aware and so can have template
// functions that interact with the client.
func RenderWithClient(chrt *chart.Chart, values chartutil.Values, config *rest.Config) (map[string]string, error) {
func RenderWithClient(chrt *chart.Chart, values releaseutil.Values, config *rest.Config) (map[string]string, error) {
var clientProvider ClientProvider = clientProviderFromConfig{config}
return Engine{
clientProvider: &clientProvider,
@ -98,7 +98,7 @@ func RenderWithClient(chrt *chart.Chart, values chartutil.Values, config *rest.C
// render the Go templates using the default options. This engine is client aware and so can have template
// functions that interact with the client.
// This function differs from RenderWithClient in that it lets you customize the way a dynamic client is constructed.
func RenderWithClientProvider(chrt *chart.Chart, values chartutil.Values, clientProvider ClientProvider) (map[string]string, error) {
func RenderWithClientProvider(chrt *chart.Chart, values releaseutil.Values, clientProvider ClientProvider) (map[string]string, error) {
return Engine{
clientProvider: &clientProvider,
}.Render(chrt, values)
@ -109,7 +109,7 @@ type renderable struct {
// tpl is the current template.
tpl string
// vals are the values to be supplied to the template.
vals chartutil.Values
vals releaseutil.Values
// namespace prefix to the templates of the current chart
basePath string
}
@ -292,7 +292,7 @@ func (e Engine) render(tpls map[string]renderable) (rendered map[string]string,
}
// At render time, add information about the template that is being rendered.
vals := tpls[filename].vals
vals["Template"] = chartutil.Values{"Name": filename, "BasePath": tpls[filename].basePath}
vals["Template"] = releaseutil.Values{"Name": filename, "BasePath": tpls[filename].basePath}
var buf strings.Builder
if err := t.ExecuteTemplate(&buf, filename, vals); err != nil {
return map[string]string{}, cleanupExecError(filename, err)
@ -371,7 +371,7 @@ func (p byPathLen) Less(i, j int) bool {
// allTemplates returns all templates for a chart and its dependencies.
//
// As it goes, it also prepares the values in a scope-sensitive manner.
func allTemplates(c *chart.Chart, vals chartutil.Values) map[string]renderable {
func allTemplates(c *chart.Chart, vals releaseutil.Values) map[string]renderable {
templates := make(map[string]renderable)
recAllTpls(c, templates, vals)
return templates
@ -381,7 +381,7 @@ func allTemplates(c *chart.Chart, vals chartutil.Values) map[string]renderable {
//
// As it recurses, it also sets the values to be appropriate for the template
// scope.
func recAllTpls(c *chart.Chart, templates map[string]renderable, vals chartutil.Values) map[string]interface{} {
func recAllTpls(c *chart.Chart, templates map[string]renderable, vals releaseutil.Values) map[string]interface{} {
subCharts := make(map[string]interface{})
chartMetaData := struct {
chart.Metadata
@ -393,7 +393,7 @@ func recAllTpls(c *chart.Chart, templates map[string]renderable, vals chartutil.
"Files": newFiles(c.Files),
"Release": vals["Release"],
"Capabilities": vals["Capabilities"],
"Values": make(chartutil.Values),
"Values": make(releaseutil.Values),
"Subcharts": subCharts,
}

@ -31,7 +31,7 @@ import (
"k8s.io/client-go/dynamic/fake"
"helm.sh/helm/v4/pkg/chart"
"helm.sh/helm/v4/pkg/chartutil"
"helm.sh/helm/v4/pkg/releaseutil"
)
func TestSortTemplates(t *testing.T) {
@ -112,7 +112,7 @@ func TestRender(t *testing.T) {
},
}
v, err := chartutil.CoalesceValues(c, vals)
v, err := releaseutil.CoalesceValues(c, vals)
if err != nil {
t.Fatalf("Failed to coalesce values: %s", err)
}
@ -163,7 +163,7 @@ func TestRenderRefsOrdering(t *testing.T) {
}
for i := 0; i < 100; i++ {
out, err := Render(parentChart, chartutil.Values{})
out, err := Render(parentChart, releaseutil.Values{})
if err != nil {
t.Fatalf("Failed to render templates: %s", err)
}
@ -179,7 +179,7 @@ func TestRenderRefsOrdering(t *testing.T) {
func TestRenderInternals(t *testing.T) {
// Test the internals of the rendering tool.
vals := chartutil.Values{"Name": "one", "Value": "two"}
vals := releaseutil.Values{"Name": "one", "Value": "two"}
tpls := map[string]renderable{
"one": {tpl: `Hello {{title .Name}}`, vals: vals},
"two": {tpl: `Goodbye {{upper .Value}}`, vals: vals},
@ -226,7 +226,7 @@ func TestRenderWithDNS(t *testing.T) {
"Values": map[string]interface{}{},
}
v, err := chartutil.CoalesceValues(c, vals)
v, err := releaseutil.CoalesceValues(c, vals)
if err != nil {
t.Fatalf("Failed to coalesce values: %s", err)
}
@ -363,7 +363,7 @@ func TestRenderWithClientProvider(t *testing.T) {
"Values": map[string]interface{}{},
}
v, err := chartutil.CoalesceValues(c, vals)
v, err := releaseutil.CoalesceValues(c, vals)
if err != nil {
t.Fatalf("Failed to coalesce values: %s", err)
}
@ -399,7 +399,7 @@ func TestRenderWithClientProvider_error(t *testing.T) {
"Values": map[string]interface{}{},
}
v, err := chartutil.CoalesceValues(c, vals)
v, err := releaseutil.CoalesceValues(c, vals)
if err != nil {
t.Fatalf("Failed to coalesce values: %s", err)
}
@ -446,7 +446,7 @@ func TestParallelRenderInternals(t *testing.T) {
}
func TestParseErrors(t *testing.T) {
vals := chartutil.Values{"Values": map[string]interface{}{}}
vals := releaseutil.Values{"Values": map[string]interface{}{}}
tplsUndefinedFunction := map[string]renderable{
"undefined_function": {tpl: `{{foo}}`, vals: vals},
@ -462,7 +462,7 @@ func TestParseErrors(t *testing.T) {
}
func TestExecErrors(t *testing.T) {
vals := chartutil.Values{"Values": map[string]interface{}{}}
vals := releaseutil.Values{"Values": map[string]interface{}{}}
cases := []struct {
name string
tpls map[string]renderable
@ -526,7 +526,7 @@ linebreak`,
}
func TestFailErrors(t *testing.T) {
vals := chartutil.Values{"Values": map[string]interface{}{}}
vals := releaseutil.Values{"Values": map[string]interface{}{}}
failtpl := `All your base are belong to us{{ fail "This is an error" }}`
tplsFailed := map[string]renderable{
@ -579,7 +579,7 @@ func TestAllTemplates(t *testing.T) {
}
dep1.AddDependency(dep2)
tpls := allTemplates(ch1, chartutil.Values{})
tpls := allTemplates(ch1, releaseutil.Values{})
if len(tpls) != 5 {
t.Errorf("Expected 5 charts, got %d", len(tpls))
}
@ -600,7 +600,7 @@ func TestChartValuesContainsIsRoot(t *testing.T) {
}
ch1.AddDependency(dep1)
out, err := Render(ch1, chartutil.Values{})
out, err := Render(ch1, releaseutil.Values{})
if err != nil {
t.Fatalf("failed to render templates: %s", err)
}
@ -704,15 +704,15 @@ func TestRenderNestedValues(t *testing.T) {
},
}
tmp, err := chartutil.CoalesceValues(outer, injValues)
tmp, err := releaseutil.CoalesceValues(outer, injValues)
if err != nil {
t.Fatalf("Failed to coalesce values: %s", err)
}
inject := chartutil.Values{
inject := releaseutil.Values{
"Values": tmp,
"Chart": outer.Metadata,
"Release": chartutil.Values{
"Release": releaseutil.Values{
"Name": "dyin",
},
}
@ -772,10 +772,10 @@ func TestRenderBuiltinValues(t *testing.T) {
}
outer.AddDependency(inner)
inject := chartutil.Values{
inject := releaseutil.Values{
"Values": "",
"Chart": outer.Metadata,
"Release": chartutil.Values{
"Release": releaseutil.Values{
"Name": "Aeneid",
},
}
@ -819,10 +819,10 @@ func TestAlterFuncMap_include(t *testing.T) {
},
}
v := chartutil.Values{
v := releaseutil.Values{
"Values": "",
"Chart": c.Metadata,
"Release": chartutil.Values{
"Release": releaseutil.Values{
"Name": "Mistah Kurtz",
},
}
@ -853,13 +853,13 @@ func TestAlterFuncMap_require(t *testing.T) {
},
}
v := chartutil.Values{
"Values": chartutil.Values{
v := releaseutil.Values{
"Values": releaseutil.Values{
"who": "us",
"bases": 2,
},
"Chart": c.Metadata,
"Release": chartutil.Values{
"Release": releaseutil.Values{
"Name": "That 90s meme",
},
}
@ -880,12 +880,12 @@ func TestAlterFuncMap_require(t *testing.T) {
// test required without passing in needed values with lint mode on
// verifies lint replaces required with an empty string (should not fail)
lintValues := chartutil.Values{
"Values": chartutil.Values{
lintValues := releaseutil.Values{
"Values": releaseutil.Values{
"who": "us",
},
"Chart": c.Metadata,
"Release": chartutil.Values{
"Release": releaseutil.Values{
"Name": "That 90s meme",
},
}
@ -914,12 +914,12 @@ func TestAlterFuncMap_tpl(t *testing.T) {
},
}
v := chartutil.Values{
"Values": chartutil.Values{
v := releaseutil.Values{
"Values": releaseutil.Values{
"value": "myvalue",
},
"Chart": c.Metadata,
"Release": chartutil.Values{
"Release": releaseutil.Values{
"Name": "TestRelease",
},
}
@ -943,12 +943,12 @@ func TestAlterFuncMap_tplfunc(t *testing.T) {
},
}
v := chartutil.Values{
"Values": chartutil.Values{
v := releaseutil.Values{
"Values": releaseutil.Values{
"value": "myvalue",
},
"Chart": c.Metadata,
"Release": chartutil.Values{
"Release": releaseutil.Values{
"Name": "TestRelease",
},
}
@ -972,12 +972,12 @@ func TestAlterFuncMap_tplinclude(t *testing.T) {
{Name: "templates/_partial", Data: []byte(`{{.Template.Name}}`)},
},
}
v := chartutil.Values{
"Values": chartutil.Values{
v := releaseutil.Values{
"Values": releaseutil.Values{
"value": "myvalue",
},
"Chart": c.Metadata,
"Release": chartutil.Values{
"Release": releaseutil.Values{
"Name": "TestRelease",
},
}
@ -1003,10 +1003,10 @@ func TestRenderRecursionLimit(t *testing.T) {
{Name: "templates/recursion", Data: []byte(`{{define "recursion"}}{{include "recursion" . }}{{end}}`)},
},
}
v := chartutil.Values{
v := releaseutil.Values{
"Values": "",
"Chart": c.Metadata,
"Release": chartutil.Values{
"Release": releaseutil.Values{
"Name": "TestRelease",
},
}
@ -1062,13 +1062,13 @@ func TestRenderLoadTemplateForTplFromFile(t *testing.T) {
},
}
v := chartutil.Values{
"Values": chartutil.Values{
v := releaseutil.Values{
"Values": releaseutil.Values{
"filename": "test",
"filename2": "test2",
},
"Chart": c.Metadata,
"Release": chartutil.Values{
"Release": releaseutil.Values{
"Name": "TestRelease",
},
}
@ -1093,9 +1093,9 @@ func TestRenderTplEmpty(t *testing.T) {
{Name: "templates/only-defines", Data: []byte(`{{tpl "{{define \"not-invoked\"}}not-rendered{{end}}" .}}`)},
},
}
v := chartutil.Values{
v := releaseutil.Values{
"Chart": c.Metadata,
"Release": chartutil.Values{
"Release": releaseutil.Values{
"Name": "TestRelease",
},
}
@ -1129,10 +1129,10 @@ func TestRenderTplTemplateNames(t *testing.T) {
{Name: "templates/modified-field", Data: []byte(`{{tpl "{{ .Template.Field }}" .Values.dot}}`)},
},
}
v := chartutil.Values{
"Values": chartutil.Values{
"dot": chartutil.Values{
"Template": chartutil.Values{
v := releaseutil.Values{
"Values": releaseutil.Values{
"dot": releaseutil.Values{
"Template": releaseutil.Values{
"BasePath": "path/to/template",
"Name": "name-of-template",
"Field": "extra-field",
@ -1140,7 +1140,7 @@ func TestRenderTplTemplateNames(t *testing.T) {
},
},
"Chart": c.Metadata,
"Release": chartutil.Values{
"Release": releaseutil.Values{
"Name": "TestRelease",
},
}
@ -1190,8 +1190,8 @@ func TestRenderTplRedefines(t *testing.T) {
)},
},
}
v := chartutil.Values{
"Values": chartutil.Values{
v := releaseutil.Values{
"Values": releaseutil.Values{
"partialText": `{{define "partial"}}redefined-in-tpl{{end}}tpl: {{include "partial" .}}`,
"manifestText": `{{define "manifest"}}redefined-in-tpl{{end}}tpl: {{include "manifest" .}}`,
"manifestOnlyText": `tpl: {{include "manifest-only" .}}`,
@ -1203,7 +1203,7 @@ func TestRenderTplRedefines(t *testing.T) {
"innerText": `{{define "nested"}}redefined-in-inner-tpl{{end}}inner-tpl: {{include "nested" .}} {{include "nested-outer" . }}`,
},
"Chart": c.Metadata,
"Release": chartutil.Values{
"Release": releaseutil.Values{
"Name": "TestRelease",
},
}
@ -1240,10 +1240,10 @@ func TestRenderTplMissingKey(t *testing.T) {
)},
},
}
v := chartutil.Values{
"Values": chartutil.Values{},
v := releaseutil.Values{
"Values": releaseutil.Values{},
"Chart": c.Metadata,
"Release": chartutil.Values{
"Release": releaseutil.Values{
"Name": "TestRelease",
},
}
@ -1273,10 +1273,10 @@ func TestRenderTplMissingKeyString(t *testing.T) {
)},
},
}
v := chartutil.Values{
"Values": chartutil.Values{},
v := releaseutil.Values{
"Values": releaseutil.Values{},
"Chart": c.Metadata,
"Release": chartutil.Values{
"Release": releaseutil.Values{
"Name": "TestRelease",
},
}

@ -19,19 +19,19 @@ package lint // import "helm.sh/helm/v4/pkg/lint"
import (
"path/filepath"
"helm.sh/helm/v4/pkg/chartutil"
"helm.sh/helm/v4/pkg/lint/rules"
"helm.sh/helm/v4/pkg/lint/support"
"helm.sh/helm/v4/pkg/releaseutil"
)
type linterOptions struct {
KubeVersion *chartutil.KubeVersion
KubeVersion *releaseutil.KubeVersion
SkipSchemaValidation bool
}
type LinterOption func(lo *linterOptions)
func WithKubeVersion(kubeVersion *chartutil.KubeVersion) LinterOption {
func WithKubeVersion(kubeVersion *releaseutil.KubeVersion) LinterOption {
return func(lo *linterOptions) {
lo.KubeVersion = kubeVersion
}

@ -20,12 +20,11 @@ import (
"fmt"
"strconv"
"helm.sh/helm/v4/pkg/releaseutil"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/runtime/schema"
"k8s.io/apiserver/pkg/endpoints/deprecation"
kscheme "k8s.io/client-go/kubernetes/scheme"
"helm.sh/helm/v4/pkg/chartutil"
)
var (
@ -47,7 +46,7 @@ func (e deprecatedAPIError) Error() string {
return msg
}
func validateNoDeprecations(resource *K8sYamlStruct, kubeVersion *chartutil.KubeVersion) error {
func validateNoDeprecations(resource *K8sYamlStruct, kubeVersion *releaseutil.KubeVersion) error {
// if `resource` does not have an APIVersion or Kind, we cannot test it for deprecation
if resource.APIVersion == "" {
return nil

@ -34,9 +34,9 @@ import (
"k8s.io/apimachinery/pkg/util/yaml"
"helm.sh/helm/v4/pkg/chart/loader"
"helm.sh/helm/v4/pkg/chartutil"
"helm.sh/helm/v4/pkg/engine"
"helm.sh/helm/v4/pkg/lint/support"
"helm.sh/helm/v4/pkg/releaseutil"
)
var (
@ -50,12 +50,12 @@ func Templates(linter *support.Linter, values map[string]interface{}, namespace
}
// TemplatesWithKubeVersion lints the templates in the Linter, allowing to specify the kubernetes version.
func TemplatesWithKubeVersion(linter *support.Linter, values map[string]interface{}, namespace string, kubeVersion *chartutil.KubeVersion) {
func TemplatesWithKubeVersion(linter *support.Linter, values map[string]interface{}, namespace string, kubeVersion *releaseutil.KubeVersion) {
TemplatesWithSkipSchemaValidation(linter, values, namespace, kubeVersion, false)
}
// TemplatesWithSkipSchemaValidation lints the templates in the Linter, allowing to specify the kubernetes version and if schema validation is enabled or not.
func TemplatesWithSkipSchemaValidation(linter *support.Linter, values map[string]interface{}, namespace string, kubeVersion *chartutil.KubeVersion, skipSchemaValidation bool) {
func TemplatesWithSkipSchemaValidation(linter *support.Linter, values map[string]interface{}, namespace string, kubeVersion *releaseutil.KubeVersion, skipSchemaValidation bool) {
fpath := "templates/"
templatesPath := filepath.Join(linter.ChartDir, fpath)
@ -75,28 +75,28 @@ func TemplatesWithSkipSchemaValidation(linter *support.Linter, values map[string
return
}
options := chartutil.ReleaseOptions{
options := releaseutil.ReleaseOptions{
Name: "test-release",
Namespace: namespace,
}
caps := chartutil.DefaultCapabilities.Copy()
caps := releaseutil.DefaultCapabilities.Copy()
if kubeVersion != nil {
caps.KubeVersion = *kubeVersion
}
// lint ignores import-values
// See https://github.com/helm/helm/issues/9658
if err := chartutil.ProcessDependencies(chart, values); err != nil {
if err := releaseutil.ProcessDependencies(chart, values); err != nil {
return
}
cvals, err := chartutil.CoalesceValues(chart, values)
cvals, err := releaseutil.CoalesceValues(chart, values)
if err != nil {
return
}
valuesToRender, err := chartutil.ToRenderValuesWithSchemaValidation(chart, cvals, options, caps, skipSchemaValidation)
valuesToRender, err := releaseutil.ToRenderValuesWithSchemaValidation(chart, cvals, options, caps, skipSchemaValidation)
if err != nil {
linter.RunLinterRule(support.ErrorSev, fpath, err)
return

@ -22,8 +22,8 @@ import (
"github.com/pkg/errors"
"helm.sh/helm/v4/pkg/chartutil"
"helm.sh/helm/v4/pkg/lint/support"
"helm.sh/helm/v4/pkg/releaseutil"
)
// ValuesWithOverrides tests the values.yaml file.
@ -53,7 +53,7 @@ func validateValuesFileExistence(valuesPath string) error {
}
func validateValuesFile(valuesPath string, overrides map[string]interface{}) error {
values, err := chartutil.ReadValuesFile(valuesPath)
values, err := releaseutil.ReadValuesFile(valuesPath)
if err != nil {
return errors.Wrap(err, "unable to parse YAML")
}
@ -63,8 +63,8 @@ func validateValuesFile(valuesPath string, overrides map[string]interface{}) err
// We could change that. For now, though, we retain that strategy, and thus can
// coalesce tables (like reuse-values does) instead of doing the full chart
// CoalesceValues
coalescedValues := chartutil.CoalesceTables(make(map[string]interface{}, len(overrides)), overrides)
coalescedValues = chartutil.CoalesceTables(coalescedValues, values)
coalescedValues := releaseutil.CoalesceTables(make(map[string]interface{}, len(overrides)), overrides)
coalescedValues = releaseutil.CoalesceTables(coalescedValues, values)
ext := filepath.Ext(valuesPath)
schemaPath := valuesPath[:len(valuesPath)-len(ext)] + ".schema.json"
@ -75,5 +75,5 @@ func validateValuesFile(valuesPath string, overrides map[string]interface{}) err
if err != nil {
return err
}
return chartutil.ValidateAgainstSingleSchema(coalescedValues, schema)
return releaseutil.ValidateAgainstSingleSchema(coalescedValues, schema)
}

@ -13,7 +13,7 @@ See the License for the specific language governing permissions and
limitations under the License.
*/
package chartutil
package releaseutil
import (
"fmt"

@ -13,7 +13,7 @@ See the License for the specific language governing permissions and
limitations under the License.
*/
package chartutil
package releaseutil
import (
"testing"

@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
limitations under the License.
*/
package chartutil
package releaseutil
import (
"fmt"

@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
limitations under the License.
*/
package chartutil
package releaseutil
import (
"encoding/json"

@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
limitations under the License.
*/
package chartutil
package releaseutil
import "github.com/Masterminds/semver/v3"

@ -15,7 +15,7 @@ limitations under the License.
*/
// Package version represents the current version of the project.
package chartutil
package releaseutil
import "testing"

@ -13,7 +13,7 @@ See the License for the specific language governing permissions and
limitations under the License.
*/
package chartutil
package releaseutil
import (
"log"

@ -12,7 +12,7 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package chartutil
package releaseutil
import (
"encoding/json"

@ -0,0 +1,35 @@
/*
Copyright The Helm Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package releaseutil
import (
"fmt"
)
// ErrNoTable indicates that a chart does not have a matching table.
type ErrNoTable struct {
Key string
}
func (e ErrNoTable) Error() string { return fmt.Sprintf("%q is not a table", e.Key) }
// ErrNoValue indicates that Values does not contain a key with a value
type ErrNoValue struct {
Key string
}
func (e ErrNoValue) Error() string { return fmt.Sprintf("%q is not a value", e.Key) }

@ -0,0 +1,37 @@
/*
Copyright The Helm Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package releaseutil
import (
"testing"
)
func TestErrorNoTableDoesNotPanic(t *testing.T) {
x := "empty"
y := ErrNoTable{x}
t.Logf("error is: %s", y)
}
func TestErrorNoValueDoesNotPanic(t *testing.T) {
x := "empty"
y := ErrNoValue{x}
t.Logf("error is: %s", y)
}

@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
limitations under the License.
*/
package chartutil
package releaseutil
import (
"bytes"

@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
limitations under the License.
*/
package chartutil
package releaseutil
import (
"os"

@ -26,7 +26,6 @@ import (
"github.com/pkg/errors"
"sigs.k8s.io/yaml"
"helm.sh/helm/v4/pkg/chartutil"
"helm.sh/helm/v4/pkg/release"
)
@ -74,7 +73,7 @@ var events = map[string]release.HookEvent{
//
// Files that do not parse into the expected format are simply placed into a map and
// returned.
func SortManifests(files map[string]string, _ chartutil.VersionSet, ordering KindSortOrder) ([]*release.Hook, []Manifest, error) {
func SortManifests(files map[string]string, _ VersionSet, ordering KindSortOrder) ([]*release.Hook, []Manifest, error) {
result := &result{}
var sortedFilePaths []string

Before

Width:  |  Height:  |  Size: 374 B

After

Width:  |  Height:  |  Size: 374 B

Some files were not shown because too many files have changed in this diff Show More

Loading…
Cancel
Save