Skip to content

Instantly share code, notes, and snippets.

@bluebrown
Created October 31, 2022 07:23
Show Gist options
  • Save bluebrown/c37383ee8614cfd7af1e255ff87b5913 to your computer and use it in GitHub Desktop.
Save bluebrown/c37383ee8614cfd7af1e255ff87b5913 to your computer and use it in GitHub Desktop.
dump a deployed helm release into individual manifest files
#!/usr/bin/env bash
set -euo pipefail
# ./helmdump.sh [target-chart] [output-dir] [namespace]
# $1: the target char
# $2: the output directory, must be a relative path
# $3: optional namespace, if not provided the current namespace is used
targetChart="$1"
outputDir="$PWD/${2%/}"
namespace="${3:-"$(kubectl config view --minify -o jsonpath='{..namespace}')"}"
mkdir -p "$outputDir"
ws="$(mktemp -d)"
trap "rm -rf $ws" EXIT ERR
cd "$ws"
helm status "$targetChart" -o json -n "$namespace" | jq -r '.manifest' >manifests.yaml
kustomize init
kustomize edit add resource manifests.yaml
kustomize edit set namespace "$namespace"
kustomize build . --output "$outputDir/"
cd -
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment