chartify icon indicating copy to clipboard operation
chartify copied to clipboard

Add Kustomize-style patches support

Open Copilot opened this issue 4 months ago • 0 comments

This PR implements Kustomize-style patches support for chartify, adding a unified patches field that can handle both Strategic Merge Patches and JSON Patches with automatic type detection.

Overview

The new Patches field in ChartifyOpts provides a modern, unified interface for applying patches that matches Kustomize's native patches functionality. This complements the existing JsonPatches and StrategicMergePatches fields while maintaining full backward compatibility.

Key Features

Auto-detection of Patch Types

Chartify automatically detects whether a patch is a Strategic Merge Patch or JSON Patch based on content structure:

  • JSON Patches: Detected when content contains operations with op and path fields
  • Strategic Merge Patches: Standard Kubernetes YAML resources

File-based and Inline Patches

// File-based patch
patches := []Patch{{Path: "./my-patch.yaml"}}

// Inline patch
patches := []Patch{{
    Patch: `apiVersion: apps/v1
kind: Deployment
metadata:
  name: myapp
spec:
  replicas: 3`,
}}

Target Specification for JSON Patches

patches := []Patch{{
    Target: &PatchTarget{
        Kind: "Deployment", 
        Name: "myapp",
    },
    Patch: `- op: replace
  path: /spec/replicas
  value: 5`,
}}

CLI Integration

New --patch flag provides easy access to the patches functionality:

chartify myapp ./chart -o ./output --patch ./my-patch.yaml

Implementation Details

  • New Types: Added Patch and PatchTarget structs to match Kustomize's patches field structure
  • Auto-detection Logic: Implemented intelligent patch type detection in patch.go
  • Kustomization Generation: Enhanced kustomization.yaml generation to handle the new unified patches format
  • CLI Support: Extended the CLI with --patch flag for file-based patches

Testing

  • Unit Tests: Comprehensive tests for patch struct validation and construction
  • Integration Tests: End-to-end testing of strategic merge patches, inline patches, and JSON patches with targets
  • CLI Testing: Manual verification of patch application and auto-detection
  • Backward Compatibility: Verified existing --strategic-merge-patch and JsonPatches/StrategicMergePatches fields continue working

Backward Compatibility

This change is fully backward compatible:

  • Existing JsonPatches and StrategicMergePatches fields continue to work unchanged
  • Existing --strategic-merge-patch CLI flag continues to work unchanged
  • All existing functionality preserved and tested

Fixes #94.


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Copilot avatar Sep 09 '25 23:09 Copilot