Skip to content

Commit add95aa

Browse files
committed
Add support for custom Helm chart repo, URL, and service name in loki installer script
1 parent eeb69b1 commit add95aa

File tree

1 file changed

+55
-18
lines changed

1 file changed

+55
-18
lines changed

bin/install-loki.sh

Lines changed: 55 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,27 @@
11
#!/bin/bash
2-
# Description: Fetches the version for Loki from the specified YAML file and executes a helm upgrade/install command.
2+
# Description: Fetches the version for SERVICE_NAME_DEFAULT from the specified
3+
# YAML file and executes a helm upgrade/install command with dynamic values files.
34

45
# Disable SC2124 (unused array), SC2145 (array expansion issue), SC2294 (eval)
56
# shellcheck disable=SC2124,SC2145,SC2294
67

78
# Service
8-
SERVICE_NAME="loki"
9+
SERVICE_NAME_DEFAULT="loki"
910
SERVICE_NAMESPACE="grafana"
1011

1112
# Helm
12-
HELM_REPO_NAME="grafana"
13-
HELM_REPO_URL="https://grafana.github.io/helm-charts"
13+
HELM_REPO_NAME_DEFAULT="grafana"
14+
HELM_REPO_URL_DEFAULT="https://grafana.github.io/helm-charts"
1415

1516
# Base directories provided by the environment
1617
GENESTACK_BASE_DIR="${GENESTACK_BASE_DIR:-/opt/genestack}"
1718
GENESTACK_OVERRIDES_DIR="${GENESTACK_OVERRIDES_DIR:-/etc/genestack}"
1819

1920
# Define service-specific override directories based on the framework
20-
SERVICE_BASE_OVERRIDES="${GENESTACK_BASE_DIR}/base-helm-configs/${SERVICE_NAME}"
21-
SERVICE_CUSTOM_OVERRIDES="${GENESTACK_OVERRIDES_DIR}/helm-configs/${SERVICE_NAME}"
21+
SERVICE_BASE_OVERRIDES="${GENESTACK_BASE_DIR}/base-helm-configs/${SERVICE_NAME_DEFAULT}"
22+
SERVICE_CUSTOM_OVERRIDES="${GENESTACK_OVERRIDES_DIR}/helm-configs/${SERVICE_NAME_DEFAULT}"
23+
24+
# Define the Global Overrides directory used in the original script
2225
GLOBAL_OVERRIDES_DIR="${GENESTACK_OVERRIDES_DIR}/helm-configs/global_overrides"
2326

2427
# Read the desired chart version from VERSION_FILE
@@ -29,23 +32,58 @@ if [ ! -f "$VERSION_FILE" ]; then
2932
exit 1
3033
fi
3134

32-
# Extract version dynamically using the SERVICE_NAME variable
33-
SERVICE_VERSION=$(grep "^[[:space:]]*${SERVICE_NAME}:" "$VERSION_FILE" | sed "s/.*${SERVICE_NAME}: *//")
35+
# Extract version dynamically using the SERVICE_NAME_DEFAULT variable
36+
SERVICE_VERSION=$(grep "^[[:space:]]*${SERVICE_NAME_DEFAULT}:" "$VERSION_FILE" | sed "s/.*${SERVICE_NAME_DEFAULT}: *//")
3437

3538
if [ -z "$SERVICE_VERSION" ]; then
36-
echo "Error: Could not extract version for '$SERVICE_NAME' from $VERSION_FILE" >&2
39+
echo "Error: Could not extract version for '$SERVICE_NAME_DEFAULT' from $VERSION_FILE" >&2
3740
exit 1
3841
fi
3942

40-
echo "Found version for $SERVICE_NAME: $SERVICE_VERSION"
43+
echo "Found version for $SERVICE_NAME_DEFAULT: $SERVICE_VERSION"
44+
45+
# Load chart metadata from custom override YAML if defined
46+
for yaml_file in "${SERVICE_CUSTOM_OVERRIDES}"/*.yaml; do
47+
if [ -f "$yaml_file" ]; then
48+
HELM_REPO_URL=$(yq eval '.chart.repo_url // ""' "$yaml_file")
49+
HELM_REPO_NAME=$(yq eval '.chart.repo_name // ""' "$yaml_file")
50+
SERVICE_NAME=$(yq eval '.chart.service_name // ""' "$yaml_file")
51+
break # use the first match and stop
52+
fi
53+
done
54+
55+
# Fallback to defaults if variables not set
56+
: "${HELM_REPO_URL:=$HELM_REPO_URL_DEFAULT}"
57+
: "${HELM_REPO_NAME:=$HELM_REPO_NAME_DEFAULT}"
58+
: "${SERVICE_NAME:=$SERVICE_NAME_DEFAULT}"
59+
60+
61+
# Determine Helm chart path
62+
if [[ "$HELM_REPO_URL" == oci://* ]]; then
63+
# OCI registry path
64+
HELM_CHART_PATH="$HELM_REPO_URL/$HELM_REPO_NAME/$SERVICE_NAME"
65+
else
66+
# --- Helm Repository and Execution ---
67+
helm repo add "$HELM_REPO_NAME" "$HELM_REPO_URL" # uncomment if needed
68+
helm repo update
69+
HELM_CHART_PATH="$HELM_REPO_NAME/$SERVICE_NAME"
70+
fi
71+
72+
# Debug output
73+
echo "[DEBUG] HELM_REPO_URL=$HELM_REPO_URL"
74+
echo "[DEBUG] HELM_REPO_NAME=$HELM_REPO_NAME"
75+
echo "[DEBUG] SERVICE_NAME=$SERVICE_NAME"
76+
echo "[DEBUG] HELM_CHART_PATH=$HELM_CHART_PATH"
4177

4278
# Prepare an array to collect -f arguments
4379
overrides_args=()
4480

4581
# Include all YAML files from the BASE configuration directory
82+
# NOTE: Files in this directory are included first.
4683
if [[ -d "$SERVICE_BASE_OVERRIDES" ]]; then
4784
echo "Including base overrides from directory: $SERVICE_BASE_OVERRIDES"
4885
for file in "$SERVICE_BASE_OVERRIDES"/*.yaml; do
86+
# Check that there is at least one match
4987
if [[ -e "$file" ]]; then
5088
echo " - $file"
5189
overrides_args+=("-f" "$file")
@@ -56,19 +94,21 @@ else
5694
fi
5795

5896
# Include all YAML files from the GLOBAL configuration directory
97+
# NOTE: Files here override base settings and are applied before service-specific ones.
5998
if [[ -d "$GLOBAL_OVERRIDES_DIR" ]]; then
60-
echo "Including overrides from global config directory:"
99+
echo "Including global overrides from directory: $GLOBAL_OVERRIDES_DIR"
61100
for file in "$GLOBAL_OVERRIDES_DIR"/*.yaml; do
62101
if [[ -e "$file" ]]; then
63102
echo " - $file"
64103
overrides_args+=("-f" "$file")
65104
fi
66105
done
67106
else
68-
echo "Warning: Global config directory not found: $GLOBAL_OVERRIDES_DIR"
107+
echo "Warning: Global override directory not found: $GLOBAL_OVERRIDES_DIR"
69108
fi
70109

71110
# Include all YAML files from the custom SERVICE configuration directory
111+
# NOTE: Files here have the highest precedence.
72112
if [[ -d "$SERVICE_CUSTOM_OVERRIDES" ]]; then
73113
echo "Including overrides from service config directory:"
74114
for file in "$SERVICE_CUSTOM_OVERRIDES"/*.yaml; do
@@ -83,16 +123,12 @@ fi
83123

84124
echo
85125

86-
# --- Helm Repository and Execution ---
87-
helm repo add "$HELM_REPO_NAME" "$HELM_REPO_URL"
88-
helm repo update
89-
90126
# Collect all --set arguments.
91127
set_args=()
92128

93129

94130
helm_command=(
95-
helm upgrade --install "$SERVICE_NAME" "$HELM_REPO_NAME/$SERVICE_NAME"
131+
helm upgrade --install "$SERVICE_NAME_DEFAULT" "$HELM_CHART_PATH"
96132
--version "${SERVICE_VERSION}"
97133
--namespace="$SERVICE_NAMESPACE"
98134
--timeout 120m
@@ -101,8 +137,9 @@ helm_command=(
101137
"${overrides_args[@]}"
102138
"${set_args[@]}"
103139

140+
# Post-renderer configuration
104141
--post-renderer "$GENESTACK_OVERRIDES_DIR/kustomize/kustomize.sh"
105-
--post-renderer-args "$SERVICE_NAME/overlay"
142+
--post-renderer-args "$SERVICE_NAME_DEFAULT/overlay"
106143

107144
"$@"
108145
)

0 commit comments

Comments
 (0)