Help us shape the future of Go! Take the 2026 Go Developer Survey

client

package
v1.1.1 Latest Latest
Warning

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

Go to latest
Published: Oct 7, 2024 License: AGPL-3.0, MIT Imports: 28 Imported by: 2

README

The files in this directory were copied from https://github.com/mittwald/go-helm-client/tree/15ee7e014f3c79d7b48b24fcd29a34a2990d4450.

Their original contents are licensed MIT and copyrighted by Mittwald CM Service except stated otherwise.

Modifications are licensed AGPL-3.0-only under the root license of this repository. Modifications include:

  • support for plain http registries
  • usage of the client's action.Config when getting charts
  • simplification of ChartSpec by stripping unnecessary fields
  • simplification of the installation and upgrade procedures by removing (for our use-case) unnecessary code
  • removal of unnecessary functions from the client
  • embedding the registry client into the helm client to act as a tag resolver
  • Moving example code to example_test.go
  • refactoring to improve testability
  • adding tests

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 where the chart release is deployed.
	// Note that client.Options.Namespace should ideally match the namespace configured here.
	Namespace string `json:"namespace"`
	// ValuesYaml is the values.yaml content.
	// 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"`
	// Specify values similar to the cli
	// +optional
	ValuesOptions values.Options `json:"valuesOptions,omitempty"`
	// Version of the chart release.
	// +optional
	Version string `json:"version,omitempty"`
	// CreateNamespace indicates whether to create the namespace if it does not exist.
	// +optional
	CreateNamespace bool `json:"createNamespace,omitempty"`
	// Timeout configures the time to wait for any individual Kubernetes operation (like Jobs for hooks).
	// +optional
	Timeout time.Duration `json:"timeout,omitempty"`
	// Atomic indicates whether to install resources atomically.
	// 'Wait' will automatically be set to true when using Atomic.
	// +optional
	Atomic bool `json:"atomic,omitempty"`
	// ResetValues indicates whether to reset the values.yaml file during installation.
	// +optional
	ResetValues bool `json:"resetValues,omitempty"`
	// ReuseValues indicates whether to reuse the values.yaml file during installation.
	// +optional
	ReuseValues bool `json:"reuseValues,omitempty"`
	// CleanupOnFail indicates whether to cleanup the release on failure.
	// +optional
	CleanupOnFail bool `json:"cleanupOnFail,omitempty"`
	// PostRenderer can be used to apply transformations to kubernetes resources
	// on installation and upgrade after rendering the templates
	// +optional
	PostRenderer postrender.PostRenderer
}

ChartSpec defines the values of a helm chart

func (*ChartSpec) GetValuesMap

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

GetValuesMap returns the merged mapped out values of a chart, using both ValuesYaml and ValuesOptions

type Client

type Client interface {
	InstallOrUpgradeChart(ctx context.Context, spec *ChartSpec) (*release.Release, error)
	InstallChart(ctx context.Context, spec *ChartSpec) (*release.Release, error)
	UpgradeChart(ctx context.Context, spec *ChartSpec) (*release.Release, error)
	ListDeployedReleases() ([]*release.Release, error)
	ListReleasesByStateMask(action.ListStates) ([]*release.Release, error)
	GetRelease(name string) (*release.Release, error)
	// RollBack is an interface to abstract a rollback action.
	RollBack
	GetReleaseValues(name string, allValues bool) (map[string]interface{}, error)
	GetChartSpecValues(spec *ChartSpec) (map[string]interface{}, error)
	UninstallRelease(spec *ChartSpec) error
	UninstallReleaseByName(name string) error
	GetChart(spec *ChartSpec) (*chart.Chart, string, error)
	TagResolver
}

Client holds the method signatures for a Helm client. NOTE: This is an interface to allow for mocking in tests.

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{
		Namespace:        "default", // Change this to the namespace you wish the client to operate in.
		RepositoryCache:  "/tmp/.helmcache",
		RepositoryConfig: "/tmp/.helmrepo",
		Debug:            true,
		DebugLog: func(format string, v ...interface{}) {
			// Change this to your own logger. Default is 'log.Printf(format, v...)'.
		},
	},
	RestConfig: &rest.Config{},
}

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

type HelmClient

type HelmClient struct {
	TagResolver
	// Settings defines the environment settings of a client.
	Settings *cli.EnvSettings

	DebugLog action.DebugLog
	// contains filtered or unexported fields
}

HelmClient Client defines the values of a helm client.

func (*HelmClient) GetChart

func (c *HelmClient) GetChart(spec *ChartSpec) (*chart.Chart, string, error)

GetChart returns a chart matching the provided chart name and options.

func (*HelmClient) GetChartSpecValues added in v0.6.0

func (c *HelmClient) GetChartSpecValues(spec *ChartSpec) (map[string]interface{}, error)

