helmclient

package module
v0.8.1-0...-4019f26 Latest Latest
Warning

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

Go to latest
Published: Jul 8, 2021 License: MIT Imports: 31 Imported by: 0

README

Go Helm Client

Go client library for accessing Helm, enabling the user to programmatically change helm charts and releases.

This library is build upon helm and available under the MIT License.

GitHub license Go Report Card Documentation

Installation

Install this library using go get:

$ go get github.com/tsingloon/go-helm-client

Usage

Example usage of the client can be found in the package examples.

Private chart repository

When working with private repositories, you can utilize the Username and Password parameters of a chart entry to specify credentials.

An example of this can be found in the corresponding example.

Mock Client

This library includes a mock client mock/interface_mock.go which is generated by mockgen.

Example usage of the mocked client can be found in mock/mock_test.go.

If you made changes to interface.go, you should issue the go generate ./... command to trigger code generation.

Documentation

For more specific documentation, please refer to the godoc of this library.

Documentation

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ChartSpec

type ChartSpec struct {
	ReleaseName string `json:"release"`
	ChartName   string `json:"chart"`
	Namespace   string `json:"namespace"`

	// use string instead of map[string]interface{}
	// https://github.com/kubernetes-sigs/kubebuilder/issues/528#issuecomment-466449483
	// and https://github.com/kubernetes-sigs/controller-tools/pull/317
	// +optional
	ValuesYaml string `json:"valuesYaml,omitempty"`

	// +optional
	Version string `json:"version,omitempty"`

	// +optional
	DisableHooks bool `json:"disableHooks,omitempty"`

	// +optional
	Replace bool `json:"replace,omitempty"`

	// +optional
	Wait bool `json:"wait,omitempty"`

	// +optional
	DependencyUpdate bool `json:"dependencyUpdate,omitempty"`

	// +optional
	Timeout time.Duration `json:"timeout,omitempty"`

	// +optional
	GenerateName bool `json:"generateName,omitempty"`

	// +optional
	NameTemplate string `json:"NameTemplate,omitempty"`

	// +optional
	Atomic bool `json:"atomic,omitempty"`

	// +optional
	SkipCRDs bool `json:"skipCRDs,omitempty"`

	// +optional
	UpgradeCRDs bool `json:"upgradeCRDs,omitempty"`

	// +optional
	SubNotes bool `json:"subNotes,omitempty"`

	// +optional
	Force bool `json:"force,omitempty"`

	// +optional
	ResetValues bool `json:"resetValues,omitempty"`

	// +optional
	ReuseValues bool `json:"reuseValues,omitempty"`

	// +optional
	Recreate bool `json:"recreate,omitempty"`

	// +optional
	MaxHistory int `json:"maxHistory,omitempty"`

	// +optional
	CleanupOnFail bool `json:"cleanupOnFail,omitempty"`

	// +optional
	DryRun bool `json:"dryRun,omitempty"`
}

ChartSpec defines the values of a helm chart

func (*ChartSpec) GetValuesMap

func (spec *ChartSpec) GetValuesMap() (map[string]interface{}, error)

GetValuesMap returns the mapped out values of a chart

type Client

type Client interface {
	AddOrUpdateChartRepo(entry repo.Entry) error
	UpdateChartRepos() error
	InstallOrUpgradeChart(ctx context.Context, spec *ChartSpec) (*release.Release, error)
	ListDeployedReleases() ([]*release.Release, error)
	GetRelease(name string) (*release.Release, error)
	RollbackRelease(spec *ChartSpec, version int) error
	GetReleaseValues(name string, allValues bool) (map[string]interface{}, error)
	DeleteChartFromCache(spec *ChartSpec) error
	UninstallRelease(spec *ChartSpec) error
	UninstallReleaseByName(name string) error
	TemplateChart(spec *ChartSpec) ([]byte, error)
	LintChart(spec *ChartSpec) error

	GetSetings() *cli.EnvSettings
	GetProviders() getter.Providers
	GetStorage() *repo.File
	GetActionConfig() *action.Configuration
	GetLinting() bool
}

func New

func New(options *Options) (Client, error)

New returns a new Helm client with the provided options

Example
opt := &Options{
	RepositoryCache:  "/tmp/.helmcache",
	RepositoryConfig: "/tmp/.helmrepo",
	Debug:            true,
	Linting:          true,
}

helmClient, err := New(opt)
if err != nil {
	panic(err)
}
_ = helmClient
Output:

func NewClientFromKubeConf

func NewClientFromKubeConf(options *KubeConfClientOptions) (Client, error)

NewClientFromKubeConf returns a new Helm client constructed with the provided kubeconfig options

Example
opt := &KubeConfClientOptions{
	Options: &Options{
		RepositoryCache:  "/tmp/.helmcache",
		RepositoryConfig: "/tmp/.helmrepo",
		Debug:            true,
		Linting:          true,
	},
	KubeContext: "",
	KubeConfig:  []byte{},
}

