From c431fc36c5f00dc47edcfb1e08802d1fcf1dc690 Mon Sep 17 00:00:00 2001 From: alessandro Date: Thu, 30 Jul 2026 09:56:19 +0200 Subject: [PATCH] fix pipeline --- pipeline/add-listener.sh | 12 ++++++------ pipeline/addlistener.sh | 10 +++++----- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/pipeline/add-listener.sh b/pipeline/add-listener.sh index b5ffc24..4873a3a 100644 --- a/pipeline/add-listener.sh +++ b/pipeline/add-listener.sh @@ -29,18 +29,18 @@ if [[ -z "$HOSTNAME_VAL" || -z "$NAME_VAL" || -z "$SECRET_NAME" ]]; then fi # Controlla idempotenza: verifica se il listener esiste già per nome o hostname -EXISTING=$(kubectl get gateway "$GATEWAY_NAME" -n "$GATEWAY_NS" \ - -o jsonpath='{.spec.listeners[*].name}') +EXISTING_NAME=$(kubectl get gateway "$GATEWAY_NAME" -n "$GATEWAY_NS" \ + -o jsonpath='{.spec.listeners[?(@.name=="'"${NAME_VAL}"'")].name}') -if echo "$EXISTING" | grep -qw "$NAME_VAL"; then +if [[ -n "$EXISTING_NAME" ]]; then echo "Attenzione: listener con name '${NAME_VAL}' già presente. Nessuna modifica." exit 0 fi -EXISTING_HOSTS=$(kubectl get gateway "$GATEWAY_NAME" -n "$GATEWAY_NS" \ - -o jsonpath='{.spec.listeners[*].hostname}') +EXISTING_HOST=$(kubectl get gateway "$GATEWAY_NAME" -n "$GATEWAY_NS" \ + -o jsonpath='{.spec.listeners[?(@.hostname=="'"${HOSTNAME_VAL}"'")].hostname}') -if echo "$EXISTING_HOSTS" | grep -qw "$HOSTNAME_VAL"; then +if [[ -n "$EXISTING_HOST" ]]; then echo "Attenzione: listener con hostname '${HOSTNAME_VAL}' già presente. Nessuna modifica." exit 0 fi diff --git a/pipeline/addlistener.sh b/pipeline/addlistener.sh index 0eeda21..4ffb297 100644 --- a/pipeline/addlistener.sh +++ b/pipeline/addlistener.sh @@ -4,19 +4,19 @@ set -euo pipefail # Uso: ./addlistener.sh [env] [properties_file] # env e' ignorato: endpoint viene sempre letto dalla chiave "endpoint". ENVIRONMENT="${1:-dev}" -PROPERTIES_FILE="${2:-env/${ENVIRONMENT}/values.env}" +ENV_DIR="env/${ENVIRONMENT}" if [[ -n "$ENVIRONMENT" ]]; then echo "Ambiente richiesto: $ENVIRONMENT (chiave usata: endpoint)" fi -if [[ ! -f "$PROPERTIES_FILE" ]]; then - echo "Warning: file non trovato: $PROPERTIES_FILE" >&2 +if [[ ! -d "$ENV_DIR" ]]; then + echo "Warning: directory non trovata: $ENV_DIR" >&2 exit 0 fi -# Estrae endpoint ignorando commenti e spazi, supportando anche endpoint = valore -endpoint_raw="$({ grep -E '^[[:space:]]*endpoint[[:space:]]*=' "$PROPERTIES_FILE" | tail -n1 || true; } | sed -E 's/^[[:space:]]*endpoint[[:space:]]*=[[:space:]]*//')" +# Estrae endpoint da qualsiasi file .env nella directory dell'ambiente +endpoint_raw="$({ grep -r '^[[:space:]]*endpoint[[:space:]]*=' "$ENV_DIR" 2>/dev/null | head -n1 || true; } | sed -E 's/^[^:]*:[[:space:]]*endpoint[[:space:]]*=[[:space:]]*//')" # Rimuove eventuali virgolette e spazi ai bordi endpoint="$(echo "$endpoint_raw" | sed -E 's/^[[:space:]"\x27]+//; s/[[:space:]"\x27]+$//')"