11#! /bin/bash
2- # Description: Fetches the version for SERVICE_NAME from the specified
2+ # Description: Fetches the version for SERVICE_NAME_DEFAULT from the specified
33# YAML file and executes a helm upgrade/install command with dynamic values files.
44
55# Disable SC2124 (unused array), SC2145 (array expansion issue), SC2294 (eval)
66# shellcheck disable=SC2124,SC2145,SC2294
77
88# Service
9- SERVICE_NAME=" barbican-exporter"
9+ # The service name is used for both the release name and the chart name.
10+ SERVICE_NAME_DEFAULT=" barbican-exporter"
1011SERVICE_NAMESPACE=" openstack"
1112
1213# Helm
13- HELM_REPO_NAME =" genestack-barbician-exporter-helm-chart"
14- HELM_REPO_URL =" https://rackerlabs.github.io/genestack-barbician-exporter-helm-chart"
14+ HELM_REPO_NAME_DEFAULT =" genestack-barbician-exporter-helm-chart"
15+ HELM_REPO_URL_DEFAULT =" https://rackerlabs.github.io/genestack-barbician-exporter-helm-chart"
1516
1617# Base directories provided by the environment
1718GENESTACK_BASE_DIR=" ${GENESTACK_BASE_DIR:-/ opt/ genestack} "
1819GENESTACK_OVERRIDES_DIR=" ${GENESTACK_OVERRIDES_DIR:-/ etc/ genestack} "
1920
2021# Define service-specific override directories based on the framework
21- SERVICE_BASE_OVERRIDES=" ${GENESTACK_BASE_DIR} /base-helm-configs/${SERVICE_NAME } "
22- SERVICE_CUSTOM_OVERRIDES=" ${GENESTACK_OVERRIDES_DIR} /helm-configs/${SERVICE_NAME } "
22+ SERVICE_BASE_OVERRIDES=" ${GENESTACK_BASE_DIR} /base-helm-configs/${SERVICE_NAME_DEFAULT } "
23+ SERVICE_CUSTOM_OVERRIDES=" ${GENESTACK_OVERRIDES_DIR} /helm-configs/${SERVICE_NAME_DEFAULT } "
2324
2425# Define the Global Overrides directory used in the original script
25- GLOBAL_OVERRIDES =" ${GENESTACK_OVERRIDES_DIR} /helm-configs/global_overrides"
26+ GLOBAL_OVERRIDES_DIR =" ${GENESTACK_OVERRIDES_DIR} /helm-configs/global_overrides"
2627
2728# Read the desired chart version from VERSION_FILE
2829VERSION_FILE=" ${GENESTACK_OVERRIDES_DIR} /helm-chart-versions.yaml"
@@ -32,20 +33,55 @@ if [ ! -f "$VERSION_FILE" ]; then
3233 exit 1
3334fi
3435
35- # Extract version dynamically.
36- SERVICE_VERSION=$( grep " ^[[:space:]]*${SERVICE_NAME } :" " $VERSION_FILE " | sed " s/.*${SERVICE_NAME } : *//" )
36+ # Extract version dynamically using the SERVICE_NAME_DEFAULT variable
37+ SERVICE_VERSION=$( grep " ^[[:space:]]*${SERVICE_NAME_DEFAULT } :" " $VERSION_FILE " | sed " s/.*${SERVICE_NAME_DEFAULT } : *//" )
3738
3839if [ -z " $SERVICE_VERSION " ]; then
39- echo " Error: Could not extract version for '$SERVICE_NAME ' from $VERSION_FILE " >&2
40+ echo " Error: Could not extract version for '$SERVICE_NAME_DEFAULT ' from $VERSION_FILE " >&2
4041# exit 1
4142fi
4243
43- echo " Found version for $SERVICE_NAME : $SERVICE_VERSION "
44+ echo " Found version for $SERVICE_NAME_DEFAULT : $SERVICE_VERSION "
45+
46+ # Load chart metadata from custom override YAML if defined
47+ for yaml_file in " ${SERVICE_CUSTOM_OVERRIDES} " /* .yaml; do
48+ if [ -f " $yaml_file " ]; then
49+ HELM_REPO_URL=$( yq eval ' .chart.repo_url // ""' " $yaml_file " )
50+ HELM_REPO_NAME=$( yq eval ' .chart.repo_name // ""' " $yaml_file " )
51+ SERVICE_NAME=$( yq eval ' .chart.service_name // ""' " $yaml_file " )
52+ break # use the first match and stop
53+ fi
54+ done
55+
56+ # Fallback to defaults if variables not set
57+ : " ${HELM_REPO_URL:= $HELM_REPO_URL_DEFAULT } "
58+ : " ${HELM_REPO_NAME:= $HELM_REPO_NAME_DEFAULT } "
59+ : " ${SERVICE_NAME:= $SERVICE_NAME_DEFAULT } "
60+
61+
62+ # Determine Helm chart path
63+ if [[ " $HELM_REPO_URL " == oci://* ]]; then
64+ # OCI registry path
65+ HELM_CHART_PATH=" $HELM_REPO_URL /$HELM_REPO_NAME /$SERVICE_NAME "
66+ else
67+ # --- Helm Repository and Execution ---
68+ helm repo add " $HELM_REPO_NAME " " $HELM_REPO_URL " # uncomment if needed
69+ helm repo update
70+ HELM_CHART_PATH=" $HELM_REPO_NAME /$SERVICE_NAME "
71+ fi
72+
73+
74+ # Debug output
75+ echo " [DEBUG] HELM_REPO_URL=$HELM_REPO_URL "
76+ echo " [DEBUG] HELM_REPO_NAME=$HELM_REPO_NAME "
77+ echo " [DEBUG] SERVICE_NAME=$SERVICE_NAME "
78+ echo " [DEBUG] HELM_CHART_PATH=$HELM_CHART_PATH "
4479
4580# Prepare an array to collect -f arguments
4681overrides_args=()
4782
48- # Base Override Files: Check the standard base directory.
83+ # Include all YAML files from the BASE configuration directory
84+ # NOTE: Files in this directory are included first.
4985if [[ -d " $SERVICE_BASE_OVERRIDES " ]]; then
5086 echo " Including base overrides from directory: $SERVICE_BASE_OVERRIDES "
5187 for file in " $SERVICE_BASE_OVERRIDES " /* .yaml; do
5995 echo " Warning: Base override directory not found: $SERVICE_BASE_OVERRIDES "
6096fi
6197
62- # Include Global Overrides
63- if [[ -d " $GLOBAL_OVERRIDES " ]]; then
64- echo " Including global overrides from directory: $GLOBAL_OVERRIDES "
65- for file in " $GLOBAL_OVERRIDES " /* .yaml; do
98+ # Include all YAML files from the GLOBAL configuration directory
99+ # NOTE: Files here override base settings and are applied before service-specific ones.
100+ if [[ -d " $GLOBAL_OVERRIDES_DIR " ]]; then
101+ echo " Including global overrides from directory: $GLOBAL_OVERRIDES_DIR "
102+ for file in " $GLOBAL_OVERRIDES_DIR " /* .yaml; do
66103 if [[ -e " $file " ]]; then
67104 echo " - $file "
68105 overrides_args+=(" -f" " $file " )
69106 fi
70107 done
71108else
72- echo " Warning: Global override directory not found: $GLOBAL_OVERRIDES "
109+ echo " Warning: Global override directory not found: $GLOBAL_OVERRIDES_DIR "
73110fi
74111
75112# Include all YAML files from the custom SERVICE configuration directory
113+ # NOTE: Files here have the highest precedence.
76114if [[ -d " $SERVICE_CUSTOM_OVERRIDES " ]]; then
77- echo " Including overrides from config directory:"
115+ echo " Including overrides from service config directory:"
78116 for file in " $SERVICE_CUSTOM_OVERRIDES " /* .yaml; do
79117 if [[ -e " $file " ]]; then
80118 echo " - $file "
81119 overrides_args+=(" -f" " $file " )
82120 fi
83121 done
84122else
85- echo " Warning: Config directory not found: $SERVICE_CUSTOM_OVERRIDES "
123+ echo " Warning: Service config directory not found: $SERVICE_CUSTOM_OVERRIDES "
86124fi
87125
88126echo
89127
90- # --- Helm Repository and Execution ---
91- helm repo add " $HELM_REPO_NAME " " $HELM_REPO_URL "
92- helm repo update
93-
94128# Collect all --set arguments, executing commands and quoting safely
95129set_args=()
96130
97131helm_command=(
98- helm upgrade --install " $SERVICE_NAME " " $HELM_REPO_NAME / $SERVICE_NAME "
132+ helm upgrade --install " $SERVICE_NAME_DEFAULT " " $HELM_CHART_PATH "
99133# --version "${SERVICE_VERSION}"
100134 --namespace=" $SERVICE_NAMESPACE "
101135 --timeout 120m
@@ -106,7 +140,8 @@ helm_command=(
106140
107141 # Post-renderer configuration
108142 --post-renderer " $GENESTACK_OVERRIDES_DIR /kustomize/kustomize.sh"
109- --post-renderer-args " $SERVICE_NAME /overlay"
143+ --post-renderer-args " $SERVICE_NAME_DEFAULT /overlay"
144+
110145 " $@ "
111146)
112147
0 commit comments