helmClient, err := NewClientFromKubeConf(opt)
if err != nil {
	panic(err)
}
_ = helmClient
Output:

func NewClientFromRestConf

func NewClientFromRestConf(options *RestConfClientOptions) (Client, error)

NewClientFromRestConf returns a new Helm client constructed with the provided REST config options

Example
opt := &RestConfClientOptions{
	Options: &Options{
		RepositoryCache:  "/tmp/.helmcache",
		RepositoryConfig: "/tmp/.helmrepo",
		Debug:            true,
		Linting:          true,
	},
	RestConfig: &rest.Config{},
}

helmClient, err := NewClientFromRestConf(opt)
if err != nil {
	panic(err)
}
_ = helmClient
Output:

type HelmClient

type HelmClient struct {
	Settings  *cli.EnvSettings
	Providers getter.Providers

	ActionConfig *action.Configuration
	// contains filtered or unexported fields
}

HelmClient Client defines the values of a helm client

func (*HelmClient) AddOrUpdateChartRepo

func (c *HelmClient) AddOrUpdateChartRepo(entry repo.Entry) error

AddOrUpdateChartRepo adds or updates the provided helm chart repository

Example (Private)
// Define a private chart repository
chartRepo := repo.Entry{
	Name:     "stable",
	URL:      "https://private-chartrepo.somedomain.com",
	Username: "foo",
	Password: "bar",
	// Since helm 3.6.1 it is necessary to pass PassCredentialsAll = true
	PassCredentialsAll: true,
}

// Add a chart-repository to the client
if err := helmClient.AddOrUpdateChartRepo(chartRepo); err != nil {
	panic(err)
}
Output:

Example (Public)
// Define a public chart repository
chartRepo := repo.Entry{
	Name: "stable",
	URL:  "https://kubernetes-charts.storage.googleapis.com",
}

// Add a chart-repository to the client
if err := helmClient.AddOrUpdateChartRepo(chartRepo); err != nil {
	panic(err)
}
Output:

func (*HelmClient) DeleteChartFromCache

func (c *HelmClient) DeleteChartFromCache(spec *ChartSpec) error

DeleteChartFromCache deletes the provided chart from the client's cache

Example
// Define the chart to be deleted from the client's cache
chartSpec := ChartSpec{
	ReleaseName: "etcd-operator",
	ChartName:   "stable/etcd-operator",
	Namespace:   "default",
	UpgradeCRDs: true,
	Wait:        true,
}

if err := helmClient.DeleteChartFromCache(&chartSpec); err != nil {
	panic(err)
}
Output:

func (*HelmClient) GetActionConfig

func (c *HelmClient) GetActionConfig() *action.Configuration

func (*HelmClient) GetLinting

func (c *HelmClient) GetLinting() bool

func (*HelmClient) GetProviders

func (c *HelmClient) GetProviders() getter.Providers

func (*HelmClient) GetRelease

func (c *HelmClient) GetRelease(name string) (*release.Release, error)

GetRelease returns a release specified by name.

Example
if _, err := helmClient.GetRelease("etcd-operator"); err != nil {
	panic(err)
}
Output:

func (*HelmClient) GetReleaseValues

func (c *HelmClient) GetReleaseValues(name string, allValues bool) (map[string]interface{}, error)

GetReleaseValues returns the (optionally, all computed) values for the specified release.

Example
if _, err := helmClient.GetReleaseValues("etcd-operator", true); err != nil {
	panic(err)
}
Output:

func (*HelmClient) GetSetings

func (c *HelmClient) GetSetings() *cli.EnvSettings

func (*HelmClient) GetStorage

func (c *HelmClient) GetStorage() *repo.File

func (*HelmClient) InstallOrUpgradeChart

func (c *HelmClient) InstallOrUpgradeChart(ctx context.Context, spec *ChartSpec) (*release.Release, error)

InstallOrUpgradeChart triggers the installation of the provided chart and returns the installed / upgraded release. If the chart is already installed, trigger an upgrade instead.

Example
// Define the chart to be installed
chartSpec := ChartSpec{
	ReleaseName: "etcd-operator",
	ChartName:   "stable/etcd-operator",
	Namespace:   "default",
	UpgradeCRDs: true,
	Wait:        true,
}

if err, _ := helmClient.InstallOrUpgradeChart(context.Background(), &chartSpec); err != nil {
	panic(err)
}
Output:

func (*HelmClient) LintChart

func (c *HelmClient) LintChart(spec *ChartSpec) error

LintChart fetches a chart using the provided ChartSpec 'spec' and lints it's values.

