chartutil

package
v2.0.0-beta.2+incompat... Latest Latest
Warning

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

Go to latest
Published: Oct 25, 2016 License: Apache-2.0 Imports: 17 Imported by: 7

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 utilitites 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/happy/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"
	// 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"
)
View Source
const ApiVersionV1 = "v1"

ApiVersionV1 is the API version number for version 1.

This is ApiVersionV1 instead of APIVersionV1 to match the protobuf-generated name.

View Source
const GlobalKey = "global"

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

Variables

View Source
var (
	// ErrRequirementsNotFound indicates that a requirements.yaml is not found.
	ErrRequirementsNotFound = errors.New(requirementsName + " not found")
	// ErrLockfileNotFound indicates that a requirements.lock is not found.
	ErrLockfileNotFound = errors.New(lockfileName + " not found")
)

Functions

func Create

func Create(chartfile *chart.Metadata, 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 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 directroy.

func Load

func Load(name string) (*chart.Chart, error)

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

func LoadArchive(in io.Reader) (*chart.Chart, error)

LoadArchive loads from a reader containing a compressed tar archive.

func LoadChartfile

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

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

func LoadDir

func LoadDir(dir string) (*chart.Chart, error)

LoadDir loads from a directory.

This loads charts only from directories.

func LoadFile

func LoadFile(name string) (*chart.Chart, error)

LoadFile loads from an archive file.

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 UnmarshalChartfile

func UnmarshalChartfile(data []byte) (*chart.Metadata, error)

UnmarshalChartfile takes raw Chart.yaml data and unmarshals it.

Types

type Dependency

type Dependency struct {
	// Name is the name of the dependency.
	//
	// This must mach 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"`
}

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 ErrNoTable

type ErrNoTable error

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

type Files

type Files map[string][]byte

Files is a map of files in a chart that can be accessed from a template.

func NewFiles

func NewFiles(from []*any.Any) Files

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) Get

func (f Files) Get(name string) string

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

func (f Files) GetBytes(name string) []byte

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.

type ReleaseOptions

type ReleaseOptions struct {
	Name      string
	Time      *timestamp.Timestamp
	Namespace string
}

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 {
	// Genderated 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

func CoalesceValues(chrt *chart.Chart, vals *chart.Config) (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 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 *chart.Config, options ReleaseOptions) (Values, error)

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

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) 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.

Jump to

Keyboard shortcuts

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