diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 5eb22f5..27796e9 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -13,7 +13,7 @@ jobs: strategy: matrix: - helm-version: ['v4.0.4'] + helm-version: ['v3.19.4', 'v4.0.4'] kubectl-version: ['latest'] steps: diff --git a/.gitignore b/.gitignore index 8d3333d..46dc160 100644 --- a/.gitignore +++ b/.gitignore @@ -9,7 +9,7 @@ *.dylib # Plugin binary -helm-kustomize-plugin +helm-kustomize # Test binary, built with `go test -c` *.test diff --git a/Makefile b/Makefile index 496a0b4..8004e40 100644 --- a/Makefile +++ b/Makefile @@ -1,19 +1,25 @@ .PHONY: build clean test test-integration test-all install uninstall reinstall \ coverage-report coverage-clean -BINARY_NAME=helm-kustomize-plugin +BINARY_NAME=helm-kustomize BUILD_DIR=dist COVERAGE_THRESHOLD=80 COVERAGE_PROFILE=coverage.out COVERAGE_HTML=coverage.html COVERAGE_DIR=coverage +# Get Helm version and check if it's >= 4 +HELM_VERSION_MAJOR := $(shell helm version --template='{{.Version}}' 2>/dev/null | sed -n 's/^v\([0-9]*\).*/\1/p') +HELM_MODERN_PLUGINS := $(shell [ "$(HELM_VERSION_MAJOR)" -ge "4" ] 2>/dev/null && echo "true" || echo "false") + build: go fmt ./... mkdir -p $(BUILD_DIR) go build -o $(BUILD_DIR)/$(BINARY_NAME) . cp plugin.yaml $(BUILD_DIR)/ +ifeq ($(HELM_MODERN_PLUGINS),true) helm plugin package dist --sign=false +endif clean: coverage-clean uninstall rm -rf $(BUILD_DIR) @@ -52,10 +58,14 @@ coverage-clean: rm -rf $(COVERAGE_DIR) $(COVERAGE_PROFILE) $(COVERAGE_HTML) helm-kustomize-*.tgz install: build +ifeq ($(HELM_MODERN_PLUGINS),true) helm plugin install $(BUILD_DIR) +endif uninstall: +ifeq ($(HELM_MODERN_PLUGINS),true) helm plugin uninstall helm-kustomize 2>/dev/null || true +endif # Development: uninstall, rebuild, and reinstall reinstall: uninstall build install diff --git a/README.md b/README.md index d8a95fc..3061ead 100644 --- a/README.md +++ b/README.md @@ -1,23 +1,27 @@ -# helm-kustomize-plugin +# helm-kustomize A Helm post-renderer plugin to process kustomizations embedded inside a chart. ## Requirements -- Helm v4 (with subprocess runtime support for post-renderer plugins) -- kubectl (for `kubectl kustomize` command) +- Helm v3 or v4 +- kubectl (latest) ## Installation ### Helm v4 +Install from the [OCI registry](https://github.com/orgs/owhelm/packages/container/package/helm-kustomize): + 1. `helm plugin install oci://ghcr.io/owhelm/helm-kustomize:latest` ### Helm v3 +Download from the [OCI registry](https://github.com/orgs/owhelm/packages/container/package/helm-kustomize) and use the binary from inside there: + 1. `oras pull ghcr.io/owhelm/helm-kustomize:latest` 2. Extract the tarball -3. Use `helm-kustomize-plugin` as `--post-renderer` +3. Use `helm-kustomize` as `--post-renderer` ## Design diff --git a/TODO.md b/TODO.md index 7c23e3f..eeeea52 100644 --- a/TODO.md +++ b/TODO.md @@ -26,4 +26,3 @@ - [ ] Support for multiple kustomization files - [ ] Configurable resource naming (alternative to `all.yaml`) - [ ] Performance optimization for large charts -- [ ] Support helm v3 diff --git a/go.mod b/go.mod index 571f811..d5571e0 100644 --- a/go.mod +++ b/go.mod @@ -1,4 +1,4 @@ -module github.com/owhelm/helm-kustomize-plugin +module github.com/owhelm/helm-kustomize go 1.25.5 diff --git a/main.go b/main.go index 310769b..f3c1590 100644 --- a/main.go +++ b/main.go @@ -6,9 +6,9 @@ import ( "io" "os" - "github.com/owhelm/helm-kustomize-plugin/internal/extractor" - "github.com/owhelm/helm-kustomize-plugin/internal/kustomize" - "github.com/owhelm/helm-kustomize-plugin/internal/parser" + "github.com/owhelm/helm-kustomize/internal/extractor" + "github.com/owhelm/helm-kustomize/internal/kustomize" + "github.com/owhelm/helm-kustomize/internal/parser" ) // KustomizePostRenderer processes Helm manifests through kustomize transformations. diff --git a/main_test.go b/main_test.go index c1df3d9..83eb5c9 100644 --- a/main_test.go +++ b/main_test.go @@ -249,7 +249,7 @@ files: resources: - all.yaml commonAnnotations: - managed-by: helm-kustomize-plugin + managed-by: helm-kustomize `) renderer := &KustomizePostRenderer{} @@ -264,14 +264,14 @@ data: kind: ConfigMap metadata: annotations: - managed-by: helm-kustomize-plugin + managed-by: helm-kustomize name: my-config --- apiVersion: v1 kind: Service metadata: annotations: - managed-by: helm-kustomize-plugin + managed-by: helm-kustomize name: my-service spec: type: ClusterIP @@ -280,14 +280,14 @@ apiVersion: apps/v1 kind: Deployment metadata: annotations: - managed-by: helm-kustomize-plugin + managed-by: helm-kustomize name: my-deployment spec: replicas: 2 template: metadata: annotations: - managed-by: helm-kustomize-plugin + managed-by: helm-kustomize ` if output.String() != expected { diff --git a/plugin.yaml b/plugin.yaml index dc36051..c9d4aa1 100644 --- a/plugin.yaml +++ b/plugin.yaml @@ -6,4 +6,4 @@ description: A Helm post-renderer plugin that applies Kustomize transformations runtime: subprocess runtimeConfig: platformCommand: - - command: ${HELM_PLUGIN_DIR}/helm-kustomize-plugin + - command: ${HELM_PLUGIN_DIR}/helm-kustomize diff --git a/test-integration.sh b/test-integration.sh index fb1eb00..f31fc57 100755 --- a/test-integration.sh +++ b/test-integration.sh @@ -1,7 +1,7 @@ #!/bin/bash set -euo pipefail -# Integration test for helm-kustomize-plugin +# Integration test for helm-kustomize # Tests the plugin against the simple-app example echo "Running integration test..." @@ -13,16 +13,20 @@ if ! command -v yq &> /dev/null; then exit 1 fi -# Ensure plugin is installed -if ! helm plugin list | grep -q helm-kustomize; then - echo "Error: helm-kustomize plugin not installed" - echo "Run 'make install' first" - exit 1 +# Detect Helm version and choose appropriate post-renderer +HELM_VERSION_MAJOR=$(helm version --template='{{.Version}}' 2>/dev/null | sed -n 's/^v\([0-9]*\).*/\1/p') + +if [ "$HELM_VERSION_MAJOR" -ge 4 ] 2>/dev/null; then + echo "Helm v${HELM_VERSION_MAJOR} detected - using plugin approach" + POST_RENDERER="helm-kustomize" +else + echo "Helm v${HELM_VERSION_MAJOR} detected - using direct binary" + POST_RENDERER="./dist/helm-kustomize" fi -# Run helm template with the plugin +# Run helm template with the appropriate post-renderer echo "Testing simple-app example..." -OUTPUT=$(helm template examples/simple-app --post-renderer helm-kustomize) +OUTPUT=$(helm template examples/simple-app --post-renderer "$POST_RENDERER") # Check for expected transformations FAILED=0