This commit is contained in:
alessandro barucci
2026-08-09 17:04:22 +02:00
3 changed files with 17 additions and 11 deletions

View File

@@ -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 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 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 kubectl create namespace database

View File

@@ -29,18 +29,18 @@ if [[ -z "$HOSTNAME_VAL" || -z "$NAME_VAL" || -z "$SECRET_NAME" ]]; then
fi fi
# Controlla idempotenza: verifica se il listener esiste già per nome o hostname # Controlla idempotenza: verifica se il listener esiste già per nome o hostname
EXISTING=$(kubectl get gateway "$GATEWAY_NAME" -n "$GATEWAY_NS" \ EXISTING_NAME=$(kubectl get gateway "$GATEWAY_NAME" -n "$GATEWAY_NS" \
-o jsonpath='{.spec.listeners[*].name}') -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." echo "Attenzione: listener con name '${NAME_VAL}' già presente. Nessuna modifica."
exit 0 exit 0
fi fi
EXISTING_HOSTS=$(kubectl get gateway "$GATEWAY_NAME" -n "$GATEWAY_NS" \ EXISTING_HOST=$(kubectl get gateway "$GATEWAY_NAME" -n "$GATEWAY_NS" \
-o jsonpath='{.spec.listeners[*].hostname}') -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." echo "Attenzione: listener con hostname '${HOSTNAME_VAL}' già presente. Nessuna modifica."
exit 0 exit 0
fi fi

View File

@@ -7,19 +7,23 @@ ENVIRONMENT="${1:-dev}"
PROPERTIES_FILE="${2:-env/${ENVIRONMENT}/values.env}" PROPERTIES_FILE="${2:-env/${ENVIRONMENT}/values.env}"
# Hardening per evitare errori con set -u in esecuzioni/sourcing anomali # Hardening per evitare errori con set -u in esecuzioni/sourcing anomali
: "${PROPERTIES_FILE:=env/${ENVIRONMENT}/values.env}" : "${PROPERTIES_FILE:=env/${ENVIRONMENT}/values.env}"
ENV_DIR="env/${ENVIRONMENT}"
if [[ -n "$ENVIRONMENT" ]]; then if [[ -n "$ENVIRONMENT" ]]; then
echo "Ambiente richiesto: $ENVIRONMENT (chiave usata: endpoint)" echo "Ambiente richiesto: $ENVIRONMENT (chiave usata: endpoint)"
fi fi
if [[ ! -f "${PROPERTIES_FILE:-}" ]]; then if [[ -f "${PROPERTIES_FILE:-}" ]]; then
echo "Warning: file non trovato: ${PROPERTIES_FILE:-<non impostato>}" >&2 # 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:-<non impostato>} e directory non trovata: $ENV_DIR" >&2
exit 0 exit 0
fi 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 # Rimuove eventuali virgolette e spazi ai bordi
endpoint="$(echo "$endpoint_raw" | sed -E 's/^[[:space:]"\x27]+//; s/[[:space:]"\x27]+$//')" endpoint="$(echo "$endpoint_raw" | sed -E 's/^[[:space:]"\x27]+//; s/[[:space:]"\x27]+$//')"