Documentation
¶
Index ¶
- Variables
- func MatchRepositoryPattern(repository, pattern string) bool
- func PackageAndPush(ctx context.Context, ch *Chart, ociRef string) (string, error)
- type Chart
- type ChartImage
- type ChartSourceSpec
- type CommandRunner
- type Dependency
- type ImageMapping
- type Metadata
- type OverrideSpec
- type ValuePathMapping
Constants ¶
This section is empty.
Variables ¶
var DownloadChart = func(ctx context.Context, name, version, repository string) (*Chart, error) { tmpDir, err := os.MkdirTemp("", "copa-helm-pull-*") if err != nil { return nil, fmt.Errorf("create chart download directory: %w", err) } defer os.RemoveAll(tmpDir) args := []string{"pull", "--destination", tmpDir, "--version", version} if strings.HasPrefix(repository, "oci://") { args = append(args, strings.TrimSuffix(repository, "/")+"/"+name) } else { args = append(args, name, "--repo", repository) } if _, err := RunHelm(ctx, args...); err != nil { return nil, fmt.Errorf("pull chart %q v%s from %s: %w", name, version, repository, err) } archivePath, err := findChartArchivePath(tmpDir, name) if err != nil { return nil, err } archive, err := os.ReadFile(archivePath) if err != nil { return nil, fmt.Errorf("read downloaded chart archive: %w", err) } return loadChart(archive) }
DownloadChart downloads and reads a chart archive with the Helm CLI.
var PackageAndPushFunc = packageAndPush
PackageAndPushFunc is replaceable in tests.
var RenderChart = func(ctx context.Context, ch *Chart) (string, error) { tmpDir, err := os.MkdirTemp("", "copa-helm-template-*") if err != nil { return "", fmt.Errorf("create chart render directory: %w", err) } defer os.RemoveAll(tmpDir) archivePath := filepath.Join(tmpDir, ch.Metadata.Name+".tgz") if err := os.WriteFile(archivePath, ch.Archive, 0o600); err != nil { return "", fmt.Errorf("write chart archive for rendering: %w", err) } output, err := RunHelm(ctx, "template", ch.Metadata.Name, archivePath, "--include-crds") if err != nil { return "", fmt.Errorf("render chart %q: %w", ch.Metadata.Name, err) } return string(output), nil }
RenderChart renders default chart values, including CRDs and hooks, with the Helm CLI.
Functions ¶
func MatchRepositoryPattern ¶
MatchRepositoryPattern checks if a repository matches a pattern key using exact match first, then suffix matching to handle registry prefixes. For example, pattern "nginx" matches repository "docker.io/library/nginx".
Types ¶
type Chart ¶
Chart is the local representation needed for discovery and wrapper generation.
func BuildPatchedChart ¶
func BuildPatchedChart(original *Chart, chartSpec ChartSourceSpec, mappings []ImageMapping, valuePaths []ValuePathMapping) (*Chart, error)
BuildPatchedChart creates local wrapper chart files and embeds the original archive.
type ChartImage ¶
type ChartImage struct {
Repository string // e.g., "docker.io/timberio/vector"
Tag string // e.g., "0.53.0-distroless-libc"
}
ChartImage represents a container image reference discovered from a Helm chart.
func ApplyOverrides ¶
func ApplyOverrides(images []ChartImage, overrides map[string]OverrideSpec) []ChartImage
ApplyOverrides applies tag variant overrides to a list of chart-discovered images. The overrides map key is an image name pattern (e.g., "timberio/vector"). Matching is performed as an exact key match first, then as a suffix match to handle images prefixed with a registry (e.g., "docker.io/timberio/vector"). Returns a new slice with overrides applied (input is not mutated).
func DiscoverChartImages ¶
func DiscoverChartImages(ctx context.Context, ch *Chart, overrides map[string]OverrideSpec) ([]ChartImage, error)
DiscoverChartImages renders and extracts all container images from a chart.
func ExtractImages ¶
func ExtractImages(renderedManifests string) ([]ChartImage, error)
ExtractImages parses rendered Kubernetes YAML manifests and extracts all container image references, including init containers and sidecar containers. It deduplicates by full image reference (repository:tag).
type ChartSourceSpec ¶
type ChartSourceSpec struct{ Name, Version, Repository string }
type CommandRunner ¶
CommandRunner runs the Helm CLI without invoking a shell.
var RunHelm CommandRunner = runHelm
RunHelm is replaceable in tests.
type Dependency ¶
type Dependency struct {
Name string `yaml:"name"`
Version string `yaml:"version"`
Repository string `yaml:"repository"`
}
Dependency describes a wrapper chart dependency.
type ImageMapping ¶
type Metadata ¶
type Metadata struct {
APIVersion string `yaml:"apiVersion"`
Name string `yaml:"name"`
Version string `yaml:"version"`
Description string `yaml:"description,omitempty"`
Type string `yaml:"type,omitempty"`
Annotations map[string]string `yaml:"annotations,omitempty"`
Dependencies []Dependency `yaml:"dependencies,omitempty"`
}
Metadata is the chart metadata Copa needs.
type OverrideSpec ¶
OverrideSpec defines a tag variant substitution for chart-discovered images. From and To are substrings of the image tag (e.g., From: "distroless-libc", To: "debian").
type ValuePathMapping ¶
type ValuePathMapping struct {
ImageRepo string
ImageTag string
RepositoryPath string
TagPath string
RegistryPath string
FullReference bool
}
func ResolveImageValuePaths ¶
func ResolveImageValuePaths(chartValues map[string]interface{}, images []ChartImage, explicitPaths map[string]string) ([]ValuePathMapping, error)