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
- Variables
- func CleanupExpiredCharts()
- func ClearChartCache() error
- func CreateChartCopy(sourcePath string) (string, error)
- func GenerateCacheKey(manifest *manifest.Manifest) (string, error)
- func GenerateReleaseName(projectName, environmentName string) string
- func GetCachedChart(cacheKey string) (string, bool)
- func GetChartCacheStats() (count int, totalSize int64)
- func MapManifestToChartValues(m *manifest.Manifest, desiredEnvironment string) (map[string]any, error)
- func PrepareChart(ctx context.Context, manifest *manifest.Manifest, desiredEnvironment string) (string, error)
- func SetCachedChart(cacheKey, chartPath string)
- type ChartCache
- type ChartCacheInfo
- type ChartData
- type Client
- func (c *Client) DeleteRelease(ctx context.Context, project, environment string) error
- func (c *Client) GetRelease(ctx context.Context, project, environment string) (*v1.Release, error)
- func (c *Client) GetReleaseHistory(ctx context.Context, project, environment string) ([]*v1.Release, error)
- func (c *Client) InstallApp(ctx context.Context, manifest *manifest.Manifest, environment string, ...) error
- func (c *Client) IsReachable() error
- func (c *Client) ListReleases(ctx context.Context, selector labels.Selector) ([]*v1.Release, error)
- func (c *Client) RollbackRelease(ctx context.Context, releaseName string, revision int, timeout time.Duration) error
- type Option
- func WithDebug(keep bool) Option
- func WithExtraKubeconfigPaths(paths ...string) Option
- func WithKubeContext(kubeContext string) Option
- func WithKubeconfig(kubeconfig string) Option
- func WithNamespace(namespace string) Option
- func WithStorageDriver(driver string) Option
- func WithTimeout(timeout time.Duration) Option
Constants ¶
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 ¶
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") )
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 ¶
CreateChartCopy creates a copy of a cached chart directory to avoid conflicts
func GenerateCacheKey ¶
GenerateCacheKey creates a cache key from manifest and chart template hashes.
func GenerateReleaseName ¶
GenerateReleaseName returns the Helm release name for project and environment. Format: PROJECT_NAME-ENVIRONMENT_NAME.
func GetCachedChart ¶
GetCachedChart retrieves a cached chart if it exists and is valid
func GetChartCacheStats ¶
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 ¶
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 ¶
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 ¶
DeleteRelease uninstalls the given release.
func (*Client) GetRelease ¶
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 ¶
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 ¶
ListReleases returns release details in the current namespace.
type Option ¶
type Option func(*Client)
Option is a functional option for configuring the Helm client
func WithExtraKubeconfigPaths ¶
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 ¶
WithKubeContext sets the Kubernetes context to use, overriding the kubeconfig's current context.
func WithKubeconfig ¶
WithKubeconfig sets the path to the kubeconfig file
func WithNamespace ¶
WithNamespace sets the Kubernetes namespace for Helm operations
func WithStorageDriver ¶
WithStorageDriver sets the Helm storage driver (secret, configmap, or memory)
func WithTimeout ¶
WithTimeout sets the default timeout for Helm operations