GetChartSpecValues returns the additional values for the specified ChartSpec.

func (*HelmClient) GetRelease

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

GetRelease returns a release specified by name.

Example
// Get specific details of a deployed release.
if _, err := helmClient.GetRelease("etcd-operator"); err != nil {
	panic(err)
}

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
// Get the values of a deployed release.
if _, err := helmClient.GetReleaseValues("etcd-operator", true); err != nil {
	panic(err)
}

func (*HelmClient) InstallChart

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

InstallChart installs the provided chart and returns the corresponding release. Namespace and other context is provided via the client.Options struct when instantiating a client.

func (*HelmClient) InstallOrUpgradeChart

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

InstallOrUpgradeChart installs or upgrades the provided chart and returns the corresponding release. Namespace and other context is provided via the client.Options struct when instantiating a client.

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

// Install a chart release.
// Note that helmclient.Options.Namespace should ideally match the namespace in chartSpec.Namespace.
if _, err := helmClient.InstallOrUpgradeChart(context.Background(), &chartSpec); err != nil {
	panic(err)
}
Example (UseChartDirectory)
// Use an unpacked chart directory.
chartSpec := ChartSpec{
	ReleaseName: "etcd-operator",
	ChartName:   "/path/to/stable/etcd-operator",
	Namespace:   "default",
}

if _, err := helmClient.InstallOrUpgradeChart(context.Background(), &chartSpec); err != nil {
	panic(err)
}
Example (UseLocalChartArchive)
// Use an archived chart directory.
chartSpec := ChartSpec{
	ReleaseName: "etcd-operator",
	ChartName:   "/path/to/stable/etcd-operator.tar.gz",
	Namespace:   "default",
}

if _, err := helmClient.InstallOrUpgradeChart(context.Background(), &chartSpec); err != nil {
	panic(err)
}
Example (UseURL)
// Use an archived chart directory via URL.
chartSpec := ChartSpec{
	ReleaseName: "etcd-operator",
	ChartName:   "http://helm.whatever.com/repo/etcd-operator.tar.gz",
	Namespace:   "default",
}

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

func (*HelmClient) ListDeployedReleases

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

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

Example
// List all deployed releases.
if _, err := helmClient.ListDeployedReleases(); err != nil {
	panic(err)
}

func (*HelmClient) ListReleasesByStateMask

func (c *HelmClient) ListReleasesByStateMask(states action.ListStates) ([]*release.Release, error)

ListReleasesByStateMask lists all releases filtered by stateMask. Namespace and other context is provided via the client.Options struct when instantiating a client.

func (*HelmClient) RollbackRelease

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

RollbackRelease implicitly rolls back a release to the last revision.

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

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

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",
}

// Uninstall the chart release.
// Note that helmclient.Options.Namespace should ideally match the namespace in chartSpec.Namespace.
if err := helmClient.UninstallRelease(&chartSpec); err != nil {
	panic(err)
}

func (*HelmClient) UninstallReleaseByName

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

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

Example
// Uninstall a release by name.
if err := helmClient.UninstallReleaseByName("etcd-operator"); err != nil {
	panic(err)
}

func (*HelmClient) UpgradeChart

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

UpgradeChart upgrades the provided chart and returns the corresponding release. Namespace and other context is provided via the client.Options struct when instantiating a client.

type HelmTemplateOptions

type HelmTemplateOptions struct {
	KubeVersion *chartutil.KubeVersion
	// APIVersions defined here will be appended to the default list helm provides
	APIVersions chartutil.VersionSet
}

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
	DebugLog         action.DebugLog
	RegistryConfig   string
	Output           io.Writer
	// PlainHttp forces the registry client to establish plain http connections. This option will override by InsecureTls by using HTTP traffic.
	PlainHttp bool
	// InsecureTls allows invalid or selfsigned certificates to be used. This option may be overridden by PlainHttp which forces HTTP traffic.
	InsecureTls bool
}

Options defines the options of a client. If Output is not set, os.Stdout will be used.

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, opts ...RESTClientOption) *RESTClientGetter

NewRESTClientGetter returns a RESTClientGetter using the provided 'namespace', 'kubeConfig' and 'restConfig'.

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

func (*RESTClientGetter) ToDiscoveryClient

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

ToDiscoveryClient returns a CachedDiscoveryInterface that can be used as a discovery client.

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 RESTClientOption

type RESTClientOption func(*rest.Config)

RESTClientOption is a function that can be used to set the RESTClientOptions of a HelmClient.

type RestConfClientOptions

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

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

type RollBack

type RollBack interface {
	RollbackRelease(spec *ChartSpec) error
}

type TagResolver

type TagResolver interface {
	Tags(ref string) ([]string, error)
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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