chartutil

package
v3.16.3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 11, 2024 License: Apache-2.0 Imports: 25 Imported by: 415

Documentation

Overview

Package chartutil contains tools for working with charts.

Charts are described in the chart package (pkg/chart). This package provides utilities for serializing and deserializing charts.

A chart can be represented on the file system in one of two ways:

  • As a directory that contains a Chart.yaml file and other chart things.
  • As a tarred gzipped file containing a directory that then contains a Chart.yaml file.

This package provides utilities for working with those file formats.

The preferred way of loading a chart is using 'loader.Load`:

chart, err := loader.Load(filename)

This will attempt to discover whether the file at 'filename' is a directory or a chart archive. It will then load accordingly.

For accepting raw compressed tar file data from an io.Reader, the 'loader.LoadArchive()' will read in the data, uncompress it, and unpack it into a Chart.

When creating charts in memory, use the 'helm.sh/helm/pkg/chart' package directly.

Index

Examples

Constants

View Source
const (
	// ChartfileName is the default Chart file name.
	ChartfileName = "Chart.yaml"
	// ValuesfileName is the default values file name.
	ValuesfileName = "values.yaml"
	// SchemafileName is the default values schema file name.
	SchemafileName = "values.schema.json"
	// TemplatesDir is the relative directory name for templates.
	TemplatesDir = "templates"
	// ChartsDir is the relative directory name for charts dependencies.
	ChartsDir = "charts"
	// TemplatesTestsDir is the relative directory name for tests.
	TemplatesTestsDir = TemplatesDir + sep + "tests"
	// IgnorefileName is the name of the Helm ignore file.
	IgnorefileName = ".helmignore"
	// IngressFileName is the name of the example ingress file.
	IngressFileName = TemplatesDir + sep + "ingress.yaml"
	// DeploymentName is the name of the example deployment file.
	DeploymentName = TemplatesDir + sep + "deployment.yaml"
	// ServiceName is the name of the example service file.
	ServiceName = TemplatesDir + sep + "service.yaml"
	// ServiceAccountName is the name of the example serviceaccount file.
	ServiceAccountName = TemplatesDir + sep + "serviceaccount.yaml"
	// HorizontalPodAutoscalerName is the name of the example hpa file.
	HorizontalPodAutoscalerName = TemplatesDir + sep + "hpa.yaml"
	// NotesName is the name of the example NOTES.txt file.
	NotesName = TemplatesDir + sep + "NOTES.txt"
	// HelpersName is the name of the example helpers file.
	HelpersName = TemplatesDir + sep + "_helpers.tpl"
	// TestConnectionName is the name of the example test file.
	TestConnectionName = TemplatesTestsDir + sep + "test-connection.yaml"
)
View Source
const GlobalKey = "global"

GlobalKey is the name of the Values key that is used for storing global vars.

Variables

View Source
var (

	// DefaultVersionSet is the default version set, which includes only Core V1 ("v1").
	DefaultVersionSet = allKnownVersions()

	// DefaultCapabilities is the default set of capabilities.
	DefaultCapabilities = &Capabilities{
		KubeVersion: KubeVersion{
			Version: fmt.Sprintf("v%s.%s.0", k8sVersionMajor, k8sVersionMinor),
			Major:   k8sVersionMajor,
			Minor:   k8sVersionMinor,
		},
		APIVersions: DefaultVersionSet,
		HelmVersion: helmversion.Get(),
	}
)
View Source
var Stderr io.Writer = os.Stderr

Stderr is an io.Writer to which error messages can be written

In Helm 4, this will be replaced. It is needed in Helm 3 to preserve API backward compatibility.

Functions

func CoalesceTables

func CoalesceTables(dst, src map[string]interface{}) map[string]interface{}

CoalesceTables merges a source map into a destination map.

dest is considered authoritative.

func Create

func Create(name, dir string) (string, error)

Create creates a new chart in a directory.

Inside of dir, this will create a directory based on the name of chartfile.Name. It will then write the Chart.yaml into this directory and create the (empty) appropriate directories.

The returned string will point to the newly created directory. It will be an absolute path, even if the provided base directory was relative.

If dir does not exist, this will return an error. If Chart.yaml or any directories cannot be created, this will return an error. In such a case, this will attempt to clean up by removing the new chart directory.

func CreateFrom

func CreateFrom(chartfile *chart.Metadata, dest, src string) error

CreateFrom creates a new chart, but scaffolds it from the src chart.

func Expand

func Expand(dir string, r io.Reader) error

Expand uncompresses and extracts a chart into the specified directory.

func ExpandFile

func ExpandFile(dest, src string) error

ExpandFile expands the src file into the dest directory.

func IsChartDir

func IsChartDir(dirName string) (bool, error)

IsChartDir validate a chart directory.

Checks for a valid Chart.yaml.

func IsCompatibleRange

func IsCompatibleRange(constraint, ver string) bool

IsCompatibleRange compares a version to a constraint. It returns true if the version matches the constraint, and false in all other cases.

func LoadChartfile

func LoadChartfile(filename string) (*chart.Metadata, error)

LoadChartfile loads a Chart.yaml file into a *chart.Metadata.

func MergeTables added in v3.13.0

func MergeTables(dst, src map[string]interface{}) map[string]interface{}

func ProcessDependencies

func ProcessDependencies(c *chart.Chart, v Values) error

ProcessDependencies checks through this chart's dependencies, processing accordingly.

TODO: For Helm v4 this can be combined with or turned into ProcessDependenciesWithMerge

func ProcessDependenciesWithMerge added in v3.13.0

func ProcessDependenciesWithMerge(c *chart.Chart, v Values) error

ProcessDependenciesWithMerge checks through this chart's dependencies, processing accordingly. It is similar to ProcessDependencies but it does not remove nil values during the import/export handling process.

func Save

func Save(c *chart.Chart, outDir string) (string, error)

Save creates an archived chart to the given directory.

This takes an existing chart and a destination directory.

If the directory is /foo, and the chart is named bar, with version 1.0.0, this will generate /foo/bar-1.0.0.tgz.

This returns the absolute path to the chart archive file.

func SaveChartfile

func SaveChartfile(filename string, cf *chart.Metadata) error

SaveChartfile saves the given metadata as a Chart.yaml file at the given path.

'filename' should be the complete path and filename ('foo/Chart.yaml')

func SaveDir

func SaveDir(c *chart.Chart, dest string) error

SaveDir saves a chart as files in a directory.

This takes the chart name, and creates a new subdirectory inside of the given dest directory, writing the chart's contents to that subdirectory.

func ValidateAgainstSchema

func ValidateAgainstSchema(chrt *chart.Chart, values map[string]interface{}) error

ValidateAgainstSchema checks that values does not violate the structure laid out in schema

func ValidateAgainstSingleSchema

func ValidateAgainstSingleSchema(values Values, schemaJSON []byte) (reterr error)

ValidateAgainstSingleSchema checks that values does not violate the structure laid out in this schema

func ValidateMetadataName deprecated added in v3.3.2

func ValidateMetadataName(name string) error

ValidateMetadataName validates the name field of a Kubernetes metadata object.

Empty strings, strings longer than 253 chars, or strings that don't match the regexp will fail.

According to the Kubernetes help text, the regular expression it uses is:

[a-z0-9]([-a-z0-9]*[a-z0-9])?(\.[a-z0-9]([-a-z0-9]*[a-z0-9])?)*

This follows the above regular expression (but requires a full string match, not partial).

The Kubernetes documentation is here, though it is not entirely correct: https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#names

Deprecated: remove in Helm 4. Name validation now uses rules defined in pkg/lint/rules.validateMetadataNameFunc()

func ValidateReleaseName added in v3.3.2

func ValidateReleaseName(name string) error

ValidateReleaseName performs checks for an entry for a Helm release name

For Helm to allow a name, it must be below a certain character count (53) and also match a regular expression.

According to the Kubernetes help text, the regular expression it uses is:

[a-z0-9]([-a-z0-9]*[a-z0-9])?(\.[a-z0-9]([-a-z0-9]*[a-z0-9])?)*

This follows the above regular expression (but requires a full string match, not partial).

The Kubernetes documentation is here, though it is not entirely correct: https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#names

Types

type Capabilities

type Capabilities struct {
	// KubeVersion is the Kubernetes version.
	KubeVersion KubeVersion
	// APIVersions are supported Kubernetes API versions.
	APIVersions VersionSet
	// HelmVersion is the build information for this helm version
	HelmVersion helmversion.BuildInfo
}

Capabilities describes the capabilities of the Kubernetes cluster.

func (*Capabilities) Copy added in v3.6.0

func (capabilities *Capabilities) Copy() *Capabilities

type ErrInvalidChartName added in v3.14.1

type ErrInvalidChartName struct {
	Name string
}

func (ErrInvalidChartName) Error added in v3.14.1

func (e ErrInvalidChartName) Error() string

type ErrNoTable

type ErrNoTable struct {
	Key string
}

ErrNoTable indicates that a chart does not have a matching table.

func (ErrNoTable) Error

func (e ErrNoTable) Error() string

type ErrNoValue

type ErrNoValue struct {
	Key string
}

ErrNoValue indicates that Values does not contain a key with a value

func (ErrNoValue) Error

func (e ErrNoValue) Error() string

type KubeVersion

