helmclient

package module
v1.0.6 Latest Latest
Warning

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

Go to latest
Published: Aug 5, 2020 License: Apache-2.0 Imports: 32 Imported by: 20

README

GoDoc CircleCI

helmclient

Package helmclient implements Helm related primitives to work against helm releases. Currently supports Helm 3.

Branches

  • master
    • Latest version using Helm 3.
  • helm2
    • Legacy support for Helm 2.

Interface

See helmclient.Interface in spec.go for supported methods.

Getting Project

Clone the git repository: https://github.com/giantswarm/helmclient.git

How to build

Build it using the standard go build command.

go build github.com/giantswarm/helmclient

Contact

Contributing & Reporting Bugs

See CONTRIBUTING for details on submitting patches, the contribution workflow as well as reporting bugs.

License

helmclient is under the Apache 2.0 license. See the LICENSE file for details.

Documentation

Index

Constants

View Source
const (
	PrometheusNamespace = "helmclient"
	PrometheusSubsystem = "library"
)
View Source
const (
	// StatusUnknown indicates that a release is in an uncertain state.
	StatusUnknown = "unknown"
	// StatusDeployed indicates that the release has been pushed to Kubernetes.
	StatusDeployed = "deployed"
	// StatusUninstalled indicates that a release has been uninstalled from Kubernetes.
	StatusUninstalled = "uninstalled"
	// StatusSuperseded indicates that this release object is outdated and a newer one exists.
	StatusSuperseded = "superseded"
	// StatusFailed indicates that the release was not successfully deployed.
	StatusFailed = "failed"
	// StatusUninstalling indicates that a uninstall operation is underway.
	StatusUninstalling = "uninstalling"
	// StatusPendingInstall indicates that an install operation is underway.
	StatusPendingInstall = "pending-install"
	// StatusPendingUpgrade indicates that an upgrade operation is underway.
	StatusPendingUpgrade = "pending-upgrade"
	// StatusPendingRollback indicates that an rollback operation is underway.
	StatusPendingRollback = "pending-rollback"
)

Describes the status of a release. This needs to be kept in sync with upstream but it allows us to have constants without importing Helm packages.

See: https://github.com/helm/helm/blob/master/pkg/release/status.go

Variables

View Source
var (
	// ReleaseTransitionStatuses is used to determine if the Helm Release is
	// currently being updated.
	ReleaseTransitionStatuses = map[string]bool{
		StatusUninstalled:     true,
		StatusPendingInstall:  true,
		StatusPendingUpgrade:  true,
		StatusPendingRollback: true,
	}
)

Functions

func IsCannotReuseRelease

func IsCannotReuseRelease(err error) bool

IsCannotReuseRelease asserts cannotReuseReleaseError.

func IsEmptyChartTemplates

func IsEmptyChartTemplates(err error) bool

IsEmptyChartTemplates asserts emptyChartTemplatesError.

func IsExecutionFailed

func IsExecutionFailed(err error) bool

IsExecutionFailed asserts executionFailedError.

func IsInvalidConfig

func IsInvalidConfig(err error) bool

IsInvalidConfig asserts invalidConfigError.

func IsInvalidGZipHeader

func IsInvalidGZipHeader(err error) bool

IsInvalidGZipHeader asserts invalidGZipHeaderError.

func IsInvalidManifest added in v1.0.1

func IsInvalidManifest(err error) bool

IsInvalidManifest asserts invalidManifestError.

func IsNotFound

func IsNotFound(err error) bool

IsNotFound asserts notFoundError.

func IsParsingDestFailedError added in v0.2.3

func IsParsingDestFailedError(err error) bool

IsParsingDestFailedError asserts parsingDestFailedError.

func IsParsingSrcFailedError added in v0.2.3

func IsParsingSrcFailedError(err error) bool

IsparsingSrcFailedError asserts parsingSrcFailedError.

func IsPullChartFailedError

func IsPullChartFailedError(err error) bool

IsPullChartFailedError asserts pullChartFailedError.

func IsPullChartNotFound

func IsPullChartNotFound(err error) bool

IsPullChartNotFound asserts pullChartNotFoundError.

func IsPullChartTimeout

func IsPullChartTimeout(err error) bool

IsPullChartTimeout asserts pullChartTimeoutError.

func IsReleaseAlreadyExists

func IsReleaseAlreadyExists(err error) bool

IsReleaseAlreadyExists asserts releaseAlreadyExistsError.

func IsReleaseNameInvalid

func IsReleaseNameInvalid(err error) bool

IsReleaseNameInvalid asserts releaseNameInvalidError.

func IsReleaseNotDeployed

func IsReleaseNotDeployed(err error) bool

