shcv
is a command-line tool and Go package that helps maintain Helm chart values by automatically synchronizing values files with the parameters used in your Helm templates. It scans all template files for {{ .Values.* }}
expressions and ensures they are properly defined in your values files.
- Automatically detects all Helm value references in template files
- Supports multiple values files
- Supports nested value structures (e.g.,
{{ .Values.gateway.domain }}
) - Handles default values in templates (e.g.,
{{ .Values.domain | default "api.example.com" }}
) - Creates missing values in values files with their default values
- Preserves existing values, structure, and data types in your values files
- Provides line number and source file tracking for each reference
- Uses atomic file operations to prevent data corruption
- Provides robust error handling with detailed messages
go install github.com/agentstation/shcv@latest
# Process chart in current directory
shcv .
# Process chart with verbose output
shcv -v ./my-helm-chart
# Show version
shcv --version
The CLI provides a simple interface to process Helm charts:
shcv [flags] CHART_DIRECTORY
Available flags:
-v, --verbose
: Enable verbose output showing all found references--version
: Show version information-h, --help
: Show help information
import "github.com/agentstation/shcv/pkg/shcv"
// Create a new chart instance
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)
}
The package provides functional options for customization:
chart, err := shcv.NewChart("./my-chart",
shcv.WithValuesFileNames([]string{"values.yaml", "values-prod.yaml"}),
shcv.WithTemplatesDir("custom-templates"),
shcv.WithVerbose(true),
)
Given a template file templates/ingress.yaml
:
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: {{ .Values.name | default "my-ingress" }}
spec:
rules:
- host: {{ .Values.domain | default "example.com" }}
http:
paths:
- path: {{ .Values.path | default "/" }}
backend:
service:
port:
number: {{ .Values.port | default 80 }}
Running shcv .
will create/update values.yaml
:
name: "my-ingress"
domain: "example.com"
path: "/"
port: 80
- Go 1.21 or later
- A valid Helm chart directory structure
- Read/write permissions for the chart directory
The tool provides detailed error messages for:
- Invalid chart directory structure
- Missing or inaccessible templates directory
- Permission issues with values files
- Invalid YAML syntax
- Concurrent file access conflicts
Contributions are welcome! Please feel free to submit a Pull Request.
- Fork the repository
- Create your feature branch (
git checkout -b feature/amazing-feature
) - Commit your changes (
git commit -m 'Add some amazing feature'
) - Push to the branch (
git push origin feature/amazing-feature
) - Open a Pull Request
This project is licensed under the MIT License - see the LICENSE file for details.