Skip to content

feat: add kustomize unified 'patches' field support#199

Merged
yxxhero merged 1 commit into
masterfrom
feat/patches-support-94
Jun 21, 2026
Merged

feat: add kustomize unified 'patches' field support#199
yxxhero merged 1 commit into
masterfrom
feat/patches-support-94

Conversation

@yxxhero

@yxxhero yxxhero commented Jun 21, 2026

Copy link
Copy Markdown
Member

Summary

Add support for kustomize's unified patches: field which auto-detects Strategic Merge vs JSON Patch and supports both inline content (via patch:) and external file references (via path:).

See https://github.com/kubernetes-sigs/kustomize/blob/master/examples/inlinePatch.md

Closes #94

Changes

Library API

  • Add Patches []string field to ChartifyOpts and PatchOpts
  • Each file may contain a single patch document, a list of patch documents, or a multi-document YAML stream
  • External path: references are copied into tempDir (consistent with transformer path resolution from Usage of kustomize transformers with "path" instead of "patch" #90)
  • Added jsonpatches and patch-files dirs to removedPathList for cleanup (jsonpatches was previously leaking)

CLI

  • Add -patch flag (repeatable) to cmd/chartify

Usage

# inline-patch.yaml - single patch entry with inline content
patch: |-
  apiVersion: apps/v1
  kind: Deployment
  metadata:
    name: my-deploy
  spec:
    replicas: 3
target:
  kind: Deployment
# CLI
chartify -patch inline-patch.yaml -o output release chart-path

# Go library
opts := chartify.ChartifyOpts{
    Patches: []string{"inline-patch.yaml"},
}

Test plan

  • Unit tests: TestParsePatchDocuments (8 cases), TestMarshalPatchEntry (2 cases), TestPatch_Patches (2 cases)
  • Integration tests with snapshots: inline strategic merge, list (strategic + JSON6902), external path reference
  • go fmt, go vet, go build all pass
  • Existing tests unaffected (except pre-existing kube_version_and_api_versions which depends on cluster state)

Add support for kustomize's unified 'patches:' field which auto-detects
Strategic Merge vs JSON Patch and supports both inline content (via
'patch:') and external file references (via 'path:').

See https://github.com/kubernetes-sigs/kustomize/blob/master/examples/inlinePatch.md

Closes #94

Changes:
- Add Patches []string field to ChartifyOpts and PatchOpts
- Implement handler in Patch() that parses each file as either a single
  patch document, a list of documents, or a multi-document YAML stream
- External 'path:' references are copied into tempDir (consistent with
  transformer path resolution from #90)
- Add -patch CLI flag (repeatable) to cmd/chartify
- Add jsonpatches and patch-files dirs to removedPathList for cleanup
- Add unit tests (TestParsePatchDocuments, TestMarshalPatchEntry,
  TestPatch_Patches) covering single doc, list, multi-doc, edge cases
- Add integration tests with snapshots for inline, list, and path forms

Signed-off-by: yxxhero <yxxhero@users.noreply.github.com>
Signed-off-by: yxxhero <aiopsclub@163.com>
@yxxhero yxxhero merged commit 6d65240 into master Jun 21, 2026
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

add patches support

1 participant