IsReleaseNotDeployed asserts releaseNotDeployedError.

func IsReleaseNotFound

func IsReleaseNotFound(err error) bool

IsReleaseNotFound asserts releaseNotFoundError.

func IsTarballNotFound

func IsTarballNotFound(err error) bool

IsTarballNotFound asserts tarballNotFoundError.

func IsTestReleaseFailure

func IsTestReleaseFailure(err error) bool

IsTestReleaseFailure asserts testReleaseFailureError.

func IsTestReleaseTimeout

func IsTestReleaseTimeout(err error) bool

IsTestReleaseTimeout asserts testReleaseTimeoutError.

func IsTooManyResults

func IsTooManyResults(err error) bool

IsTooManyResults asserts tooManyResultsError.

func IsValidationFailedError added in v1.0.2

func IsValidationFailedError(err error) bool

IsValidationFailedError asserts validationFailedError.

func IsYamlConversionFailed

func IsYamlConversionFailed(err error) bool

IsYamlConversionFailed asserts yamlConversionFailedError.

func MergeValues

func MergeValues(destMap, srcMap map[string][]byte) (map[string]interface{}, error)

MergeValues merges config values so they can be used when installing or updating Helm releases. It takes in 2 maps with a string key and YAML values passed as a byte array.

A deep merge is performed into a single map[string]interface{} output. If a value is present in both then the source map is preferred.

The YAML values are parsed using yamlToStringMap. This is because the default behaviour of the YAML parser is to unmarshal into map[interface{}]interface{} which causes problems with the merge logic. See https://github.com/go-yaml/yaml/issues/139.

Types

type Chart

type Chart struct {
	// Version is the version of the Helm Chart.
	Version string
}

Chart returns information about a Helm Chart.

type Client

type Client struct {
	// contains filtered or unexported fields
}

Client knows how to talk with Helm.

func New

func New(config Config) (*Client, error)

New creates a new configured Helm client.

func (*Client) DeleteRelease

func (c *Client) DeleteRelease(ctx context.Context, namespace, releaseName string) error

DeleteRelease uninstalls a chart given its release name.

func (*Client) GetReleaseContent

func (c *Client) GetReleaseContent(ctx context.Context, namespace, releaseName string) (*ReleaseContent, error)

GetReleaseContent gets the current status of the Helm Release including any values provided when the chart was installed. The releaseName is the name of the Helm Release that is set when the Helm Chart is installed.

func (*Client) GetReleaseHistory

func (c *Client) GetReleaseHistory(ctx context.Context, namespace, releaseName string) (*ReleaseHistory, error)

GetReleaseHistory gets the current installed version of the Helm Release. The releaseName is the name of the Helm Release that is set when the Helm Chart is installed.

func (*Client) InstallReleaseFromTarball

func (c *Client) InstallReleaseFromTarball(ctx context.Context, chartPath, namespace string, values map[string]interface{}, options InstallOptions) error

InstallReleaseFromTarball installs a chart packaged in the given tarball.

func (*Client) ListReleaseContents

func (c *Client) ListReleaseContents(ctx context.Context, namespace string) ([]*ReleaseContent, error)

ListReleaseContents gets the current status of all Helm Releases.

func (*Client) LoadChart

func (c *Client) LoadChart(ctx context.Context, chartPath string) (Chart, error)

LoadChart loads a Helm Chart and returns relevant parts of its structure.

func (*Client) PullChartTarball

func (c *Client) PullChartTarball(ctx context.Context, tarballURL string) (string, error)

PullChartTarball downloads a tarball from the provided tarball URL, returning the file path.

func (*Client) Rollback added in v1.0.6

func (c *Client) Rollback(ctx context.Context, namespace, releaseName string, revision int, options RollbackOptions) error

Rollback executes a rollback to a previous revision of a Helm release.

func (*Client) RunReleaseTest

func (c *Client) RunReleaseTest(ctx context.Context, namespace, releaseName string) error

RunReleaseTest runs the tests for a Helm Release. The releaseName is the name of the Helm Release that is set when the Helm Chart is installed. This is the same action as running the helm test command.

func (*Client) UpdateReleaseFromTarball

func (c *Client) UpdateReleaseFromTarball(ctx context.Context, chartPath, namespace, releaseName string, values map[string]interface{}, options UpdateOptions) error

UpdateReleaseFromTarball updates the given release using the chart packaged in the tarball.

type Config

type Config struct {
	Fs afero.Fs
	// HelmClient sets a helm client used for all operations of the initiated
	// client. If this is nil, a new helm client will be created. Setting the
	// helm client here manually might only be sufficient for testing or
	// whenever you know what you do.
	HelmClient Interface
	K8sClient  k8sclient.Interface
	Logger     micrologger.Logger

	HTTPClientTimeout time.Duration
}