type KubeVersion struct {
	Version string // Kubernetes version
	Major   string // Kubernetes major version
	Minor   string // Kubernetes minor version
}

KubeVersion is the Kubernetes version.

func ParseKubeVersion added in v3.6.0

func ParseKubeVersion(version string) (*KubeVersion, error)

ParseKubeVersion parses kubernetes version from string

func (*KubeVersion) GitVersion deprecated

func (kv *KubeVersion) GitVersion() string

GitVersion returns the Kubernetes version string.

Deprecated: use KubeVersion.Version.

func (*KubeVersion) String

func (kv *KubeVersion) String() string

String implements fmt.Stringer

type ReleaseOptions

type ReleaseOptions struct {
	Name      string
	Namespace string
	Revision  int
	IsUpgrade bool
	IsInstall bool
}

ReleaseOptions represents the additional release options needed for the composition of the final values struct

type Values

type Values map[string]interface{}

Values represents a collection of chart values.

Example
doc := `
title: "Moby Dick"
chapter:
  one:
    title: "Loomings"
  two:
    title: "The Carpet-Bag"
  three:
    title: "The Spouter Inn"
`
d, err := ReadValues([]byte(doc))
if err != nil {
	panic(err)
}
ch1, err := d.Table("chapter.one")
if err != nil {
	panic("could not find chapter one")
}
fmt.Print(ch1["title"])
Output:

Loomings

func CoalesceValues

func CoalesceValues(chrt *chart.Chart, vals map[string]interface{}) (Values, error)

CoalesceValues coalesces all of the values in a chart (and its subcharts).

Values are coalesced together using the following rules:

  • Values in a higher level chart always override values in a lower-level dependency chart
  • Scalar values and arrays are replaced, maps are merged
  • A chart has access to all of the variables for it, as well as all of the values destined for its dependencies.

func MergeValues added in v3.13.0

func MergeValues(chrt *chart.Chart, vals map[string]interface{}) (Values, error)

MergeValues is used to merge the values in a chart and its subcharts. This is different from Coalescing as nil/null values are preserved.

Values are coalesced together using the following rules:

  • Values in a higher level chart always override values in a lower-level dependency chart
  • Scalar values and arrays are replaced, maps are merged
  • A chart has access to all of the variables for it, as well as all of the values destined for its dependencies.

Retaining Nils is useful when processes early in a Helm action or business logic need to retain them for when Coalescing will happen again later in the business logic.

func ReadValues

func ReadValues(data []byte) (vals Values, err error)

ReadValues will parse YAML byte data into a Values.

func ReadValuesFile

func ReadValuesFile(filename string) (Values, error)

ReadValuesFile will parse a YAML file into a map of values.

func ToRenderValues

func ToRenderValues(chrt *chart.Chart, chrtVals map[string]interface{}, options ReleaseOptions, caps *Capabilities) (Values, error)

ToRenderValues composes the struct from the data coming from the Releases, Charts and Values files

This takes both ReleaseOptions and Capabilities to merge into the render values.

func ToRenderValuesWithSchemaValidation added in v3.16.0

func ToRenderValuesWithSchemaValidation(chrt *chart.Chart, chrtVals map[string]interface{}, options ReleaseOptions, caps *Capabilities, skipSchemaValidation bool) (Values, error)

ToRenderValuesWithSchemaValidation composes the struct from the data coming from the Releases, Charts and Values files

This takes both ReleaseOptions and Capabilities to merge into the render values.

func (Values) AsMap

func (v Values) AsMap() map[string]interface{}

AsMap is a utility function for converting Values to a map[string]interface{}.

It protects against nil map panics.

func (Values) Encode

func (v Values) Encode(w io.Writer) error

Encode writes serialized Values information to the given io.Writer.

func (Values) PathValue

func (v Values) PathValue(path string) (interface{}, error)

PathValue takes a path that traverses a YAML structure and returns the value at the end of that path. The path starts at the root of the YAML structure and is comprised of YAML keys separated by periods. Given the following YAML data the value at path "chapter.one.title" is "Loomings".

chapter:
  one:
    title: "Loomings"

func (Values) Table

func (v Values) Table(name string) (Values, error)

Table gets a table (YAML subsection) from a Values object.

The table is returned as a Values.

Compound table names may be specified with dots:

foo.bar

The above will be evaluated as "The table bar inside the table foo".

An ErrNoTable is returned if the table does not exist.

func (Values) YAML

func (v Values) YAML() (string, error)

YAML encodes the Values into a YAML string.

type VersionSet

type VersionSet []string

VersionSet is a set of Kubernetes API versions.

func (VersionSet) Has

func (v VersionSet) Has(apiVersion string) bool

Has returns true if the version string is in the set.

vs.Has("apps/v1")

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL