helm

package
v0.1.3 Latest Latest
Warning

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

Go to latest
Published: Jun 6, 2026 License: Apache-2.0 Imports: 30 Imported by: 0

Documentation

Overview

Package helm generates Helm charts from Deployah manifests and drives install, upgrade, list, and delete operations against a cluster.

PrepareChart renders templates and values for an environment. Client wraps Helm v4 actions with Deployah-specific release naming, labels, and caching through ChartCache.

Index

Constants

View Source
const (
	// ChartNameTemplate is the template for generated chart names
	ChartNameTemplate = "%s-%s"

	// ReleaseNameTemplate is the template for Helm release names
	ReleaseNameTemplate = "%s-%s"

	// TempChartPrefix is the prefix for temporary chart directories
	TempChartPrefix = "deployah-chart-"

	// ChartYamlTemplate is the template file name for Chart.yaml
	ChartYamlTemplate = "Chart.yaml.gotmpl"

	// ValuesYamlFile is the name of the values file
	ValuesYamlFile = "values.yaml"
)

Chart and Template Constants

Variables

View Source
var (
	// ErrClusterUnreachable is returned when the Kubernetes cluster cannot be reached.
	ErrClusterUnreachable = errors.New("kubernetes cluster unreachable")
	// ErrReleaseNotFound is returned when a Helm release does not exist.
	ErrReleaseNotFound = errors.New("release not found")
	// ErrReleaseAlreadyExists is returned when a Helm release already exists.
	ErrReleaseAlreadyExists = errors.New("release already exists")
	// ErrReleasePending is returned when a Helm release has an operation in progress.
	ErrReleasePending = errors.New("another operation is in progress")
)
View Source
var ChartTemplateFS embed.FS

ChartTemplateFS embeds the chart directory. Underscore-prefixed templates were renamed so directory embedding includes them without explicit listing.

Functions

func CleanupExpiredCharts

func CleanupExpiredCharts()

CleanupExpiredCharts removes expired chart cache entries

func ClearChartCache

func ClearChartCache() error

ClearChartCache clears all cached charts and removes their directories

func CreateChartCopy

func CreateChartCopy(sourcePath string) (string, error)

CreateChartCopy creates a copy of a cached chart directory to avoid conflicts

func GenerateCacheKey

func GenerateCacheKey(manifest *manifest.Manifest) (string, error)

GenerateCacheKey creates a cache key from manifest and chart template hashes.

func GenerateReleaseName

func GenerateReleaseName(projectName, environmentName string) string

GenerateReleaseName returns the Helm release name for project and environment. Format: PROJECT_NAME-ENVIRONMENT_NAME.

func GetCachedChart

func GetCachedChart(cacheKey string) (string, bool)

GetCachedChart retrieves a cached chart if it exists and is valid

func GetChartCacheStats

func GetChartCacheStats() (count int, totalSize int64)

GetChartCacheStats returns statistics about the chart cache

func MapManifestToChartValues

func MapManifestToChartValues(m *manifest.Manifest, desiredEnvironment string) (map[string]any, error)

MapManifestToChartValues converts a manifest into Helm chart values for the given environment.

func PrepareChart

func PrepareChart(ctx context.Context, manifest *manifest.Manifest, desiredEnvironment string) (string, error)

PrepareChart expands the embedded chart into a temporary directory, rendering .gotmpl files with Go templates and Sprig functions. It returns the prepared chart root directory. Uses caching to avoid regenerating identical charts.

func SetCachedChart

func SetCachedChart(cacheKey, chartPath string)

SetCachedChart stores a chart path in the cache

Types

type ChartCache

type ChartCache struct {
	Path      string
	CreatedAt time.Time
}

ChartCache represents a cached chart entry

type ChartCacheInfo

type ChartCacheInfo struct {
	Count     int      `json:"count"`
	TotalSize int64    `json:"totalSize"`
	ChartHash string   `json:"chartHash"`
	TTL       string   `json:"ttl"`
	CacheKeys []string `json:"cacheKeys,omitempty"`
}

ChartCacheInfo provides detailed information about the chart cache

func GetChartCacheInfo

func GetChartCacheInfo() (*ChartCacheInfo, error)

GetChartCacheInfo returns detailed information about the chart cache

type ChartData

type ChartData struct {
	Chart struct {
		Name        string
		Description string
		Version     string
		AppVersion  string
	}
	Values   map[string]any     // For values.yaml templating
	Manifest *manifest.Manifest // Added for dynamic sub-charts
}

ChartData holds values substituted in templates, including arbitrary values for values.yaml. .Values can be used in values.yaml.gotmpl for flexible templating.

type Client

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

Client wraps Helm action configuration for Deployah operations.

func NewClient

func NewClient(opts ...Option) (*Client, error)

NewClient initializes Helm action configuration with functional options. Default storage driver is "secret" if not specified. Default timeout is 5 minutes if not specified.

func (*Client) DeleteRelease

func (c *Client) DeleteRelease(ctx context.Context, project, environment string) error

DeleteRelease uninstalls the given release.

func (*Client) GetRelease

func (c *Client) GetRelease(ctx context.Context, project, environment string) (*v1.Release, error)

GetRelease retrieves a release by project and environment.

func (*Client) GetReleaseHistory

func (c *Client) GetReleaseHistory(ctx context.Context, project, environment string) ([]*v1.Release, error)

GetReleaseHistory returns the history of a specific release.

func (*Client) InstallApp

func (c *Client) InstallApp(ctx context.Context, manifest *manifest.Manifest, environment string, dryRun bool) error

InstallApp installs or upgrades the app using the embedded chart.

func (*Client) IsReachable

func (c *Client) IsReachable() error

IsReachable reports whether the configured Kubernetes cluster is reachable.

NOTE: this is also a workaround for helm/helm#32183. Helm v4.2.0 panics on the second IsReachable call when the first one fails (typed-nil cached in getKubeClient). Calling this once before InstallApp prevents InstallApp from ever hitting the second call against a poisoned client.

func (*Client) ListReleases

func (c *Client) ListReleases(ctx context.Context, selector labels.Selector) ([]*v1.Release, error)

ListReleases returns release details in the current namespace.

func (*Client) RollbackRelease

func (c *Client) RollbackRelease(ctx context.Context, releaseName string, revision int, timeout time.Duration) error

RollbackRelease rolls back a release to a previous revision.

type Option

type Option func(*Client)

Option is a functional option for configuring the Helm client

func WithDebug

func WithDebug(keep bool) Option

WithDebug controls whether to keep temporary chart directories.

func WithExtraKubeconfigPaths

func WithExtraKubeconfigPaths(paths ...string) Option

WithExtraKubeconfigPaths appends additional kubeconfig file paths so their contexts are available alongside the default kubeconfig. This is ignored when WithKubeconfig is also set, because an explicit path takes full precedence and makes extra paths redundant.

func WithKubeContext

func WithKubeContext(kubeContext string) Option

WithKubeContext sets the Kubernetes context to use, overriding the kubeconfig's current context.

func WithKubeconfig

func WithKubeconfig(kubeconfig string) Option

WithKubeconfig sets the path to the kubeconfig file

func WithNamespace

func WithNamespace(namespace string) Option

WithNamespace sets the Kubernetes namespace for Helm operations

func WithStorageDriver

func WithStorageDriver(driver string) Option

WithStorageDriver sets the Helm storage driver (secret, configmap, or memory)

func WithTimeout

func WithTimeout(timeout time.Duration) Option

WithTimeout sets the default timeout for Helm operations

Jump to

Keyboard shortcuts

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