Example
// Define a chart with custom values to be tested
chartSpec := ChartSpec{
	ReleaseName: "etcd-operator",
	ChartName:   "stable/etcd-operator",
	Namespace:   "default",
	UpgradeCRDs: true,
	Wait:        true,
	ValuesYaml: `deployments:
  etcdOperator: true
  backupOperator: false`,
}

if err := helmClient.LintChart(&chartSpec); err != nil {
	panic(err)
}
Output:

func (*HelmClient) ListDeployedReleases

func (c *HelmClient) ListDeployedReleases() ([]*release.Release, error)

ListDeployedReleases lists all deployed releases. Namespace and other context is provided via the Options struct when instantiating a client.

Example
if _, err := helmClient.ListDeployedReleases(); err != nil {
	panic(err)
}
Output:

func (*HelmClient) RollbackRelease

func (c *HelmClient) RollbackRelease(spec *ChartSpec, version int) error

RollbackRelease rollbacks a release to a specific version. Specifying '0' as the value for 'version' will result in a rollback to the previous release version.

Example
// Define the released chart to be installed
chartSpec := ChartSpec{
	ReleaseName: "etcd-operator",
	ChartName:   "stable/etcd-operator",
	Namespace:   "default",
	UpgradeCRDs: true,
	Wait:        true,
}

// Rollback to the previous version of the release by setting the release version to '0'.
if err := helmClient.RollbackRelease(&chartSpec, 0); err != nil {
	return
}
Output:

func (*HelmClient) TemplateChart

func (c *HelmClient) TemplateChart(spec *ChartSpec) ([]byte, error)

TemplateChart returns a rendered version of the provided ChartSpec 'spec' by performing a "dry-run" install

Example
chartSpec := ChartSpec{
	ReleaseName: "etcd-operator",
	ChartName:   "stable/etcd-operator",
	Namespace:   "default",
	UpgradeCRDs: true,
	Wait:        true,
	ValuesYaml: `deployments:
  etcdOperator: true
  backupOperator: false`,
}

_, err := helmClient.TemplateChart(&chartSpec)
if err != nil {
	panic(err)
}
Output:

func (*HelmClient) UninstallRelease

func (c *HelmClient) UninstallRelease(spec *ChartSpec) error

UninstallRelease uninstalls the provided release

Example
// Define the released chart to be installed
chartSpec := ChartSpec{
	ReleaseName: "etcd-operator",
	ChartName:   "stable/etcd-operator",
	Namespace:   "default",
	UpgradeCRDs: true,
	Wait:        true,
}

if err := helmClient.UninstallRelease(&chartSpec); err != nil {
	panic(err)
}
Output:

func (*HelmClient) UninstallReleaseByName

func (c *HelmClient) UninstallReleaseByName(name string) error

UninstallReleaseByName uninstalls a release identified by the provided 'name'.

Example
if err := helmClient.UninstallReleaseByName("etcd-operator"); err != nil {
	panic(err)
}
Output:

func (*HelmClient) UpdateChartRepos

func (c *HelmClient) UpdateChartRepos() error

UpdateChartRepos updates the list of chart repositories stored in the client's cache

Example
if err := helmClient.UpdateChartRepos(); err != nil {
	panic(err)
}
Output:

type KubeConfClientOptions

type KubeConfClientOptions struct {
	*Options
	KubeContext string
	KubeConfig  []byte
}

KubeConfClientOptions defines the options used for constructing a client via kubeconfig

type Options

type Options struct {
	Namespace        string
	RepositoryConfig string
	RepositoryCache  string
	Debug            bool
	Linting          bool
	DebugLog         action.DebugLog
}

Options defines the options of a client

type RESTClientGetter

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

RESTClientGetter defines the values of a helm REST client

func NewRESTClientGetter

func NewRESTClientGetter(namespace string, kubeConfig []byte, restConfig *rest.Config) *RESTClientGetter

NewRESTClientGetter

source: https://github.com/helm/helm/issues/6910#issuecomment-601277026

func (*RESTClientGetter) ToDiscoveryClient

func (c *RESTClientGetter) ToDiscoveryClient() (discovery.CachedDiscoveryInterface, error)

func (*RESTClientGetter) ToRESTConfig

func (c *RESTClientGetter) ToRESTConfig() (*rest.Config, error)

ToRESTConfig returns a REST config build from a given kubeconfig

func (*RESTClientGetter) ToRESTMapper

func (c *RESTClientGetter) ToRESTMapper() (meta.RESTMapper, error)

func (*RESTClientGetter) ToRawKubeConfigLoader

func (c *RESTClientGetter) ToRawKubeConfigLoader() clientcmd.ClientConfig

type RestConfClientOptions

type RestConfClientOptions struct {
	*Options
	RestConfig *rest.Config
}

RestConfClientOptions defines the options used for constructing a client via REST config

Directories

Path Synopsis
Package mockhelmclient is a generated GoMock package.
Package mockhelmclient is a generated GoMock package.

Jump to

Keyboard shortcuts

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