Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/copilot-instructions.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ Chartify is a Go library and CLI tool that converts Kubernetes resource YAMLs, K
## Working Effectively

### Bootstrap and Build
- **Prerequisites**: Go 1.25.4+, Helm v4.0.0, Kustomize v5.8.0+ are required
- **Prerequisites**: Go 1.25.4+, Helm v4.1.0, Kustomize v5.8.0+ are required
- Build the CLI: `go build -o chartify ./cmd/chartify` -- takes 25 seconds. **NEVER CANCEL**. Set timeout to 60+ seconds.
- Build dependencies: `go mod download` -- takes 15 seconds. **NEVER CANCEL**. Set timeout to 120+ seconds.
- Alternative build with chart repo server: `go build -o chartreposerver ./cmd/chartreposerver`
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/go.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ jobs:
strategy:
matrix:
helm-version:
- v3.19.5
- v4.0.5
- v3.20.0
- v4.1.0
steps:
- name: Check out code into the Go module directory
uses: actions/checkout@v6
Expand Down
147 changes: 147 additions & 0 deletions AGENTS.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,147 @@
# Chartify - Agents Guide

This guide helps agentic coding agents work effectively with the chartify codebase.

## Build, Lint, and Test Commands

### Build
- **Build CLI**: `go build -o chartify ./cmd/chartify` (25s, set timeout 60s+)
- **Build chart repo server**: `go build -o chartreposerver ./cmd/chartreposerver`
- **Download dependencies**: `go mod download` (15s, set timeout 120s+)

### Common Build Times and Timeouts
- `go mod download`: 15 seconds (set timeout: 120+ seconds)
- `go build`: 25 seconds (set timeout: 60+ seconds)
- `go test ./...`: 60 seconds (set timeout: 180+ seconds)
- `go vet ./...`: 42 seconds (set timeout: 120+ seconds)
- `go fmt ./...`: 1 second (set timeout: 30+ seconds)
- **NEVER CANCEL** build commands - they complete predictably

### Testing
- **Run all tests**: `CGO_ENABLED=0 go test ./...` (60s, set timeout 180s+)
- **Run with verbose output**: `RETAIN_TEMP_DIR=1 go test -v ./...`
- **Run single test**: `go test -run TestFunctionName ./...`
- **Run single test file**: `go test -v chartify_test.go`
- **Use Makefile**: `make test` or `make test/verbose`

### Linting and Formatting
- **Format code**: `go fmt ./...`
- **Vet code**: `go vet ./...` (42s, set timeout 120s+)
- **NOTE**: golangci-lint config (.golangci.yaml) has compatibility issues with recent versions. Use `go fmt` and `go vet` for validation.

### Running the CLI
- Basic usage: `./chartify -o OUTPUT_DIR RELEASE_NAME CHART_OR_MANIFEST_PATH`
- Example with Helm chart: `./chartify -o /tmp/output test-release testdata/charts/log`
- Example with K8s manifests: `./chartify -o /tmp/output test-release testdata/kube_manifest_yml`
- Help: `./chartify -h`

### Running the Chart Repo Server
- Usage: `./chartreposerver CHARTS_DIR`
- Example: `./chartreposerver testdata/charts` (serves charts on port 18080)
- No help flag available - expects exactly 1 argument (charts directory)

## Code Style Guidelines

### Imports
- Order: standard library → third-party → local (github.com/helmfile/chartify prefix)
- Use `goimports` or `gci` formatter for consistent ordering
- Example:
```go
import (
"fmt"
"os"

"github.com/Masterminds/semver/v3"
"helm.sh/helm/v3/pkg/registry"

"github.com/helmfile/chartify"
)
```

### Formatting
- Use `go fmt ./...` before committing
- Line length: 120 characters (per golangci.yaml)
- Use `gofmt` with simplify: true

### Types and Naming
- Use PascalCase for exported types, functions, constants
- Use camelCase for unexported variables and fields
- Type names should be descriptive (e.g., `ChartifyOpts`, `PatchOpts`)
- Interface names typically end with "Option" when used for functional options pattern
- Use `func(t *testing.T)` and `t.Helper()` for test helpers

### Error Handling
- Always check and return errors explicitly
- Use early returns for error conditions
- Pattern:
```go
if err != nil {
return "", err
}
```
- In tests, use `require.NoError(t, err)` or `require.Error(t, err)` from testify
- Use `require.Containsf(t, err.Error(), "msg")` to check error messages

### Testing Conventions
- Use `github.com/stretchr/testify/require` for assertions
- Use `github.com/google/go-cmp/cmp` for comparing complex structs
- Test functions: `func TestFeatureName(t *testing.T)`
- Integration tests in `integration_test.go`
- Use `RETAIN_TEMP_DIR=1` env var to keep temp directories for debugging
- Setup functions use `t.Helper()` and are called at start of tests

### Function Options Pattern
- The codebase uses functional options extensively
- Pattern: `type Option func(*Runner) error`
- Implementation: `func HelmBin(b string) Option { return func(r *Runner) error { r.HelmBinary = b; return nil } }`
- Usage: `New(HelmBin("helm"), UseHelm3(true))`

### Comments and Documentation
- Exported types and functions should have godoc comments
- Comment explains "what" and "why", not "how"
- Use `// nolint` sparingly when intentionally bypassing linters

### File Organization
- `chartify.go` - Core library functionality
- `kustomize.go` - Kustomize integration
- `patch.go` - Strategic merge and JSON patch logic
- `replace.go` - Text replacement functionality
- `requirements.go` - Chart dependency management
- `runner.go` - Command execution utilities
- `cmd/chartify/main.go` - CLI entry point
- `cmd/chartreposerver/main.go` - HTTP server for charts

### Validation After Changes
**Always manually test CLI functionality after making changes to core library code:**
- Test with Helm chart: `./chartify -o /tmp/test1 test-release testdata/charts/log && ls /tmp/test1/`
- Test with K8s manifests: `./chartify -o /tmp/test2 test-release testdata/kube_manifest_yml && find /tmp/test2/ -type f`
- Verify help: `./chartify -h`

### Before Committing
Run these commands to ensure CI passes:
```bash
go fmt ./...
go vet ./...
CGO_ENABLED=0 go test ./...
```

### Prerequisites
- Go 1.25.4+
- Helm v4.1.0 (helm command)
- Kustomize v5.8.0+ (kustomize command)

### External Dependencies
- **Helm**: Required for chart operations. Usually pre-installed as `helm` command.
- **Kustomize**: Required for kustomize integration. Usually pre-installed as `kustomize` command.
- **Note**: Helm repo add commands may fail in restricted network environments but tests can still pass.

### Common Issues
- Helm repo operations may fail in restricted network environments - core functionality still works
- Some complex kustomize examples may fail helm template validation - this is expected
- Use environment variable `HELM_BIN` to override helm binary path for testing
- Never cancel build commands - they take predictable time (see timeouts above)

### Debugging
- Use `RETAIN_TEMP_DIR=1` environment variable to keep temporary directories for debugging
- Build output goes to temporary directories that are automatically cleaned up
- The CLI expects exactly 2 positional arguments: RELEASE_NAME and CHART_PATH, with -o flag for output directory
62 changes: 29 additions & 33 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ require (
github.com/otiai10/copy v1.14.1
github.com/stretchr/testify v1.11.1
gopkg.in/yaml.v3 v3.0.1
helm.sh/helm/v3 v3.19.5
helm.sh/helm/v4 v4.0.5
helm.sh/helm/v3 v3.20.0
helm.sh/helm/v4 v4.1.0
)

require (
Expand All @@ -20,7 +20,7 @@ require (
github.com/blang/semver/v4 v4.0.0 // indirect
github.com/chai2010/gettext-go v1.0.2 // indirect
github.com/cloudflare/circl v1.6.1 // indirect
github.com/containerd/containerd v1.7.29 // indirect
github.com/containerd/containerd v1.7.30 // indirect
github.com/containerd/errdefs v0.3.0 // indirect
github.com/containerd/log v0.1.0 // indirect
github.com/containerd/platforms v0.2.1 // indirect
Expand All @@ -30,19 +30,17 @@ require (
github.com/evanphx/json-patch/v5 v5.9.11 // indirect
github.com/exponent-io/jsonpath v0.0.0-20210407135951-1de76d718b3f // indirect
github.com/extism/go-sdk v1.7.1 // indirect
github.com/fluxcd/cli-utils v0.36.0-flux.14 // indirect
github.com/fluxcd/cli-utils v0.37.0-flux.1 // indirect
github.com/fxamacker/cbor/v2 v2.9.0 // indirect
github.com/go-errors/errors v1.5.1 // indirect
github.com/go-logr/logr v1.4.3 // indirect
github.com/go-openapi/jsonpointer v0.21.1 // indirect
github.com/go-openapi/jsonreference v0.21.0 // indirect
github.com/go-openapi/swag v0.23.1 // indirect
github.com/gobwas/glob v0.2.3 // indirect
github.com/gogo/protobuf v1.3.2 // indirect
github.com/google/btree v1.1.3 // indirect
github.com/google/gnostic-models v0.7.0 // indirect
github.com/google/uuid v1.6.0 // indirect
github.com/gorilla/websocket v1.5.4-0.20250319132907-e064f32e3674 // indirect
github.com/gregjones/httpcache v0.0.0-20190611155906-901d90724c79 // indirect
github.com/hashicorp/errwrap v1.1.0 // indirect
github.com/hashicorp/go-multierror v1.1.1 // indirect
Expand All @@ -54,13 +52,11 @@ require (
github.com/liggitt/tabwriter v0.0.0-20181228230101-89fcab3d43de // indirect
github.com/mailru/easyjson v0.9.0 // indirect
github.com/mitchellh/go-wordwrap v1.0.1 // indirect
github.com/moby/spdystream v0.5.0 // indirect
github.com/moby/term v0.5.2 // indirect
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
github.com/modern-go/reflect2 v1.0.3-0.20250322232337-35a7c28c31ee // indirect
github.com/monochromegane/go-gitignore v0.0.0-20200626010858-205db1a8cc00 // indirect
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect
github.com/mxk/go-flowrate v0.0.0-20140419014527-cca7078d478f // indirect
github.com/opencontainers/go-digest v1.0.0 // indirect
github.com/opencontainers/image-spec v1.1.1 // indirect
github.com/otiai10/mint v1.6.3 // indirect
Expand All @@ -69,43 +65,43 @@ require (
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect
github.com/russross/blackfriday/v2 v2.1.0 // indirect
github.com/sirupsen/logrus v1.9.3 // indirect
github.com/spf13/cobra v1.10.1 // indirect
github.com/spf13/cobra v1.10.2 // indirect
github.com/spf13/pflag v1.0.10 // indirect
github.com/tetratelabs/wabin v0.0.0-20230304001439-f6f874872834 // indirect
github.com/tetratelabs/wazero v1.9.0 // indirect
github.com/tetratelabs/wazero v1.11.0 // indirect
github.com/x448/float16 v0.8.4 // indirect
github.com/xlab/treeprint v1.2.0 // indirect
go.opentelemetry.io/proto/otlp v1.5.0 // indirect
go.yaml.in/yaml/v2 v2.4.2 // indirect
go.yaml.in/yaml/v2 v2.4.3 // indirect
go.yaml.in/yaml/v3 v3.0.4 // indirect
golang.org/x/crypto v0.45.0 // indirect
golang.org/x/net v0.47.0 // indirect
golang.org/x/crypto v0.46.0 // indirect
golang.org/x/net v0.48.0 // indirect
golang.org/x/oauth2 v0.30.0 // indirect
golang.org/x/sync v0.18.0 // indirect
golang.org/x/sys v0.39.0 // indirect
golang.org/x/term v0.37.0 // indirect
golang.org/x/text v0.31.0 // indirect
golang.org/x/sync v0.19.0 // indirect
golang.org/x/sys v0.40.0 // indirect
golang.org/x/term v0.39.0 // indirect
golang.org/x/text v0.33.0 // indirect
golang.org/x/time v0.12.0 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20250303144028-a0af3efb3deb // indirect
google.golang.org/grpc v1.72.1 // indirect
google.golang.org/protobuf v1.36.6 // indirect
gopkg.in/evanphx/json-patch.v4 v4.12.0 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20250528174236-200df99c418a // indirect
google.golang.org/grpc v1.72.2 // indirect
google.golang.org/protobuf v1.36.8 // indirect
gopkg.in/evanphx/json-patch.v4 v4.13.0 // indirect
gopkg.in/inf.v0 v0.9.1 // indirect
k8s.io/api v0.34.2 // indirect
k8s.io/apiextensions-apiserver v0.34.2 // indirect
k8s.io/apimachinery v0.34.2 // indirect
k8s.io/cli-runtime v0.34.2 // indirect
k8s.io/client-go v0.34.2 // indirect
k8s.io/component-base v0.34.2 // indirect
k8s.io/api v0.35.0 // indirect
k8s.io/apiextensions-apiserver v0.35.0 // indirect
k8s.io/apimachinery v0.35.0 // indirect
k8s.io/cli-runtime v0.35.0 // indirect
k8s.io/client-go v0.35.0 // indirect
k8s.io/component-base v0.35.0 // indirect
k8s.io/klog/v2 v2.130.1 // indirect
k8s.io/kube-openapi v0.0.0-20250710124328-f3f2b991d03b // indirect
k8s.io/kubectl v0.34.2 // indirect
k8s.io/utils v0.0.0-20250604170112-4c0f3b243397 // indirect
k8s.io/kube-openapi v0.0.0-20250910181357-589584f1c912 // indirect
k8s.io/kubectl v0.35.0 // indirect
k8s.io/utils v0.0.0-20251002143259-bc988d571ff4 // indirect
oras.land/oras-go/v2 v2.6.0 // indirect
sigs.k8s.io/controller-runtime v0.22.3 // indirect
sigs.k8s.io/json v0.0.0-20241014173422-cfa47c3a1cc8 // indirect
sigs.k8s.io/controller-runtime v0.22.4 // indirect
sigs.k8s.io/json v0.0.0-20250730193827-2d320260d730 // indirect
sigs.k8s.io/kustomize/api v0.20.1 // indirect
sigs.k8s.io/kustomize/kyaml v0.20.1 // indirect
sigs.k8s.io/kustomize/kyaml v0.21.0 // indirect
sigs.k8s.io/randfill v1.0.0 // indirect
sigs.k8s.io/structured-merge-diff/v6 v6.3.0 // indirect
sigs.k8s.io/yaml v1.6.0 // indirect
Expand Down
Loading