package helm

import "github.com/oslokommune/okctl/pkg/helm"

Package helm implements a helm client, this is based on code from: - https://github.com/PrasadG193/helm-clientgo-example - https://github.com/helm/helm

Index

Constants

const (
	// DefaultHelmDriver is set to secrets, which is the default
	// for Helm 3: https://helm.sh/docs/topics/advanced/#storage-backends
	DefaultHelmDriver = "secrets"
	// DefaultHelmLockExt is the extension used to create a file lock
	DefaultHelmLockExt = ".lock"
	// DefaultHelmLockTimeout is the default timeout in seconds
	DefaultHelmLockTimeout = 120 * time.Second
)

Functions

func IsChartInstallable

func IsChartInstallable(ch *chartPkg.Chart) error

IsChartInstallable determines if a chart can be installed or not

func SplitEnv

func SplitEnv(envs []string) map[string]string

SplitEnv returns the split envvars

Types

type Chart

type Chart struct {
	RepositoryName string
	RepositoryURL  string

	ReleaseName string
	Version     string
	Chart       string
	Namespace   string

	Timeout time.Duration

	Values interface{}
}

Chart contains the state for installing a chart

func Mysql

func Mysql(values interface{}) *Chart

Mysql demonstrates how a chart can be specified

func (*Chart) DeleteConfig

func (c *Chart) DeleteConfig() *DeleteConfig

DeleteConfig returns a valid delete config

func (*Chart) InstallConfig

func (c *Chart) InstallConfig() (*InstallConfig, error)

InstallConfig returns a valid install config

func (*Chart) ValuesYAML

func (c *Chart) ValuesYAML() ([]byte, error)

ValuesYAML returns the values file serialised to the yaml format

type Config

type Config struct {
	// HomeDir allows us to modify where $HOME/.kube
	// ends up
	HomeDir string
	Path    string

	HelmPluginsDirectory string
	HelmRegistryConfig   string
	HelmRepositoryConfig string
	HelmRepositoryCache  string
	HelmBaseDir          string

	Debug       bool
	DebugOutput io.Writer
}

Config lists all configuration variables that must be set to configure the environment for helm correctly

func (*Config) Envs

func (c *Config) Envs() map[string]string

Envs returns the config as a helm compatible set of env vars

type DeleteConfig

type DeleteConfig struct {
	// ReleaseName is the name given to the release in Kubernetes
	ReleaseName string
	// Namespace is the namespace the release will be removed from
	Namespace string
	// Timeout determines how long we will wait for the delete to succeed
	Timeout time.Duration
}

DeleteConfig defines the variables that must be set to remove a chart

type Deleter

type Deleter interface {
	Delete(kubeConfigPath string, cfg *DeleteConfig) error
}

Deleter defines the interface for removing a released helm chart

type FindConfig

type FindConfig struct {
	// ReleaseName is the name given to the release in Kubernetes
	ReleaseName string
	// Namespace is the namespace the release will be looked for in
	Namespace string
	// Timeout determines how long we will wait for the location to succeed
	Timeout time.Duration
}

FindConfig defines the variables that must be set to find a chart

type Finder

type Finder interface {
	Find(kubeConfigPath string, cfg *FindConfig) (*release.Release, error)
}

Finder defines the interface for finding a released helm chart

type Helm

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

Helm stores all state required for running helm tasks

func New

func New(config *Config, auth aws.Authenticator, fs *afero.Afero) *Helm

New initialises a new Helm operator

func (*Helm) Delete

func (h *Helm) Delete(kubeConfigPath string, cfg *DeleteConfig) error

Delete a released Helm chart, functionality is comparable to: - https://helm.sh/docs/helm/helm_uninstall/ nolint: funlen

func (*Helm) Find

func (h *Helm) Find(kubeConfigPath string, cfg *FindConfig) (*release.Release, error)

Find returns an existing helm release from the cluster

func (*Helm) Install

func (h *Helm) Install(kubeConfigPath string, cfg *InstallConfig) (*release.Release, error)

Install a chart, comparable to: https://helm.sh/docs/helm/helm_install/ though we have not implemented all the functionality found there Some details to consider about CRDs: - https://helm.sh/docs/chart_best_practices/custom_resource_definitions/#some-caveats-and-explanations

func (*Helm) RepoAdd

func (h *Helm) RepoAdd(name, url string) error

RepoAdd adds repo with given name and url nolint: funlen

func (*Helm) RepoUpdate

func (h *Helm) RepoUpdate() error

RepoUpdate updates charts for all helm repos

type Helmer

type Helmer interface {
	RepoAdder
	RepoUpdater
	Installer
	Deleter
	Finder
}

Helmer defines all available helm operations

type InstallConfig

type InstallConfig struct {
	// ReleaseName is the name given to the release in Kubernetes
	ReleaseName string
	// Version is the version of the chart to install
	Version string
	// Chart is the name of the chart to install
	Chart string
	// Repo is the name of the repository from which to install
	Repo string
	// Namespace is the namespace the chart will be installed in
	Namespace string
	// ValuesBody is a yaml encoded byte array of the values.yaml file
	ValuesBody []byte
	// Timeout determines how long we will wait for the deployment to succeed
	Timeout time.Duration
}

InstallConfig defines the variables that must be set to install a chart

func (*InstallConfig) RepoChart

func (c *InstallConfig) RepoChart() string

RepoChart returns the repo/[chart] string

func (*InstallConfig) ValuesMap

func (c *InstallConfig) ValuesMap() (map[string]interface{}, error)

ValuesMap returns the values

type Installer

type Installer interface {
	Install(kubeConfigPath string, cfg *InstallConfig) (*release.Release, error)
}

Installer defines the interface for installing a helm chart

type MysqlPersistence

type MysqlPersistence struct {
	Enabled bool `yaml:"enabled"`
}

MysqlPersistence demonstrates how the values can be set

type MysqlValues

type MysqlValues struct {
	MysqlRootPassword string           `yaml:"mysqlRootPassword"`
	Persistence       MysqlPersistence `yaml:"persistence"`
	ImagePullPolicy   string           `yaml:"imagePullPolicy"`
}

MysqlValues demonstrates how the values can be set

type RawMarshaller

type RawMarshaller interface {
	RawYAML() ([]byte, error)
}

RawMarshaller provides an interface for returning raw YAML

type RepoAdder

type RepoAdder interface {
	RepoAdd(repoName, url string) error
}

RepoAdder defines the interface for adding a helm repository

type RepoUpdater

type RepoUpdater interface {
	RepoUpdate() error
}

RepoUpdater defines the interface for updating the helm repositories

type RestoreEnvFn

type RestoreEnvFn func() error

RestoreEnvFn can be deferred in the calling function and will return the environment to its original state

func EstablishEnv

func EstablishEnv(envs map[string]string) (RestoreEnvFn, error)

EstablishEnv provides functionality for setting a safe environment, this is required, because helm for some reason, loves fetching everything from environment variables

type UnlockFn

type UnlockFn func() error

UnlockFn can be deferred in the calling function to unlock the file

func Lock

func Lock(file string) (UnlockFn, error)

Lock a file to ensure no concurrent access

Source Files

helm.go

Directories

PathSynopsis
pkg/helm/charts
pkg/helm/charts/argocdPackage argocd provides a Helm chart for installing: - https://argoproj.github.io/argo-cd/ - https://github.com/argoproj/argo-helm
pkg/helm/charts/autoscalerPackage autoscaler provides a Helm chart for installing: - https://github.com/kubernetes/autoscaler/tree/master/charts/cluster-autoscaler
pkg/helm/charts/awslbcPackage awslbc provides a Helm chart for installing: - https://github.com/kubernetes-sigs/aws-load-balancer-controller - https://github.com/aws/eks-charts/tree/master/stable/aws-load-balancer-controller
pkg/helm/charts/blockstoragePackage blockstorage provides a Helm chart installing: - https://github.com/kubernetes-sigs/aws-ebs-csi-driver
pkg/helm/charts/externalsecretsPackage externalsecrets provides a helm chart for installing external-secrets: - https://external-secrets.github.io/kubernetes-external-secrets
pkg/helm/charts/kubepromstackPackage kubepromstack provides a helm chart for installing kube-prometheus-stack: - https://github.com/prometheus-community/helm-charts/tree/main/charts/kube-prometheus-stack
pkg/helm/charts/lokiPackage loki provides a Helm chart for installing: - https://github.com/grafana/helm-charts/tree/main/charts/loki - https://grafana.com/oss/loki/
pkg/helm/charts/promtailPackage promtail provides a Helm chart for installing: - https://github.com/grafana/helm-charts/tree/main/charts/promtail
pkg/helm/charts/tempoPackage tempo provides a Helm chart for installing: - https://github.com/grafana/helm-charts/tree/main/charts/tempo - https://grafana.com/oss/tempo/
Version
v0.0.106 (latest)
Published
Oct 21, 2022
Platform
linux/amd64
Imports
23 packages
Last checked
1 day ago

Tools for package owners.