helmclient

package module
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: May 4, 2020 License: MIT Imports: 28 Imported by: 64

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/v3.1.2 and available under the MIT License:

GitHub license

Usage

import "github.com/mittwald/go-helm-client"

Construct a new Helm client, then use the various services on the client to manage helm chart repositories and releases:

package main

import (
	"github.com/mittwald/go-helm-client"
	"helm.sh/helm/v3/pkg/repo"
)

func main() {
	// Create a client
	helmClient, err := helmclient.New(&helmclient.Options{
		RepositoryCache:  "/tmp/.helmcache",
		RepositoryConfig: "/tmp/.helmrepo",
		Debug:            true,
		Linting:          true,
	})
	if err != nil {
		panic(err)
	}

	// Add needed chart-repos to the client
	err = helmClient.AddOrUpdateChartRepo(repo.Entry{
		Name: "stable",
		URL:  "https://kubernetes-charts.storage.googleapis.com",
	})
	if err != nil {
		panic(err)
	}

	// Define the chart you want to install
	chartSpec := helmclient.ChartSpec{
		ReleaseName: "etcd-operator",
		ChartName:   "stable/etcd-operator",
		Namespace:   "default",
		UpgradeCRDs: true,
		Wait:        true,
	}

	err = helmClient.InstallOrUpgradeChart(&chartSpec)
	if err != nil {
		panic(err)
	}
}

Alternatively, you can create a client via REST config:

helmClient, err := helmclient.NewClientFromRestConf(&restClientOpts)

or via Kubeconfig:

helmClient, err := helmclient.NewClientFromKubeConf()
Private chart repository

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

err := helmClient.AddOrUpdateChartRepo(repo.Entry{
    Name: "stable",
    URL:  "https://private-chart.somedomain.com",
    Username: "foo",
    Password: "bar",
})

Documentation

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

Documentation

Index

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

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 struct {
	Settings  *cli.EnvSettings
	Providers getter.Providers

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

Client defines the values of a helm client

func New

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

New returns a new Helm client with the provided options

func NewClientFromKubeConf

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

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

func NewClientFromRestConf

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

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

func (*Client) AddOrUpdateChartRepo

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

AddOrUpdateChartRepo adds or updates the provided helm chart repository

func (*Client) DeleteChartFromCache

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

DeleteChartFromCache deletes the provided chart from the client's cache

func (*Client) InstallOrUpgradeChart

func (c *Client) InstallOrUpgradeChart(spec *ChartSpec) error

InstallOrUpgradeChart triggers the installation of the provided chart. If the chart is already installed, trigger an upgrade instead

func (*Client) UninstallRelease

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

UninstallRelease uninstalls the provided release

func (*Client) UpdateChartRepos

func (c *Client) UpdateChartRepos() error

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

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
}

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

Jump to

Keyboard shortcuts

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