Skip to content

`shcv` is a command-line tool and Go package that helps maintain Helm chart values by automatically synchronizing `values.yaml` 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 file.

License

Notifications You must be signed in to change notification settings

agentstation/shcv

Repository files navigation

shcv (Sync Helm Chart Values)

Go Report Card GoDoc GitHub Workflow Status codecov License Version Go Version

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.

Features

  • 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

Installation

go install github.com/agentstation/shcv@latest

Quick Start

# Process chart in current directory
shcv .

# Process chart with verbose output
shcv -v ./my-helm-chart

# Show version
shcv --version

Usage

Command Line Interface

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

Go Package

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)
}

Configuration Options

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),
)

Example

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

Requirements

  • Go 1.21 or later
  • A valid Helm chart directory structure
  • Read/write permissions for the chart directory

Error Handling

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

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

  1. Fork the repository
  2. Create your feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add some amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

License

This project is licensed under the MIT License - see the LICENSE file for details.

About

`shcv` is a command-line tool and Go package that helps maintain Helm chart values by automatically synchronizing `values.yaml` 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 file.

Resources

License

Stars

Watchers

Forks

Packages

No packages published