Documentation ¶
Overview ¶
Package chartutil contains tools for working with charts.
Charts are described in the protocol buffer definition (pkg/proto/hapi/charts). This packe 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 'chartutil.Load`:
chart, err := chartutil.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 'chartutil.LoadArchive()' will read in the data, uncompress it, and unpack it into a Chart.
When creating charts in memory, use the 'k8s.io/helm/pkg/proto/hapi/chart' package directly.
Index ¶
- Constants
- Variables
- func Create(chartfile *chart.Metadata, dir string) (string, error)
- func CreateFrom(chartfile *chart.Metadata, dest string, src string) error
- func Expand(dir string, r io.Reader) error
- func ExpandFile(dest, src string) error
- func FromJson(str string) map[string]interface{}
- func FromYaml(str string) map[string]interface{}
- func IsChartDir(dirName string) (bool, error)
- func Load(name string) (*chart.Chart, error)
- func LoadArchive(in io.Reader) (*chart.Chart, error)
- func LoadChartfile(filename string) (*chart.Metadata, error)
- func LoadDir(dir string) (*chart.Chart, error)
- func LoadFile(name string) (*chart.Chart, error)
- func LoadFiles(files []*BufferedFile) (*chart.Chart, error)
- func ProcessRequirementsConditions(reqs *Requirements, cvals Values)
- func ProcessRequirementsEnabled(c *chart.Chart, v *chart.Config) error
- func ProcessRequirementsImportValues(c *chart.Chart) error
- func ProcessRequirementsTags(reqs *Requirements, cvals Values)
- func Save(c *chart.Chart, outDir string) (string, error)
- func SaveChartfile(filename string, cf *chart.Metadata) error
- func SaveDir(c *chart.Chart, dest string) error
- func ToJson(v interface{}) string
- func ToToml(v interface{}) string
- func ToYaml(v interface{}) string
- func Transform(src string, key string, replacement string) []byte
- func UnmarshalChartfile(data []byte) (*chart.Metadata, error)
- type BufferedFile
- type Capabilities
- type Dependency
- type ErrNoRequirementsFile
- type ErrNoTable
- type ErrNoValue
- type Files
- type ReleaseOptions
- type Requirements
- type RequirementsLock
- type Values
- func CoalesceValues(chrt *chart.Chart, vals *chart.Config) (Values, error)
- func ReadValues(data []byte) (vals Values, err error)
- func ReadValuesFile(filename string) (Values, error)
- func ToRenderValues(chrt *chart.Chart, chrtVals *chart.Config, options ReleaseOptions) (Values, error)
- func ToRenderValuesCaps(chrt *chart.Chart, chrtVals *chart.Config, options ReleaseOptions, ...) (Values, error)
- type VersionSet
Examples ¶
Constants ¶
const ( // ChartfileName is the default Chart file name. ChartfileName = "Chart.yaml" // ValuesfileName is the default values file name. ValuesfileName = "values.yaml" // TemplatesDir is the relative directory name for templates. TemplatesDir = "templates" // ChartsDir is the relative directory name for charts dependencies. ChartsDir = "charts" // IgnorefileName is the name of the Helm ignore file. IgnorefileName = ".helmignore" // IngressFileName is the name of the example ingress file. IngressFileName = "ingress.yaml" // DeploymentName is the name of the example deployment file. DeploymentName = "deployment.yaml" // ServiceName is the name of the example service file. ServiceName = "service.yaml" // NotesName is the name of the example NOTES.txt file. NotesName = "NOTES.txt" // HelpersName is the name of the example helpers file. HelpersName = "_helpers.tpl" // TemplatesTestsDir is the relative directory name for templates tests. TemplatesTestsDir = "templates/tests" // TestConnectionName is the name of the example connection test file. TestConnectionName = "test-connection.yaml" )
const ApiVersionV1 = "v1" // nolint
ApiVersionV1 is the API version number for version 1.
This is ApiVersionV1 instead of APIVersionV1 to match the protobuf-generated name.
const GlobalKey = "global"
GlobalKey is the name of the Values key that is used for storing global vars.
Variables ¶
var ( // DefaultVersionSet is the default version set, which includes only Core V1 ("v1"). DefaultVersionSet = NewVersionSet("v1") // DefaultKubeVersion is the default kubernetes version DefaultKubeVersion = &version.Info{ Major: "1", Minor: "9", GitVersion: "v1.9.0", GoVersion: runtime.Version(), Compiler: runtime.Compiler, Platform: fmt.Sprintf("%s/%s", runtime.GOOS, runtime.GOARCH), } )
Functions ¶
func Create ¶
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 ¶
CreateFrom creates a new chart, but scaffolds it from the src chart.
func Expand ¶
Expand uncompresses and extracts a chart into the specified directory.
func ExpandFile ¶
ExpandFile expands the src file into the dest directory.
func FromJson ¶
FromJson converts a JSON document into a map[string]interface{}.
This is not a general-purpose JSON parser, and will not parse all valid JSON documents. Additionally, because its intended use is within templates it tolerates errors. It will insert the returned error message string into m["Error"] in the returned map. TODO: change the function signature in Helm 3
func FromYaml ¶
FromYaml converts a YAML document into a map[string]interface{}.
This is not a general-purpose YAML parser, and will not parse all valid YAML documents. Additionally, because its intended use is within templates it tolerates errors. It will insert the returned error message string into m["Error"] in the returned map.
func Load ¶
Load takes a string name, tries to resolve it to a file or directory, and then loads it.
This is the preferred way to load a chart. It will discover the chart encoding and hand off to the appropriate chart reader.
If a .helmignore file is present, the directory loader will skip loading any files matching it. But .helmignore is not evaluated when reading out of an archive.
func LoadArchive ¶
LoadArchive loads from a reader containing a compressed tar archive.
func LoadChartfile ¶
LoadChartfile loads a Chart.yaml file into a *chart.Metadata.
func LoadFile ¶
LoadFile loads from an archive file.
func LoadFiles ¶
func LoadFiles(files []*BufferedFile) (*chart.Chart, error)
LoadFiles loads from in-memory files.
func ProcessRequirementsConditions ¶
func ProcessRequirementsConditions(reqs *Requirements, cvals Values)
ProcessRequirementsConditions disables charts based on condition path value in values
func ProcessRequirementsEnabled ¶
ProcessRequirementsEnabled removes disabled charts from dependencies
func ProcessRequirementsImportValues ¶
ProcessRequirementsImportValues imports specified chart values from child to parent.
func ProcessRequirementsTags ¶
func ProcessRequirementsTags(reqs *Requirements, cvals Values)
ProcessRequirementsTags disables charts based on tags in values
func Save ¶
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 ¶
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 ¶
SaveDir saves a chart as files in a directory.
func ToJson ¶
func ToJson(v interface{}) string
ToJson takes an interface, marshals it to json, and returns a string. It will always return a string, even on marshal error (empty string).
This is designed to be called from a template. TODO: change the function signature in Helm 3
func ToToml ¶
func ToToml(v interface{}) string
ToToml takes an interface, marshals it to toml, and returns a string. It will always return a string, even on marshal error (empty string).
This is designed to be called from a template.
func ToYaml ¶
func ToYaml(v interface{}) string
ToYaml takes an interface, marshals it to yaml, and returns a string. It will always return a string, even on marshal error (empty string).
This is designed to be called from a template.
func Transform ¶
Transform performs a string replacement of the specified source for a given key with the replacement string
Types ¶
type BufferedFile ¶
BufferedFile represents an archive file buffered for later processing.
type Capabilities ¶
type Capabilities struct { // APIVersions list of all supported API versions APIVersions VersionSet // KubeVersion is the Kubernetes version KubeVersion *version.Info // TillerVersion is the Tiller version // // This always comes from pkg/version.GetVersionProto(). TillerVersion *tversion.Version }
Capabilities describes the capabilities of the Kubernetes cluster that Tiller is attached to.
type Dependency ¶
type Dependency struct { // Name is the name of the dependency. // // This must match the name in the dependency's Chart.yaml. Name string `json:"name"` // Version is the version (range) of this chart. // // A lock file will always produce a single version, while a dependency // may contain a semantic version range. Version string `json:"version,omitempty"` // The URL to the repository. // // Appending `index.yaml` to this string should result in a URL that can be // used to fetch the repository index. Repository string `json:"repository"` // A yaml path that resolves to a boolean, used for enabling/disabling charts (e.g. subchart1.enabled ) Condition string `json:"condition,omitempty"` // Tags can be used to group charts for enabling/disabling together Tags []string `json:"tags,omitempty"` // Enabled bool determines if chart should be loaded Enabled bool `json:"enabled,omitempty"` // ImportValues holds the mapping of source values to parent key to be imported. Each item can be a // string or pair of child/parent sublist items. ImportValues []interface{} `json:"import-values,omitempty"` // Alias usable alias to be used for the chart Alias string `json:"alias,omitempty"` }
Dependency describes a chart upon which another chart depends.
Dependencies can be used to express developer intent, or to capture the state of a chart.
type ErrNoRequirementsFile ¶
type ErrNoRequirementsFile error
ErrNoRequirementsFile to detect error condition
type ErrNoTable ¶
type ErrNoTable error
ErrNoTable indicates that a chart does not have a matching table.
type ErrNoValue ¶
type ErrNoValue error
ErrNoValue indicates that Values does not contain a key with a value
type Files ¶
Files is a map of files in a chart that can be accessed from a template.
func NewFiles ¶
NewFiles creates a new Files from chart files. Given an []*any.Any (the format for files in a chart.Chart), extract a map of files.
func (Files) AsConfig ¶
AsConfig turns a Files group and flattens it to a YAML map suitable for including in the 'data' section of a Kubernetes ConfigMap definition. Duplicate keys will be overwritten, so be aware that your file names (regardless of path) should be unique.
This is designed to be called from a template, and will return empty string (via ToYaml function) if it cannot be serialized to YAML, or if the Files object is nil.
The output will not be indented, so you will want to pipe this to the 'indent' template function.
data:
{{ .Files.Glob("config/**").AsConfig() | indent 4 }}
func (Files) AsSecrets ¶
AsSecrets returns the base64-encoded value of a Files object suitable for including in the 'data' section of a Kubernetes Secret definition. Duplicate keys will be overwritten, so be aware that your file names (regardless of path) should be unique.
This is designed to be called from a template, and will return empty string (via ToYaml function) if it cannot be serialized to YAML, or if the Files object is nil.
The output will not be indented, so you will want to pipe this to the 'indent' template function.
data:
{{ .Files.Glob("secrets/*").AsSecrets() }}
func (Files) Get ¶
Get returns a string representation of the given file.
Fetch the contents of a file as a string. It is designed to be called in a template.
{{.Files.Get "foo"}}
func (Files) GetBytes ¶
GetBytes gets a file by path.
The returned data is raw. In a template context, this is identical to calling {{index .Files $path}}.
This is intended to be accessed from within a template, so a missed key returns an empty []byte.
func (Files) Glob ¶
Glob takes a glob pattern and returns another files object only containing matched files.
This is designed to be called from a template.
{{ range $name, $content := .Files.Glob("foo/**") }} {{ $name }}: | {{ .Files.Get($name) | indent 4 }}{{ end }}
type ReleaseOptions ¶
type ReleaseOptions struct { Name string Time *timestamp.Timestamp Namespace string IsUpgrade bool IsInstall bool Revision int }
ReleaseOptions represents the additional release options needed for the composition of the final values struct
type Requirements ¶
type Requirements struct {
Dependencies []*Dependency `json:"dependencies"`
}
Requirements is a list of requirements for a chart.
Requirements are charts upon which this chart depends. This expresses developer intent.
func LoadRequirements ¶
func LoadRequirements(c *chart.Chart) (*Requirements, error)
LoadRequirements loads a requirements file from an in-memory chart.
type RequirementsLock ¶
type RequirementsLock struct { // Generated is the date the lock file was last generated. Generated time.Time `json:"generated"` // Digest is a hash of the requirements file used to generate it. Digest string `json:"digest"` // Dependencies is the list of dependencies that this lock file has locked. Dependencies []*Dependency `json:"dependencies"` }
RequirementsLock is a lock file for requirements.
It represents the state that the dependencies should be in.
func LoadRequirementsLock ¶
func LoadRequirementsLock(c *chart.Chart) (*RequirementsLock, error)
LoadRequirementsLock loads a requirements lock file.
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 ¶
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 ReadValues ¶
ReadValues will parse YAML byte data into a Values.
func ReadValuesFile ¶
ReadValuesFile will parse a YAML file into a map of values.
func ToRenderValues ¶
func ToRenderValues(chrt *chart.Chart, chrtVals *chart.Config, options ReleaseOptions) (Values, error)
ToRenderValues composes the struct from the data coming from the Releases, Charts and Values files
WARNING: This function is deprecated for Helm > 2.1.99 Use ToRenderValuesCaps() instead. It will remain in the codebase to stay SemVer compliant.
In Helm 3.0, this will be changed to accept Capabilities as a fourth parameter.
func ToRenderValuesCaps ¶
func ToRenderValuesCaps(chrt *chart.Chart, chrtVals *chart.Config, options ReleaseOptions, caps *Capabilities) (Values, error)
ToRenderValuesCaps 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 ¶
AsMap is a utility function for converting Values to a map[string]interface{}.
It protects against nil map panics.
func (Values) Encode ¶
Encode writes serialized Values information to the given io.Writer.
func (Values) MergeInto ¶
MergeInto takes the properties in src and merges them into Values. Maps are merged while values and arrays are replaced.
func (Values) PathValue ¶
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 ¶
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.
type VersionSet ¶
type VersionSet map[string]interface{}
VersionSet is a set of Kubernetes API versions.
func NewVersionSet ¶
func NewVersionSet(apiVersions ...string) VersionSet
NewVersionSet creates a new version set from a list of strings.
func (VersionSet) Has ¶
func (v VersionSet) Has(apiVersion string) bool
Has returns true if the version string is in the set.
vs.Has("extensions/v1beta1")