|
1 | | -#!/bin/bash |
2 | | -# Description: Fetches the version for SERVICE_NAME from the specified |
3 | | -# YAML file and executes a helm upgrade/install command with dynamic values files. |
4 | | - |
5 | | -# Disable SC2124 (unused array), SC2145 (array expansion issue), SC2294 (eval) |
6 | | -# shellcheck disable=SC2124,SC2145,SC2294 |
7 | | - |
8 | | -# Service |
9 | | -SERVICE_NAME="barbican-exporter" |
10 | | -SERVICE_NAMESPACE="openstack" |
11 | | - |
12 | | -# Helm |
13 | | -HELM_REPO_NAME="genestack-barbician-exporter-helm-chart" |
14 | | -HELM_REPO_URL="https://github.com/rackerlabs/genestack-barbician-exporter-helm-chart" |
15 | | - |
16 | | -# Base directories provided by the environment |
17 | | -GENESTACK_BASE_DIR="${GENESTACK_BASE_DIR:-/opt/genestack}" |
18 | | -GENESTACK_OVERRIDES_DIR="${GENESTACK_OVERRIDES_DIR:-/etc/genestack}" |
19 | | - |
20 | | -# 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}" |
23 | | - |
24 | | -# Define the Global Overrides directory used in the original script |
25 | | -GLOBAL_OVERRIDES="${GENESTACK_OVERRIDES_DIR}/helm-configs/global_overrides" |
26 | | - |
27 | | -# Read the desired chart version from VERSION_FILE |
28 | | -VERSION_FILE="${GENESTACK_OVERRIDES_DIR}/helm-chart-versions.yaml" |
29 | | - |
30 | | -if [ ! -f "$VERSION_FILE" ]; then |
31 | | - echo "Error: helm-chart-versions.yaml not found at $VERSION_FILE" >&2 |
32 | | - exit 1 |
33 | | -fi |
34 | | - |
35 | | -# Extract version dynamically. |
36 | | -SERVICE_VERSION=$(grep "^[[:space:]]*${SERVICE_NAME}:" "$VERSION_FILE" | sed "s/.*${SERVICE_NAME}: *//") |
37 | | - |
38 | | -if [ -z "$SERVICE_VERSION" ]; then |
39 | | - echo "Error: Could not extract version for '$SERVICE_NAME' from $VERSION_FILE" >&2 |
40 | | -# exit 1 |
41 | | -fi |
42 | | - |
43 | | -echo "Found version for $SERVICE_NAME: $SERVICE_VERSION" |
44 | | - |
45 | | -# Prepare an array to collect -f arguments |
46 | | -overrides_args=() |
47 | | - |
48 | | -# Base Override Files: Check the standard base directory. |
49 | | -if [[ -d "$SERVICE_BASE_OVERRIDES" ]]; then |
50 | | - echo "Including base overrides from directory: $SERVICE_BASE_OVERRIDES" |
51 | | - for file in "$SERVICE_BASE_OVERRIDES"/*.yaml; do |
52 | | - # Check that there is at least one match |
53 | | - if [[ -e "$file" ]]; then |
54 | | - echo " - $file" |
55 | | - overrides_args+=("-f" "$file") |
56 | | - fi |
57 | | - done |
58 | | -else |
59 | | - echo "Warning: Base override directory not found: $SERVICE_BASE_OVERRIDES" |
60 | | -fi |
61 | | - |
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 |
66 | | - if [[ -e "$file" ]]; then |
67 | | - echo " - $file" |
68 | | - overrides_args+=("-f" "$file") |
69 | | - fi |
70 | | - done |
71 | | -else |
72 | | - echo "Warning: Global override directory not found: $GLOBAL_OVERRIDES" |
73 | | -fi |
74 | | - |
75 | | -# Include all YAML files from the custom SERVICE configuration directory |
76 | | -if [[ -d "$SERVICE_CUSTOM_OVERRIDES" ]]; then |
77 | | - echo "Including overrides from config directory:" |
78 | | - for file in "$SERVICE_CUSTOM_OVERRIDES"/*.yaml; do |
79 | | - if [[ -e "$file" ]]; then |
80 | | - echo " - $file" |
81 | | - overrides_args+=("-f" "$file") |
82 | | - fi |
83 | | - done |
84 | | -else |
85 | | - echo "Warning: Config directory not found: $SERVICE_CUSTOM_OVERRIDES" |
86 | | -fi |
87 | | - |
88 | | -echo |
89 | | - |
90 | | -# --- Helm Repository and Execution --- |
91 | | -helm repo add "$HELM_REPO_NAME" "$HELM_REPO_URL" |
92 | | -helm repo update |
93 | | - |
94 | | -# Collect all --set arguments, executing commands and quoting safely |
95 | | -set_args=() |
96 | | - |
97 | | -helm_command=( |
98 | | - helm upgrade --install "$SERVICE_NAME" "$HELM_REPO_NAME/$SERVICE_NAME" |
99 | | -# --version "${SERVICE_VERSION}" |
100 | | - --namespace="$SERVICE_NAMESPACE" |
101 | | - --timeout 120m |
102 | | - --create-namespace |
103 | | - |
104 | | - "${overrides_args[@]}" |
105 | | - "${set_args[@]}" |
106 | | - |
107 | | - # Post-renderer configuration |
108 | | - --post-renderer "$GENESTACK_OVERRIDES_DIR/kustomize/kustomize.sh" |
109 | | - --post-renderer-args "$SERVICE_NAME/overlay" |
110 | | - "$@" |
111 | | -) |
112 | | - |
113 | | -echo "Executing Helm command (arguments are quoted safely):" |
114 | | -printf '%q ' "${helm_command[@]}" |
115 | | -echo |
116 | | - |
117 | | -# Execute the command directly from the array |
118 | | -"${helm_command[@]}" |
| 1 | +#!/bin/bash |
| 2 | +# Description: Fetches the version for SERVICE_NAME from the specified |
| 3 | +# YAML file and executes a helm upgrade/install command with dynamic values files. |
| 4 | + |
| 5 | +# Disable SC2124 (unused array), SC2145 (array expansion issue), SC2294 (eval) |
| 6 | +# shellcheck disable=SC2124,SC2145,SC2294 |
| 7 | + |
| 8 | +# Service |
| 9 | +SERVICE_NAME="barbican-exporter" |
| 10 | +SERVICE_NAMESPACE="openstack" |
| 11 | + |
| 12 | +# Helm |
| 13 | +HELM_REPO_NAME="genestack-barbician-exporter-helm-chart" |
| 14 | +HELM_REPO_URL="https://rackerlabs.github.io/genestack-barbician-exporter-helm-chart" |
| 15 | + |
| 16 | +# Base directories provided by the environment |
| 17 | +GENESTACK_BASE_DIR="${GENESTACK_BASE_DIR:-/opt/genestack}" |
| 18 | +GENESTACK_OVERRIDES_DIR="${GENESTACK_OVERRIDES_DIR:-/etc/genestack}" |
| 19 | + |
| 20 | +# 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}" |
| 23 | + |
| 24 | +# Define the Global Overrides directory used in the original script |
| 25 | +GLOBAL_OVERRIDES="${GENESTACK_OVERRIDES_DIR}/helm-configs/global_overrides" |
| 26 | + |
| 27 | +# Read the desired chart version from VERSION_FILE |
| 28 | +VERSION_FILE="${GENESTACK_OVERRIDES_DIR}/helm-chart-versions.yaml" |
| 29 | + |
| 30 | +if [ ! -f "$VERSION_FILE" ]; then |
| 31 | + echo "Error: helm-chart-versions.yaml not found at $VERSION_FILE" >&2 |
| 32 | + exit 1 |
| 33 | +fi |
| 34 | + |
| 35 | +# Extract version dynamically. |
| 36 | +SERVICE_VERSION=$(grep "^[[:space:]]*${SERVICE_NAME}:" "$VERSION_FILE" | sed "s/.*${SERVICE_NAME}: *//") |
| 37 | + |
| 38 | +if [ -z "$SERVICE_VERSION" ]; then |
| 39 | + echo "Error: Could not extract version for '$SERVICE_NAME' from $VERSION_FILE" >&2 |
| 40 | +# exit 1 |
| 41 | +fi |
| 42 | + |
| 43 | +echo "Found version for $SERVICE_NAME: $SERVICE_VERSION" |
| 44 | + |
| 45 | +# Prepare an array to collect -f arguments |
| 46 | +overrides_args=() |
| 47 | + |
| 48 | +# Base Override Files: Check the standard base directory. |
| 49 | +if [[ -d "$SERVICE_BASE_OVERRIDES" ]]; then |
| 50 | + echo "Including base overrides from directory: $SERVICE_BASE_OVERRIDES" |
| 51 | + for file in "$SERVICE_BASE_OVERRIDES"/*.yaml; do |
| 52 | + # Check that there is at least one match |
| 53 | + if [[ -e "$file" ]]; then |
| 54 | + echo " - $file" |
| 55 | + overrides_args+=("-f" "$file") |
| 56 | + fi |
| 57 | + done |
| 58 | +else |
| 59 | + echo "Warning: Base override directory not found: $SERVICE_BASE_OVERRIDES" |
| 60 | +fi |
| 61 | + |
| 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 |
| 66 | + if [[ -e "$file" ]]; then |
| 67 | + echo " - $file" |
| 68 | + overrides_args+=("-f" "$file") |
| 69 | + fi |
| 70 | + done |
| 71 | +else |
| 72 | + echo "Warning: Global override directory not found: $GLOBAL_OVERRIDES" |
| 73 | +fi |
| 74 | + |
| 75 | +# Include all YAML files from the custom SERVICE configuration directory |
| 76 | +if [[ -d "$SERVICE_CUSTOM_OVERRIDES" ]]; then |
| 77 | + echo "Including overrides from config directory:" |
| 78 | + for file in "$SERVICE_CUSTOM_OVERRIDES"/*.yaml; do |
| 79 | + if [[ -e "$file" ]]; then |
| 80 | + echo " - $file" |
| 81 | + overrides_args+=("-f" "$file") |
| 82 | + fi |
| 83 | + done |
| 84 | +else |
| 85 | + echo "Warning: Config directory not found: $SERVICE_CUSTOM_OVERRIDES" |
| 86 | +fi |
| 87 | + |
| 88 | +echo |
| 89 | + |
| 90 | +# --- Helm Repository and Execution --- |
| 91 | +helm repo add "$HELM_REPO_NAME" "$HELM_REPO_URL" |
| 92 | +helm repo update |
| 93 | + |
| 94 | +# Collect all --set arguments, executing commands and quoting safely |
| 95 | +set_args=() |
| 96 | + |
| 97 | +helm_command=( |
| 98 | + helm upgrade --install "$SERVICE_NAME" "$HELM_REPO_NAME/$SERVICE_NAME" |
| 99 | +# --version "${SERVICE_VERSION}" |
| 100 | + --namespace="$SERVICE_NAMESPACE" |
| 101 | + --timeout 120m |
| 102 | + --create-namespace |
| 103 | + |
| 104 | + "${overrides_args[@]}" |
| 105 | + "${set_args[@]}" |
| 106 | + |
| 107 | + # Post-renderer configuration |
| 108 | + --post-renderer "$GENESTACK_OVERRIDES_DIR/kustomize/kustomize.sh" |
| 109 | + --post-renderer-args "$SERVICE_NAME/overlay" |
| 110 | + "$@" |
| 111 | +) |
| 112 | + |
| 113 | +echo "Executing Helm command (arguments are quoted safely):" |
| 114 | +printf '%q ' "${helm_command[@]}" |
| 115 | +echo |
| 116 | + |
| 117 | +# Execute the command directly from the array |
| 118 | +"${helm_command[@]}" |
0 commit comments