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
99# The service name is used for both the release name and the chart name.
10- SERVICE_NAME =" barbican"
10+ SERVICE_NAME_DEFAULT =" barbican"
1111SERVICE_NAMESPACE=" openstack"
1212
1313# Helm
14- HELM_REPO_NAME =" openstack-helm"
15- HELM_REPO_URL =" https://tarballs.opendev.org/openstack/openstack-helm"
14+ HELM_REPO_NAME_DEFAULT =" openstack-helm"
15+ HELM_REPO_URL_DEFAULT =" https://tarballs.opendev.org/openstack/openstack-helm"
1616
1717# Base directories provided by the environment
1818GENESTACK_BASE_DIR=" ${GENESTACK_BASE_DIR:-/ opt/ genestack} "
1919GENESTACK_OVERRIDES_DIR=" ${GENESTACK_OVERRIDES_DIR:-/ etc/ genestack} "
2020
2121# Define service-specific override directories based on the framework
22- SERVICE_BASE_OVERRIDES=" ${GENESTACK_BASE_DIR} /base-helm-configs/${SERVICE_NAME } "
23- 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 } "
2424
2525# Define the Global Overrides directory used in the original script
26- GLOBAL_OVERRIDES =" ${GENESTACK_OVERRIDES_DIR} /helm-configs/global_overrides"
26+ GLOBAL_OVERRIDES_DIR =" ${GENESTACK_OVERRIDES_DIR} /helm-configs/global_overrides"
2727
2828# Read the desired chart version from VERSION_FILE
2929VERSION_FILE=" ${GENESTACK_OVERRIDES_DIR} /helm-chart-versions.yaml"
@@ -33,20 +33,55 @@ if [ ! -f "$VERSION_FILE" ]; then
3333 exit 1
3434fi
3535
36- # Extract version dynamically.
37- 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 } : *//" )
3838
3939if [ -z " $SERVICE_VERSION " ]; then
40- 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
4141 exit 1
4242fi
4343
44- 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 "
4579
4680# Prepare an array to collect -f arguments
4781overrides_args=()
4882
49- # 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.
5085if [[ -d " $SERVICE_BASE_OVERRIDES " ]]; then
5186 echo " Including base overrides from directory: $SERVICE_BASE_OVERRIDES "
5287 for file in " $SERVICE_BASE_OVERRIDES " /* .yaml; do
6095 echo " Warning: Base override directory not found: $SERVICE_BASE_OVERRIDES "
6196fi
6297
63- # Include Global Overrides
64- if [[ -d " $GLOBAL_OVERRIDES " ]]; then
65- echo " Including global overrides from directory: $GLOBAL_OVERRIDES "
66- 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
67103 if [[ -e " $file " ]]; then
68104 echo " - $file "
69105 overrides_args+=(" -f" " $file " )
70106 fi
71107 done
72108else
73- echo " Warning: Global override directory not found: $GLOBAL_OVERRIDES "
109+ echo " Warning: Global override directory not found: $GLOBAL_OVERRIDES_DIR "
74110fi
75111
76112# Include all YAML files from the custom SERVICE configuration directory
113+ # NOTE: Files here have the highest precedence.
77114if [[ -d " $SERVICE_CUSTOM_OVERRIDES " ]]; then
78- echo " Including overrides from config directory:"
115+ echo " Including overrides from service config directory:"
79116 for file in " $SERVICE_CUSTOM_OVERRIDES " /* .yaml; do
80117 if [[ -e " $file " ]]; then
81118 echo " - $file "
82119 overrides_args+=(" -f" " $file " )
83120 fi
84121 done
85122else
86- echo " Warning: Config directory not found: $SERVICE_OVERRIDES "
123+ echo " Warning: Service config directory not found: $SERVICE_CUSTOM_OVERRIDES "
87124fi
88125
89126echo
90127
91- # --- Helm Repository and Execution ---
92- helm repo add " $HELM_REPO_NAME " " $HELM_REPO_URL "
93- helm repo update
94-
95128# Collect all --set arguments, executing commands and quoting safely
96129set_args=(
97130 --set " endpoints.identity.auth.admin.password=$( kubectl --namespace openstack get secret keystone-admin -o jsonpath=' {.data.password}' | base64 -d) "
@@ -106,7 +139,7 @@ set_args=(
106139
107140
108141helm_command=(
109- helm upgrade --install " $SERVICE_NAME " " $HELM_REPO_NAME " / " $SERVICE_NAME "
142+ helm upgrade --install " $SERVICE_NAME_DEFAULT " " $HELM_CHART_PATH "
110143 --version " ${SERVICE_VERSION} "
111144 --namespace=" $SERVICE_NAMESPACE "
112145 --timeout 120m
@@ -117,7 +150,7 @@ helm_command=(
117150
118151 # Post-renderer configuration
119152 --post-renderer " $GENESTACK_OVERRIDES_DIR /kustomize/kustomize.sh"
120- --post-renderer-args " $SERVICE_NAME /overlay"
153+ --post-renderer-args " $SERVICE_NAME_DEFAULT /overlay"
121154
122155 " $@ "
123156)
@@ -127,5 +160,4 @@ printf '%q ' "${helm_command[@]}"
127160echo
128161
129162# Execute the command directly from the array
130- " ${helm_command[@]} "
131-
163+ " ${helm_command[@]} "
0 commit comments