diff --git a/add-on/postgresql.sh b/add-on/postgresql.sh index 2e19018..cd9001b 100644 --- a/add-on/postgresql.sh +++ b/add-on/postgresql.sh @@ -1,6 +1,8 @@ kubectl apply --server-side -f https://raw.githubusercontent.com/cloudnative-pg/cloudnative-pg/release-1.28/releases/cnpg-1.28.0.yaml--force-conflicts curl -sSfL https://github.com/cloudnative-pg/cloudnative-pg/raw/main/hack/install-cnpg-plugin.sh | sudo sh -s -- -b /usr/local/bin +kubectl apply -f \ + https://github.com/cloudnative-pg/plugin-barman-cloud/releases/download/v0.13.0/manifest.yaml kubectl create namespace database 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 3893daf..a3806f9 100644 --- a/pipeline/addlistener.sh +++ b/pipeline/addlistener.sh @@ -7,19 +7,23 @@ ENVIRONMENT="${1:-dev}" PROPERTIES_FILE="${2:-env/${ENVIRONMENT}/values.env}" # Hardening per evitare errori con set -u in esecuzioni/sourcing anomali : "${PROPERTIES_FILE:=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 [[ -f "${PROPERTIES_FILE:-}" ]]; then + # 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:]]*//')" +elif [[ -d "$ENV_DIR" ]]; then + # 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:]]*//')" +else + echo "Warning: file non trovato: ${PROPERTIES_FILE:-} e 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:]]*//')" - # Rimuove eventuali virgolette e spazi ai bordi endpoint="$(echo "$endpoint_raw" | sed -E 's/^[[:space:]"\x27]+//; s/[[:space:]"\x27]+$//')"