Config represents the configuration used to create a helm client.

type InstallOptions added in v1.0.0

type InstallOptions struct {
	Namespace   string
	ReleaseName string
	Timeout     time.Duration
	Wait        bool
}

InstallOptions is the subset of supported options when installing Helm releases.

type Interface

type Interface interface {
	// DeleteRelease uninstalls a chart given its release name.
	DeleteRelease(ctx context.Context, namespace, releaseName string) error
	// GetReleaseContent gets the current status of the Helm Release. The
	// releaseName is the name of the Helm Release that is set when the Chart
	// is installed.
	GetReleaseContent(ctx context.Context, namespace, releaseName string) (*ReleaseContent, error)
	// GetReleaseHistory gets the current installed version of the Helm Release.
	// The releaseName is the name of the Helm Release that is set when the Helm
	// Chart is installed.
	GetReleaseHistory(ctx context.Context, namespace, releaseName string) (*ReleaseHistory, error)
	// InstallReleaseFromTarball installs a Helm Chart packaged in the given tarball.
	InstallReleaseFromTarball(ctx context.Context, chartPath, namespace string, values map[string]interface{}, options InstallOptions) error
	// ListReleaseContents gets the current status of all Helm Releases.
	ListReleaseContents(ctx context.Context, namespace string) ([]*ReleaseContent, error)
	// LoadChart loads a Helm Chart and returns its structure.
	LoadChart(ctx context.Context, chartPath string) (Chart, error)
	// PullChartTarball downloads a tarball from the provided tarball URL,
	// returning the file path.
	PullChartTarball(ctx context.Context, tarballURL string) (string, error)
	// Rollback executes a rollback to a previous revision of a Helm release.
	Rollback(ctx context.Context, namespace, releaseName string, revision int, options RollbackOptions) error
	// RunReleaseTest runs the tests for a Helm Release. This is the same
	// action as running the helm test command.
	RunReleaseTest(ctx context.Context, namespace, releaseName string) error
	// UpdateReleaseFromTarball updates the given release using the chart packaged
	// in the tarball.
	UpdateReleaseFromTarball(ctx context.Context, chartPath, namespace, releaseName string, values map[string]interface{}, options UpdateOptions) error
}

Interface describes the methods provided by the Helm client.

type RESTClientGetter added in v1.0.0

type RESTClientGetter interface {
	// ToDiscoveryClient returns discovery client
	ToDiscoveryClient() (discovery.CachedDiscoveryInterface, error)
	// ToRawKubeConfigLoader return kubeconfig loader as-is
	ToRawKubeConfigLoader() clientcmd.ClientConfig
	// ToRESTConfig returns restconfig
	ToRESTConfig() (*rest.Config, error)
	// ToRESTMapper returns a restmapper
	ToRESTMapper() (meta.RESTMapper, error)
}

RESTClientGetter is used to configure the action package which is the Helm Go client.

type ReleaseContent

type ReleaseContent struct {
	// AppVersion is the app version of the Helm Chart that has been deployed.
	AppVersion string
	// Description is a human-friendly "log entry" about this Helm release.
	Description string
	// LastDeployed is the time the Helm Chart was last deployed.
	LastDeployed time.Time
	// Name is the name of the Helm Release.
	Name string
	// Revision is the revision number of the Helm Release.
	Revision int
	// Status is the Helm status code of the Release.
	Status string
	// Values are the values provided when installing the Helm Release.
	Values map[string]interface{}
	// Version is the version of the Helm Chart that has been deployed.
	Version string
}

ReleaseContent returns status information about a Helm Release.

type ReleaseHistory

type ReleaseHistory struct {
	// AppVersion is the app version of the Helm Chart that has been deployed.
	AppVersion string
	// Description is a human-friendly "log entry" about this Helm release.
	Description string
	// LastDeployed is the time the Helm Chart was last deployed.
	LastDeployed time.Time
	// Name is the name of the Helm Release.
	Name string
	// Version is the version of the Helm Chart that has been deployed.
	Version string
}

ReleaseHistory returns version information about a Helm Release.

type RollbackOptions added in v1.0.6

type RollbackOptions struct {
	Force   bool
	Timeout time.Duration
	Version int
	Wait    bool
}

RollbackOptions is the subset of supported options when rollback back Helm releases.

type UpdateOptions added in v1.0.0

type UpdateOptions struct {
	Force   bool
	Timeout time.Duration
	Wait    bool
}

UpdateOptions is the subset of supported options when updating Helm releases.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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