Skip to content

Commit f2cfbbe

Browse files
committed
create empty configmap if no alerts defined to satisfy volume mount
1 parent 077d070 commit f2cfbbe

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

monitoring/bin/deploy_monitoring_cluster.sh

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -374,9 +374,8 @@ log_debug "Installing Helm chart from artifact [$chart2install]"
374374
log_verbose "Creating Grafana alert rules ConfigMap"
375375
CUSTOM_ALERT_CONFIG_DIR="$USER_DIR/monitoring/alerting/"
376376

377-
# Add optional custom directory if it exists
378-
if [ -d "$CUSTOM_ALERT_CONFIG_DIR" ]; then
379-
log_debug "Including notifiers and additional alert rules from '$CUSTOM_ALERT_CONFIG_DIR'"
377+
if [ -d "$CUSTOM_ALERT_CONFIG_DIR" ] && [ "$(ls -A "$CUSTOM_ALERT_CONFIG_DIR" 2>/dev/null)" ]; then
378+
log_debug "Creating configmap for alert rules/notifiers/contact points defined in '$CUSTOM_ALERT_CONFIG_DIR'"
380379
CM_ARGS=(--from-file="$CUSTOM_ALERT_CONFIG_DIR")
381380

382381
# Run the kubectl command with all arguments
@@ -385,7 +384,12 @@ if [ -d "$CUSTOM_ALERT_CONFIG_DIR" ]; then
385384
-n "$MON_NS" \
386385
--dry-run=client -o yaml | kubectl apply -f -
387386
else
388-
log_debug "No custom alert config directory found at '$CUSTOM_ALERT_CONFIG_DIR'. Skipping."
387+
log_debug "No custom alert files found at '$CUSTOM_ALERT_CONFIG_DIR'. Creating empty ConfigMap."
388+
# Create an empty ConfigMap to satisfy the volume mount
389+
kubectl create configmap grafana-alert-rules \
390+
-n "$MON_NS" \
391+
--from-literal=_README.txt="Copy alert rules from samples/alerts to $USER_DIR/monitoring/alerting/ to enable them." \
392+
--dry-run=client -o yaml | kubectl apply -f -
389393
fi
390394

391395
# shellcheck disable=SC2086

0 commit comments

Comments
 (0)