Initial commit.
This commit is contained in:
65
bin/chart-template
Executable file
65
bin/chart-template
Executable file
@@ -0,0 +1,65 @@
|
||||
#!/bin/bash
|
||||
# chart-template
|
||||
# Renders the template for a Helm chart using gomplate for values files
|
||||
# Usage: chart-template CHART [RELEASE_NAME] [NAMESPACE]
|
||||
|
||||
set -e
|
||||
|
||||
# Get script directories
|
||||
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||
REPO_ROOT="$(cd "${SCRIPT_DIR}/.." && pwd)"
|
||||
|
||||
# Load environment variables if needed
|
||||
if [[ -f "${REPO_ROOT}/load-env.sh" ]]; then
|
||||
source "${REPO_ROOT}/load-env.sh"
|
||||
fi
|
||||
|
||||
# Print usage
|
||||
if [[ $# -lt 1 || "$1" == "-h" || "$1" == "--help" ]]; then
|
||||
echo "Usage: $(basename $0) CHART [RELEASE_NAME] [NAMESPACE]"
|
||||
echo ""
|
||||
echo "Renders the Kubernetes templates for a chart with environment variable substitution."
|
||||
echo ""
|
||||
echo " CHART Chart name in charts/ directory"
|
||||
echo " RELEASE_NAME Release name (defaults to CHART)"
|
||||
echo " NAMESPACE Namespace (defaults to RELEASE_NAME)"
|
||||
echo ""
|
||||
exit 1
|
||||
fi
|
||||
|
||||
CHART="$1"
|
||||
RELEASE_NAME="${2:-$CHART}"
|
||||
NAMESPACE="${3:-$RELEASE_NAME}"
|
||||
|
||||
# Check if chart exists
|
||||
CHART_PATH="${REPO_ROOT}/charts/${CHART}"
|
||||
if [[ ! -d "$CHART_PATH" ]]; then
|
||||
echo "Error: Chart not found at ${CHART_PATH}"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Check if template values file exists
|
||||
TPL_VALUES_FILE="${CHART_PATH}/values.template.yaml"
|
||||
if [[ ! -f "$TPL_VALUES_FILE" ]]; then
|
||||
echo "Error: Template values file not found at ${TPL_VALUES_FILE}"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Set variables needed for template
|
||||
export RELEASE_NAME="$RELEASE_NAME"
|
||||
export NAMESPACE="$NAMESPACE"
|
||||
export CHART="$CHART"
|
||||
|
||||
# No headers - just let helm template output the YAML
|
||||
|
||||
# Create temporary values file with gomplate
|
||||
TEMP_VALUES=$(mktemp)
|
||||
gomplate -f "$TPL_VALUES_FILE" > "$TEMP_VALUES"
|
||||
|
||||
# Run helm template
|
||||
helm template "$RELEASE_NAME" "$CHART_PATH" \
|
||||
--namespace "$NAMESPACE" \
|
||||
--values "$TEMP_VALUES"
|
||||
|
||||
# Clean up
|
||||
rm "$TEMP_VALUES"
|
Reference in New Issue
Block a user