mirror of
https://github.com/philippemerle/KubeDiagrams.git
synced 2026-08-16 14:16:14 +00:00
Add options to helm-diagrams script
This commit is contained in:
@@ -176,7 +176,27 @@ nix shell github:philippemerle/KubeDiagrams#kubectl-diagrams
|
||||
|
||||
`helm-diagrams` generates a Kubernetes architecture diagram from an Helm chart.
|
||||
|
||||
`helm-diagrams` takes only one argument - the URL of the Helm chart - but requires that the `helm` command was installed.
|
||||
```sh
|
||||
helm-diagrams -h
|
||||
Usage: helm-diagrams <helm-chart-url> [OPTIONS]
|
||||
|
||||
A script to generate a diagram of an Helm chart using kube-diagrams.
|
||||
|
||||
Options:
|
||||
-o, --output <file> Specify the output file for the diagram
|
||||
-f, --format <format> Specify the output format (e.g., png, svg)
|
||||
-c, --config <file> Specify the custom kube-diagrams configuration file
|
||||
-h, --help Display this help message
|
||||
|
||||
Examples:
|
||||
helm-diagrams https://charts.jetstack.io/cert-manager -o diagram.png
|
||||
helm-diagrams oci://ghcr.io/argoproj/argo-helm/argo-cd -f svg
|
||||
helm-diagrams --help
|
||||
```
|
||||
|
||||
> [!NOTE]
|
||||
>
|
||||
> `helm-diagrams` requires that the `helm` command was installed.
|
||||
|
||||
Examples:
|
||||
|
||||
|
||||
+95
-16
@@ -1,38 +1,117 @@
|
||||
#! /bin/sh
|
||||
#!/bin/bash
|
||||
|
||||
# $1 contains the Helm Chart URL.
|
||||
repository=$(dirname $1)
|
||||
chart=$(basename $1)
|
||||
# helm-diagrams: A script to generate a diagram of an Helm chart
|
||||
# using kube-diagrams from the output of 'helm template <name> <chart>'
|
||||
|
||||
# Check if kube-diagrams is installed
|
||||
if ! command -v kube-diagrams &>/dev/null; then
|
||||
echo "Error: kube-diagrams is not installed. Please install it first."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Check if helm is installed
|
||||
if ! command -v helm &>/dev/null; then
|
||||
echo "Error: helm is not installed. Please install it first."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Display help message
|
||||
show_help() {
|
||||
echo "Usage: helm-diagrams <helm-chart-url> [OPTIONS]"
|
||||
echo ""
|
||||
echo "A script to generate a diagram of an Helm chart using kube-diagrams."
|
||||
echo ""
|
||||
echo "Options:"
|
||||
echo " -o, --output <file> Specify the output file for the diagram"
|
||||
echo " -f, --format <format> Specify the output format (e.g., png, svg)"
|
||||
echo " -c, --config <file> Specify the custom kube-diagrams configuration file"
|
||||
echo " -h, --help Display this help message"
|
||||
echo ""
|
||||
echo "Examples:"
|
||||
echo " helm-diagrams https://charts.jetstack.io/cert-manager -o diagram.png"
|
||||
echo " helm-diagrams oci://ghcr.io/argoproj/argo-helm/argo-cd -f svg"
|
||||
echo " helm-diagrams --help"
|
||||
exit 0
|
||||
}
|
||||
|
||||
# Initialize variables
|
||||
HELM_CHART_URL=""
|
||||
HELM_ARGS=()
|
||||
KUBE_DIAGRAMS_ARGS=("-" "--without-namespace") # Default to stdin indicator
|
||||
|
||||
# Use the KubeDiagrams custom configuration if exist.
|
||||
KD_CC="KubeDiagrams.yaml"
|
||||
if [ -e $KD_CC ]
|
||||
then
|
||||
KD_OPTS="-c $KD_CC"
|
||||
else
|
||||
KD_OPTS=""
|
||||
KUBE_DIAGRAMS_ARGS+=("--config" "$KD_CC")
|
||||
fi
|
||||
|
||||
echo Download $1...
|
||||
# Parse arguments
|
||||
while [[ $# -gt 0 ]]; do
|
||||
case "$1" in
|
||||
-h | --help)
|
||||
show_help
|
||||
;;
|
||||
-o | --output | -f | --format | -c | --config)
|
||||
KUBE_DIAGRAMS_ARGS+=("$1")
|
||||
if [[ -n "$2" ]]; then
|
||||
KUBE_DIAGRAMS_ARGS+=("$2")
|
||||
shift 2
|
||||
else
|
||||
echo "Error: $1 requires a value!"
|
||||
exit 64
|
||||
fi
|
||||
;;
|
||||
*)
|
||||
if [ -z "${HELM_CHART_URL}" ]; then
|
||||
HELM_CHART_URL=$1
|
||||
repository=$(dirname ${HELM_CHART_URL})
|
||||
name=$(basename ${HELM_CHART_URL})
|
||||
KUBE_DIAGRAMS_ARGS+=("--output" "${name}")
|
||||
else
|
||||
HELM_ARGS+=("$1")
|
||||
fi
|
||||
shift
|
||||
;;
|
||||
esac
|
||||
done
|
||||
|
||||
if [[ ${repository} == oci* ]]
|
||||
then
|
||||
# Check if any Helm chart url was specified
|
||||
if [ -z "${HELM_CHART_URL}" ]; then
|
||||
echo "Error: At least one Helm chart URL must be specified!"
|
||||
exit 64
|
||||
fi
|
||||
|
||||
echo Download ${HELM_CHART_URL}...
|
||||
|
||||
if [[ ${repository} == oci* ]]; then
|
||||
# Deal with OCI registries.
|
||||
helm template ${chart} $1 2> /dev/null | kube-diagrams $KD_OPTS --without-namespace -o $chart -
|
||||
elif [[ ${repository} == http* ]]
|
||||
then
|
||||
# Execute helm and pipe to kube-diagrams with arguments
|
||||
helm template ${name} ${HELM_CHART_URL} "${HELM_ARGS[@]}" | kube-diagrams "${KUBE_DIAGRAMS_ARGS[@]}"
|
||||
EXIT_CODE=$?
|
||||
elif [[ ${repository} == http* ]]; then
|
||||
# Deal with HTTP registries.
|
||||
|
||||
# Add a Helm repository.
|
||||
rid=helm-diagrams-repo
|
||||
helm repo add $rid $repository --force-update >/dev/null
|
||||
|
||||
# Process the chart and generate the architecture diagram.
|
||||
helm template $chart $rid/$chart | kube-diagrams $KD_OPTS --without-namespace -o $chart -
|
||||
# Execute helm and pipe to kube-diagrams with arguments
|
||||
helm template ${name} $rid/${name} "${HELM_ARGS[@]}" | kube-diagrams "${KUBE_DIAGRAMS_ARGS[@]}"
|
||||
EXIT_CODE=$?
|
||||
|
||||
# Remove the Helm repository.
|
||||
helm repo remove $rid >/dev/null
|
||||
else
|
||||
# Deal with local charts
|
||||
helm template ${chart} ${repository}/${chart} 2> /dev/null | kube-diagrams $KD_OPTS --without-namespace -o local-$chart -
|
||||
# Execute helm and pipe to kube-diagrams with arguments
|
||||
helm template ${name} ${repository}/${name} "${HELM_ARGS[@]}" | kube-diagrams -o local-$name "${KUBE_DIAGRAMS_ARGS[@]}"
|
||||
EXIT_CODE=$?
|
||||
fi
|
||||
|
||||
if [[ $EXIT_CODE -eq 0 ]]; then
|
||||
echo "Diagram generated successfully"
|
||||
else
|
||||
echo "Error: Failed to generate diagram!"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
@@ -22,14 +22,10 @@ curl https://raw.githubusercontent.com/argoproj/argo-events/refs/heads/master/ma
|
||||
git clone https://github.com/argoproj/argo-events.git downloads/argo-events
|
||||
|
||||
# Generate the Kubernetes architecture diagrams for Argo Helm Charts
|
||||
$BIN/helm-diagrams https://argoproj.github.io/argo-helm/argo-cd
|
||||
mv argo-cd.png diagrams/
|
||||
$BIN/helm-diagrams https://argoproj.github.io/argo-helm/argo-workflows
|
||||
mv argo-workflows.png diagrams/
|
||||
$BIN/helm-diagrams https://argoproj.github.io/argo-helm/argo-rollouts
|
||||
mv argo-rollouts.png diagrams/
|
||||
$BIN/helm-diagrams https://argoproj.github.io/argo-helm/argo-events
|
||||
mv argo-events.png diagrams/
|
||||
$BIN/helm-diagrams https://argoproj.github.io/argo-helm/argo-cd -o diagrams/argo-cd.png
|
||||
$BIN/helm-diagrams https://argoproj.github.io/argo-helm/argo-workflows -o diagrams/argo-workflows.png
|
||||
$BIN/helm-diagrams https://argoproj.github.io/argo-helm/argo-rollouts -o diagrams/argo-rollouts.png
|
||||
$BIN/helm-diagrams https://argoproj.github.io/argo-helm/argo-events -o diagrams/argo-events.png
|
||||
|
||||
# Generate the Kubernetes architecture diagrams for Argo Workflows
|
||||
$BIN/kube-diagrams downloads/argoproj-argo-workflows-manifests-quick-start-minimal.yaml -o diagrams/argoproj-argo-workflows-manifests-quick-start-minimal.png
|
||||
@@ -43,8 +39,8 @@ $BIN/kube-diagrams -c argo-cd.kd argo-cd-manifests-install-corrected.yaml --with
|
||||
$BIN/kube-diagrams -c argo-cd.kd downloads/argo-cd-manifests-ha-install.yaml -o diagrams/argo-cd-manifests-ha-install.png
|
||||
|
||||
# Generate the Kubernetes architecture diagram for Argo CD Example Apps
|
||||
helm template downloads/argocd-example-apps/apps | $BIN/kube-diagrams - -c KubeDiagrams.yaml -o diagrams/argoproj-argocd-example-apps-apps.png
|
||||
helm template blue-green downloads/argocd-example-apps/blue-green | $BIN/kube-diagrams - -c KubeDiagrams.yaml -o diagrams/argoproj-argocd-example-apps-blue-green.png
|
||||
$BIN/helm-diagrams downloads/argocd-example-apps/apps -o diagrams/argoproj-argocd-example-apps-apps.png
|
||||
$BIN/helm-diagrams downloads/argocd-example-apps/blue-green -o diagrams/argoproj-argocd-example-apps-blue-green.png
|
||||
kubectl kustomize downloads/argocd-example-apps/pre-post-sync | $BIN/kube-diagrams - -c KubeDiagrams.yaml -o diagrams/argoproj-argocd-example-apps-pre-post-sync.png
|
||||
kubectl kustomize downloads/argocd-example-apps/sock-shop | $BIN/kube-diagrams - -o diagrams/argoproj-argocd-example-apps-sock-shop.png
|
||||
$BIN/kube-diagrams downloads/argocd-example-apps/sync-waves/manifests.yaml -c KubeDiagrams.yaml -o diagrams/argoproj-argocd-example-apps-sync-waves.png
|
||||
|
||||
@@ -18,27 +18,27 @@ $BIN/kube-diagrams $MANIFESTS -c custom_diagram.kd -o diagrams/online-boutique-m
|
||||
|
||||
# Generate diagrams from Online Boutique Helm Chart
|
||||
CHART=oci://us-docker.pkg.dev/online-boutique-ci/charts/onlineboutique
|
||||
helm template onlineboutique $CHART | kube-diagrams - --without-namespace -o diagrams/online-boutique-helm-chart.png
|
||||
helm template onlineboutique $CHART | kube-diagrams - --without-namespace -o diagrams/online-boutique-helm-chart.svg
|
||||
helm template onlineboutique $CHART | kube-diagrams - --without-namespace -o diagrams/online-boutique-helm-chart.dot_json
|
||||
$BIN/helm-diagrams $CHART -o diagrams/online-boutique-helm-chart.png
|
||||
$BIN/helm-diagrams $CHART -o diagrams/online-boutique-helm-chart.svg
|
||||
$BIN/helm-diagrams $CHART -o diagrams/online-boutique-helm-chart.dot_json
|
||||
# diagrams with network policies
|
||||
helm template onlineboutique $CHART --set networkPolicies.create=true | kube-diagrams - --without-namespace -o diagrams/online-boutique-helm-chart-with-network-policies.png
|
||||
helm template onlineboutique $CHART --set networkPolicies.create=true | kube-diagrams - --without-namespace -o diagrams/online-boutique-helm-chart-with-network-policies.svg
|
||||
helm template onlineboutique $CHART --set networkPolicies.create=true | kube-diagrams - --without-namespace -o diagrams/online-boutique-helm-chart-with-network-policies.dot_json
|
||||
$BIN/helm-diagrams $CHART --set networkPolicies.create=true -o diagrams/online-boutique-helm-chart-with-network-policies.png
|
||||
$BIN/helm-diagrams $CHART --set networkPolicies.create=true -o diagrams/online-boutique-helm-chart-with-network-policies.svg
|
||||
$BIN/helm-diagrams $CHART --set networkPolicies.create=true -o diagrams/online-boutique-helm-chart-with-network-policies.dot_json
|
||||
# TODO: diagrams with virtual services
|
||||
#helm template onlineboutique $CHART --set frontend.virtualService.create=true | kube-diagrams - --without-namespace -o diagrams/online-boutique-helm-chart-with-virtual-services.png
|
||||
#helm template onlineboutique $CHART --set frontend.virtualService=true | kube-diagrams - --without-namespace -o diagrams/online-boutique-helm-chart-with-virtual-services.svg
|
||||
#helm template onlineboutique $CHART --set frontend.virtualService.create=true | kube-diagrams - --without-namespace -o diagrams/online-boutique-helm-chart-with-virtual-services.dot_json
|
||||
#$BIN/helm-diagrams $CHART --set frontend.virtualService.create=true -o diagrams/online-boutique-helm-chart-with-virtual-services.png
|
||||
#$BIN/helm-diagrams $CHART --set frontend.virtualService=true -o diagrams/online-boutique-helm-chart-with-virtual-services.svg
|
||||
#$BIN/helm-diagrams $CHART --set frontend.virtualService.create=true -o diagrams/online-boutique-helm-chart-with-virtual-services.dot_json
|
||||
|
||||
# Generate custom diagrams from Online Boutique Helm Chart
|
||||
helm template onlineboutique $CHART | kube-diagrams - --without-namespace -c custom_diagram.kd -o diagrams/online-boutique-helm-chart-custom-diagram.png
|
||||
helm template onlineboutique $CHART | kube-diagrams - --without-namespace -c custom_diagram.kd -o diagrams/online-boutique-helm-chart-custom-diagram.svg
|
||||
helm template onlineboutique $CHART | kube-diagrams - --without-namespace -c custom_diagram.kd -o diagrams/online-boutique-helm-chart-custom-diagram.dot_json
|
||||
$BIN/helm-diagrams $CHART -c custom_diagram.kd -o diagrams/online-boutique-helm-chart-custom-diagram.png
|
||||
$BIN/helm-diagrams $CHART -c custom_diagram.kd -o diagrams/online-boutique-helm-chart-custom-diagram.svg
|
||||
$BIN/helm-diagrams $CHART -c custom_diagram.kd -o diagrams/online-boutique-helm-chart-custom-diagram.dot_json
|
||||
# diagrams with network policies
|
||||
helm template onlineboutique $CHART --set networkPolicies.create=true | kube-diagrams - --without-namespace -c custom_diagram.kd -o diagrams/online-boutique-helm-chart-custom-diagram-with-network-policies.png
|
||||
helm template onlineboutique $CHART --set networkPolicies.create=true | kube-diagrams - --without-namespace -c custom_diagram.kd -o diagrams/online-boutique-helm-chart-custom-diagram-with-network-policies.svg
|
||||
helm template onlineboutique $CHART --set networkPolicies.create=true | kube-diagrams - --without-namespace -c custom_diagram.kd -o diagrams/online-boutique-helm-chart-custom-diagram-with-network-policies.dot_json
|
||||
$BIN/helm-diagrams $CHART --set networkPolicies.create=true -c custom_diagram.kd -o diagrams/online-boutique-helm-chart-custom-diagram-with-network-policies.png
|
||||
$BIN/helm-diagrams $CHART --set networkPolicies.create=true -c custom_diagram.kd -o diagrams/online-boutique-helm-chart-custom-diagram-with-network-policies.svg
|
||||
$BIN/helm-diagrams $CHART --set networkPolicies.create=true -c custom_diagram.kd -o diagrams/online-boutique-helm-chart-custom-diagram-with-network-policies.dot_json
|
||||
# TODO: diagrams with virtual services
|
||||
#helm template onlineboutique $CHART --set frontend.virtualService.create=true | kube-diagrams - --without-namespace -c custom_diagram.kd -o diagrams/online-boutique-helm-chart-custom-diagram-with-virtual-services.png
|
||||
#helm template onlineboutique $CHART --set frontend.virtualService=true | kube-diagrams - --without-namespace -c custom_diagram.kd -o diagrams/online-boutique-helm-chart-custom-diagram-with-virtual-services.svg
|
||||
#helm template onlineboutique $CHART --set frontend.virtualService.create=true | kube-diagrams - --without-namespace -c custom_diagram.kd -o diagrams/online-boutique-helm-chart-custom-diagram-with-virtual-services.dot_json
|
||||
#$BIN/helm-diagrams $CHART --set frontend.virtualService.create=true -c custom_diagram.kd -o diagrams/online-boutique-helm-chart-custom-diagram-with-virtual-services.png
|
||||
#$BIN/helm-diagrams $CHART --set frontend.virtualService=true -c custom_diagram.kd -o diagrams/online-boutique-helm-chart-custom-diagram-with-virtual-services.svg
|
||||
#$BIN/helm-diagrams $CHART --set frontend.virtualService.create=true -c custom_diagram.kd -o diagrams/online-boutique-helm-chart-custom-diagram-with-virtual-services.dot_json
|
||||
|
||||
Reference in New Issue
Block a user