helm

package module
v0.0.0-...-fee1c07 Latest Latest
Warning

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

Go to latest
Published: Aug 5, 2025 License: MIT Imports: 16 Imported by: 0

README

go-helm-toolkit

HELM client helpers and wrappers used by other Adevinta tools & operators.

Overview

The go-helm-toolkit is a Go library that provides a clean, type-safe interface for interacting with Helm charts and repositories. It abstracts the complexity of Helm CLI operations and provides a consistent API for common Helm operations like installing, upgrading, templating, and managing charts.

Features

  • Helm 3 Support: Full support for Helm 3.x operations
  • Type-Safe Interface: Clean Go interface for Helm operations
  • Chart Discovery: Utilities to discover and scan chart directories
  • Metadata Loading: Parse and work with Chart.yaml metadata
  • Test Utilities: Helper functions for testing Helm chart operations
  • Repository Management: Add and update Helm repositories
  • Version Management: Support for multiple Helm versions
  • Flag System: Flexible flag system for customizing Helm operations

Installation

go get github.com/adevinta/go-helm-toolkit

Usage

Basic Operations
package main

import (
    "io"
    "log"
    
    "github.com/adevinta/go-helm-toolkit"
)

func main() {
    // Get default Helm client
    h, err := helm.Default()
    if err != nil {
        log.Fatal(err)
    }
    
    // Template a chart
    reader, err := h.Template("my-namespace", "my-release", "./my-chart")
    if err != nil {
        log.Fatal(err)
    }
    
    // Install a chart
    err = h.Install("my-namespace", "my-release", "./my-chart", 
        helm.Values("values.yaml"),
        helm.Version("1.0.0"))
    if err != nil {
        log.Fatal(err)
    }
    
    // Upgrade a chart
    err = h.Update("my-namespace", "my-release", "./my-chart")
    if err != nil {
        log.Fatal(err)
    }
    
    // Delete a release
    err = h.Delete("my-namespace", "my-release")
    if err != nil {
        log.Fatal(err)
    }
}
Repository Operations
// Add a repository
err := h.RepoAdd("stable", "https://kubernetes-charts.storage.googleapis.com",
    helm.RepoUsername("user"),
    helm.RepoPassword("pass"))

// Update repositories
err := h.RepoUpdate()
Chart Discovery
// Discover all charts in a directory
for chartDir := range helm.DiscoverChartDirs("/path/to/charts") {
    fmt.Printf("Found chart: %s\n", chartDir)
}

// Discover test files in a chart
for testFile := range helm.DiscoverChartTests("/path/to/chart") {
    fmt.Printf("Found test: %s\n", testFile)
}
Metadata Operations
// Load chart metadata
metadata, err := helm.LoadMetadata("/path/to/chart")
if err != nil {
    log.Fatal(err)
}

fmt.Printf("Chart name: %s\n", metadata.Name)
fmt.Printf("Chart version: %s\n", metadata.Version)
Using Flags

The toolkit provides a flexible flag system for customizing Helm operations:

// Available flags
helm.Debug()                    // Enable debug output
helm.UpgradeInstall()           // Install if not exists
helm.Values("values.yaml")      // Specify values file
helm.RepoUsername("user")       // Repository username
helm.RepoPassword("pass")       // Repository password
helm.Version("1.0.0")          // Specify chart version
Testing

The toolkit includes test utilities for writing Helm chart tests:

package main

import (
    "context"
    "testing"
    
    "github.com/adevinta/go-helm-toolkit"
    "github.com/adevinta/go-helm-toolkit/testutils"
    "github.com/stretchr/testify/require"
)

func TestChartInstallation(t *testing.T) {
    h, err := helm.Default()
    require.NoError(t, err)
    
    // Install and test a chart
    helmtestutils.InstallFilteredHelmChart(t, context.Background(), client, 
        "test-namespace", "release-name", "examples/hello-world", 
        k8stestutils.ExtractObjectName(k8stestutils.WithKind("Deployment"), &name))
}

API Reference

Core Interface
type Helm interface {
    Template(namespace, release, chart string, flags ...Flag) (io.Reader, error)
    Install(namespace, release, chart string, flags ...Flag) error
    Update(namespace, release, chart string, flags ...Flag) error
    Package(chart string, flags ...Flag) error
    UpdateDeps(chart string) error
    Test(namespace, release string) error
    Delete(namespace, release string) error
    Init() error
    RepoAdd(name, url string, flags ...Flag) error
    RepoUpdate() error
    Version() string
}
Metadata Types
type Metadata struct {
    Name        string                 `json:"name,omitempty"`
    Version     string                 `json:"version,omitempty"`
    Description string                 `json:"description,omitempty"`
    APIVersion  string                 `json:"apiVersion,omitempty"`
    AppVersion  string                 `json:"appVersion,omitempty"`
    // ... other fields
}

Dependencies

This toolkit depends on several Adevinta internal packages:

  • github.com/adevinta/go-k8s-toolkit - Kubernetes utilities
  • github.com/adevinta/go-system-toolkit - System utilities
  • github.com/adevinta/go-testutils-toolkit - Testing utilities

Contributing

  1. Fork the repository
  2. Create a feature branch
  3. Make your changes
  4. Add tests for new functionality
  5. Submit a pull request

License

This project is part of Adevinta's internal tooling ecosystem.

Documentation

Index

Constants

View Source
const DefaultHelmVersion = "v3.18.4"

Variables

This section is empty.

Functions

func DiscoverChartDirs

func DiscoverChartDirs(path string) <-chan string

func DiscoverChartTests

func DiscoverChartTests(path string) <-chan string

func Download

func Download(version, dest string) error

func Supported

func Supported() <-chan Helm

Types

type Dependency

type Dependency struct {
	// Name is the name of the dependency.
	//
	// This must mach the name in the dependency's Chart.yaml.
	Name string `json:"name"`
	// Version is the version (range) of this chart.
	//
	// A lock file will always produce a single version, while a dependency
	// may contain a semantic version range.
	Version string `json:"version,omitempty"`
	// The URL to the repository.
	//
	// Appending `index.yaml` to this string should result in a URL that can be
	// used to fetch the repository index.
	Repository string `json:"repository"`
	// A yaml path that resolves to a boolean, used for enabling/disabling charts (e.g. subchart1.enabled )
	Condition string `json:"condition,omitempty"`
	// Tags can be used to group charts for enabling/disabling together
	Tags []string `json:"tags,omitempty"`
	// Enabled bool determines if chart should be loaded
	Enabled bool `json:"enabled,omitempty"`
	// ImportValues holds the mapping of source values to parent key to be imported. Each item can be a
	// string or pair of child/parent sublist items.
	ImportValues []interface{} `json:"import-values,omitempty"`
	// Alias usable alias to be used for the chart
	Alias string `json:"alias,omitempty"`
}

Dependency describes a chart upon which another chart depends.

Dependencies can be used to express developer intent, or to capture the state of a chart.

type Flag

type Flag func() []string

func Debug

func Debug() Flag

func RepoPassword

func RepoPassword(password string) Flag

func RepoUsername

func RepoUsername(username string) Flag

func UpgradeInstall

func UpgradeInstall() Flag

func Values

func Values(path string) Flag

func Version

func Version(v string) Flag

type Helm

type Helm interface {
	Template(namespace, release, chart string, flags ...Flag) (io.Reader, error)
	Install(namespace, release, chart string, flags ...Flag) error
	Update(namespace, release, chart string, flags ...Flag) error
	Package(chart string, flags ...Flag) error
	UpdateDeps(chart string) error
	Test(namespace, release string) error
	Delete(namespace, release string) error
	Init() error
	RepoAdd(name, url string, flags ...Flag) error
	RepoUpdate() error
	Version() string
}

func Default

func Default() (Helm, error)

type Helm3

type Helm3 struct {
	Path        string
	APIVersions []string
	GlobalFlags []string
}

func (*Helm3) Delete

func (h *Helm3) Delete(namespace, release string) error

func (*Helm3) Init

func (h *Helm3) Init() error

func (*Helm3) Install

func (h *Helm3) Install(namespace, release, chart string, flags ...Flag) error

func (*Helm3) Package

func (h *Helm3) Package(chart string, flags ...Flag) error

func (*Helm3) RepoAdd

func (h *Helm3) RepoAdd(name, url string, flags ...Flag) error

func (*Helm3) RepoUpdate

func (h *Helm3) RepoUpdate() error

func (*Helm3) Template

func (h *Helm3) Template(namespace, release, chart string, flags ...Flag) (io.Reader, error)

func (*Helm3) Test

func (h *Helm3) Test(namespace, release string) error

func (*Helm3) Update

func (h *Helm3) Update(namespace, release, chart string, flags ...Flag) error

func (*Helm3) UpdateDeps

func (h *Helm3) UpdateDeps(chart string) error

func (*Helm3) Version

func (h *Helm3) Version() string

type Maintainer

type Maintainer struct {
	// Name is a user name or organization name
	Name string `json:"name,omitempty"`
	// Email is an optional email address to contact the named maintainer
	Email string `json:"email,omitempty"`
	// URL is an optional URL to an address for the named maintainer
	URL string `json:"url,omitempty"`
}

Maintainer describes a Chart maintainer.

type Metadata

type Metadata struct {
	// The name of the chart. Required.
	Name string `json:"name,omitempty"`
	// The URL to a relevant project page, git repo, or contact person
	Home string `json:"home,omitempty"`
	// Source is the URL to the source code of this chart
	Sources []string `json:"sources,omitempty"`
	// A SemVer 2 conformant version string of the chart. Required.
	Version string `json:"version,omitempty"`
	// A one-sentence description of the chart
	Description string `json:"description,omitempty"`
	// A list of string keywords
	Keywords []string `json:"keywords,omitempty"`
	// A list of name and URL/email address combinations for the maintainer(s)
	Maintainers []*Maintainer `json:"maintainers,omitempty"`
	// The URL to an icon file.
	Icon string `json:"icon,omitempty"`
	// The API Version of this chart. Required.
	APIVersion string `json:"apiVersion,omitempty"`
	// The condition to check to enable chart
	Condition string `json:"condition,omitempty"`
	// The tags to check to enable chart
	Tags string `json:"tags,omitempty"`
	// The version of the application enclosed inside of this chart.
	AppVersion string `json:"appVersion,omitempty"`
	// Whether or not this chart is deprecated
	Deprecated bool `json:"deprecated,omitempty"`
	// Annotations are additional mappings uninterpreted by Helm,
	// made available for inspection by other applications.
	Annotations map[string]string `json:"annotations,omitempty"`
	// KubeVersion is a SemVer constraint specifying the version of Kubernetes required.
	KubeVersion string `json:"kubeVersion,omitempty"`
	// Dependencies are a list of dependencies for a chart.
	Dependencies []*Dependency `json:"dependencies,omitempty"`
	// Specifies the chart type: application or library
	Type string `json:"type,omitempty"`
}

Metadata for a Chart file. This models the structure of a Chart.yaml file.

func LoadMetadata

func LoadMetadata(path string) (*Metadata, error)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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