Documentation
¶
Overview ¶
Package helm provides client-side Helm chart rendering from OCI registries and HTTP Helm repositories.
RenderChart pulls a chart and renders its templates using the Helm template engine — equivalent to `helm template` — returning multi-document YAML. No Kubernetes cluster connection is required. RenderOption (WithReleaseName, WithNamespace) overrides the default release identity ("release" in "default").
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func RenderChart ¶
func RenderChart(chartURL, version string, values map[string]any, opts ...RenderOption) ([]byte, error)
RenderChart pulls a Helm chart and renders it client-side (equivalent to `helm template`), returning multi-doc YAML.
OCI registries: chartURL must start with "oci://". Authentication uses the local Docker credential store (~/.docker/config.json).
HTTP repositories: chartURL must start with "http://" or "https://", with the chart name as the last path segment (e.g. "https://charts.example.com/myapp"). Only public unauthenticated repositories are supported; basic auth, client TLS, and other credential mechanisms are not.
version is the chart version tag (e.g. "1.16.5"). values are merged on top of the chart's default values. opts customizes the release identity (name, namespace); see WithReleaseName and WithNamespace. Without opts, rendering uses release "release" in namespace "default".
Example ¶
package main
import (
"fmt"
"github.com/go-kure/kure/pkg/stack/helm"
)
func main() {
manifests, err := helm.RenderChart(
"oci://registry.example.com/charts/cilium", // OCI chart URL
"1.16.5", // chart version
map[string]any{ // value overrides (merged on top of chart defaults)
"kubeProxyReplacement": true,
"ipam": map[string]any{
"mode": "kubernetes",
},
},
)
if err != nil {
panic(err)
}
// manifests is multi-doc YAML suitable for kubectl apply -f -
fmt.Print(string(manifests))
}
Output:
Example (Http) ¶
package main
import (
"fmt"
"github.com/go-kure/kure/pkg/stack/helm"
)
func main() {
manifests, err := helm.RenderChart(
"https://charts.bitnami.com/bitnami/redis", // repo base URL + chart name
"19.0.0",
map[string]any{"replicaCount": 3},
)
if err != nil {
panic(err)
}
fmt.Print(string(manifests))
}
Output:
Types ¶
type HookGroup ¶
HookGroup is a set of Helm manifests sharing the same hook phase and weight. Resources with no helm.sh/hook annotation have Phase="" and Weight=0 (main group).
func SplitByHookWeight ¶
SplitByHookWeight groups rendered Helm manifests by hook phase and weight for ordered FluxCD Kustomization generation. Groups are returned in execution order: pre-install, pre-upgrade, main (non-hook), post-install, post-upgrade, then any remaining unknown hook phases alphabetically.
Objects whose helm.sh/hook phase has no FluxCD lifecycle equivalent (pre-delete, post-delete, pre-rollback, post-rollback, test) are excluded. Comma-separated hook annotations (e.g. "pre-install,post-install") are treated as a single opaque phase string and placed in the unknown group.
Example ¶
package main
import (
"fmt"
"github.com/go-kure/kure/pkg/io"
"github.com/go-kure/kure/pkg/stack/helm"
)
func main() {
// Multi-doc YAML as RenderChart returns it
rendered := []byte(`apiVersion: batch/v1
kind: Job
metadata:
name: db-migrate
annotations:
helm.sh/hook: pre-install
helm.sh/hook-weight: "-5"
---
apiVersion: v1
kind: ConfigMap
metadata:
name: app-config
---
apiVersion: v1
kind: Pod
metadata:
name: app-test
annotations:
helm.sh/hook: test
`)
parsed, err := io.ParseYAML(rendered) // []client.Object
if err != nil {
panic(err)
}
groups := helm.SplitByHookWeight(parsed)
for _, g := range groups {
// each group becomes one FluxCD Kustomization, deployed in order
fmt.Printf("phase=%q weight=%d resources=%d\n", g.Phase, g.Weight, len(g.Resources))
}
}
Output: phase="pre-install" weight=-5 resources=1 phase="" weight=0 resources=1
type RenderOption ¶
type RenderOption func(*renderOptions)
RenderOption customizes the release identity used to render a chart. Without options, rendering uses release "release" in namespace "default" — the defaults renderChart always used prior to this option's introduction.
func WithNamespace ¶
func WithNamespace(namespace string) RenderOption
WithNamespace sets the release namespace used during rendering (e.g. for {{ .Release.Namespace }}).
func WithReleaseName ¶
func WithReleaseName(name string) RenderOption
WithReleaseName sets the release name used during rendering (e.g. for {{ .Release.Name }} and the generated resource name helpers).
Example ¶
package main
import (
"fmt"
"github.com/go-kure/kure/pkg/stack/helm"
)
func main() {
values := map[string]any{"kubeProxyReplacement": true}
manifests, err := helm.RenderChart(
"oci://registry.example.com/charts/cilium",
"1.16.5",
values,
helm.WithReleaseName("my-cilium"),
helm.WithNamespace("kube-system"),
)
if err != nil {
panic(err)
}
fmt.Print(string(manifests))
}
Output: