Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Sep 9, 2025

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 AI changed the title [WIP] add patches support Add Kustomize-style patches support Sep 9, 2025
Copilot AI requested a review from yxxhero September 9, 2025 23:21
Copilot finished work on behalf of yxxhero September 9, 2025 23:21
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

2 participants