Allow using kubectl built-in kustomize if separate kustomize binary is missing
This PR implements automatic fallback to kubectl's built-in kustomize functionality when a standalone kustomize binary is not available, addressing the need for better accessibility when only kubectl is installed.
Changes Made
Core Functionality
-
Automatic Fallback Detection: Added logic to detect when kustomize binary is missing and automatically fall back to
kubectl kustomizefor build operations -
Direct YAML Generation: Replaced
kustomize editcommands with direct YAML file generation using Go structs, eliminating the need for edit operations that aren't supported by kubectl kustomize -
Smart Command Selection: Implemented
kustomizeBuildCommand()method that chooses the appropriate command based on binary availability
Technical Improvements
-
Modern Kustomization Format: Updated to use
resourcesfield instead of deprecatedbasesfield, eliminating deprecation warnings - Version-Agnostic Flag Handling: Enhanced version detection to gracefully handle missing binaries and use modern flag formats when version cannot be determined
- Maintained Compatibility: All existing functionality with standalone kustomize binary remains unchanged
Example Usage
Before this change, users needed both helm and kustomize binaries:
# This would fail if kustomize wasn't installed
chartify myapp ./kustomization-dir
After this change, kubectl's built-in kustomize automatically serves as fallback:
# This now works with just kubectl installed
chartify myapp ./kustomization-dir # Uses kubectl kustomize if kustomize binary missing
The implementation maintains full feature compatibility including:
- Image tag replacement
- Name prefix/suffix configuration
- Namespace settings
- Alpha plugins support
- Load restrictor configuration
Testing
Added comprehensive tests to verify:
- Fallback functionality works when kustomize binary is missing
- Normal kustomize behavior is preserved when binary is available
- Generated kustomization.yaml files use modern format
- All existing functionality continues to work correctly
The solution provides seamless user experience - users don't need to install separate kustomize binary if they already have kubectl with built-in kustomize support.
Fixes #63.
✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.