Documentation
¶
Overview ¶
Package shcv provides functionality to synchronize Helm chart values by analyzing template files and updating values files accordingly.
The package helps maintain Helm charts by automatically detecting all {{ .Values.* }} expressions in template files and ensuring they are properly defined in the values files. It uses atomic file operations to ensure data integrity and provides robust error handling.
Basic usage:
chart, err := shcv.NewChart("./my-chart")
if err != nil {
log.Fatal(err)
}
// Process the chart
if err := chart.LoadValueFiles(); err != nil {
log.Fatal(err)
}
if err := chart.FindTemplates(); err != nil {
log.Fatal(err)
}
if err := chart.ParseTemplates(); err != nil {
log.Fatal(err)
}
if err := chart.ProcessReferences(); err != nil {
log.Fatal(err)
}
if err := chart.UpdateValueFiles(); err != nil {
log.Fatal(err)
}
Configuration options:
chart, err := shcv.NewChart("./my-chart",
shcv.WithValuesFileNames([]string{"values.yaml", "values-prod.yaml"}),
shcv.WithTemplatesDir("custom-templates"),
shcv.WithVerbose(true),
)
Key features:
- Detects all Helm value references in template files
- Supports multiple values files
- Supports nested value structures
- Handles default values in templates
- Creates missing values with their default values
- Preserves existing values, structure, and data types (e.g., numbers, strings)
- Provides line number and source file tracking
- Uses atomic file operations
- Provides robust error handling
Error handling:
- Invalid chart directory structure
- Missing or inaccessible templates directory
- Permission issues with values files
- Invalid YAML syntax
- Concurrent file access conflicts
Requirements:
- Go 1.21 or later
- Valid Helm chart directory structure
- Read/write permissions for chart directory
Index ¶
Constants ¶
const Version = "1.0.7"
Version is the current version of shcv
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Chart ¶
type Chart struct {
// Dir is the root directory of the chart
Dir string
// ValuesFiles is the path to values.yaml
ValuesFiles []ValueFile
// References tracks all .Values references found in templates
References []ValueRef
// Templates lists all discovered template files
Templates []string
// contains filtered or unexported fields
}
Chart represents a Helm chart structure and manages its values and templates. It provides functionality to scan templates for value references and ensure all referenced values are properly defined in values.yaml.
func (*Chart) FindTemplates ¶
FindTemplates discovers all template files in the chart's templates directory. It looks for files with .yaml, .yml, or .tpl extensions. Returns an error if the templates directory cannot be accessed.
func (*Chart) LoadValueFiles ¶ added in v1.0.6
LoadValueFiles loads the current values from the value files provided. If the file doesn't exist, an empty values map is initialized. Returns an error if the file exists but cannot be read or parsed.
func (*Chart) ParseTemplates ¶
ParseTemplates scans all discovered templates for .Values references. It identifies both simple references and those with default values. The references are stored in the Chart's References slice.
func (*Chart) ProcessReferences ¶ added in v1.0.6
func (c *Chart) ProcessReferences()
ProcessReferences ensures all referenced values exist in values.yaml.
func (*Chart) UpdateValueFiles ¶ added in v1.0.6
UpdateValueFiles ensures all referenced values exist in values.yaml. It adds missing values with appropriate defaults and updates the file. The operation is skipped if no changes are needed.
type Option ¶ added in v1.0.6
type Option func(*config)
Option is a functional option for configuring the Chart processing.
func WithTemplatesDir ¶ added in v1.0.6
WithTemplatesDir sets the templates directory.
func WithValuesFileNames ¶ added in v1.0.6
WithValuesFileNames sets the values file names.
func WithVerbose ¶ added in v1.0.6
WithVerbose sets the verbose flag.
type ValueFile ¶ added in v1.0.6
type ValueFile struct {
// Path is the path to the values file
Path string
// Values contains the values from the values file
Values map[string]any
// Changed indicates whether values were modified during processing
Changed bool
}
ValueFile represents a values file
type ValueRef ¶
type ValueRef struct {
// Path is the full dot-notation path to the value (e.g. "gateway.domain")
Path string
// DefaultValue is the value specified in the template using the default function
DefaultValue string
// SourceFile is the template file where this reference was found
SourceFile string
// LineNumber is the line number in the source file where the reference appears
LineNumber int
}
ValueRef represents a Helm value reference found in templates. It tracks where values are used in templates and their default values if specified.