This commit is contained in:
alessandro
2026-09-21 10:00:05 +02:00
parent 48f3f1ff22
commit d190719c5e
3 changed files with 541 additions and 38 deletions
+5 -1
View File
@@ -50,11 +50,15 @@ printf '\nenv=%s\n' "$ENV" >> "$TMP_VALUES_FILE"
printf 'namespace=%s\n' "$NAMESPACE" >> "$TMP_VALUES_FILE"
printf 'project=%s\n' "$PROJECT_NAME" >> "$TMP_VALUES_FILE"
# Ricava endpoint se presente e genera endpoint-nodot sostituendo '.' con '-'
# Ricava endpoint se presente e genera le variabili derivate per le sostituzioni YAML.
ENDPOINT_VAL=$(grep -E '^[[:space:]]*endpoint[[:space:]]*=' "$TMP_VALUES_FILE" "$PROPERTIES_FILE" 2>/dev/null | tail -n 1 | sed -E 's/.*endpoint[[:space:]]*=[[:space:]]*//' | tr -d '\r\n[:space:]"' || true)
if [ -n "$ENDPOINT_VAL" ]; then
ENDPOINT_NODOT=$(echo "$ENDPOINT_VAL" | tr '.' '-')
ENDPOINT_NOSPACE=$(echo "$ENDPOINT_VAL" | tr -d '.')
printf 'endpoint-nodot=%s\n' "$ENDPOINT_NODOT" >> "$TMP_VALUES_FILE"
printf 'endpoint-nospace=%s\n' "$ENDPOINT_NOSPACE" >> "$TMP_VALUES_FILE"
fi
# Trova tutti i file .yaml nella directory kubernetes e sottodirectory
-37
View File
@@ -7,44 +7,7 @@ ENVIRONMENT="${1:-dev}"
YAML_DIR="kubernetes"
# ---------------------------------------------------------------------------
# Cerca risorse postgresql.cnpg.io/v1 nei manifest e deploya una ConfigMap
# ---------------------------------------------------------------------------
CNPG_FILE=$(grep -rl "postgresql.cnpg.io/v1" "$YAML_DIR" 2>/dev/null | head -1 || true)
if [ -n "$CNPG_FILE" ]; then
echo "Trovata risorsa postgresql.cnpg.io/v1 in: $CNPG_FILE"
# Estrae metadata.name dal manifest CNPG preferendo yq, altrimenti awk
if command -v yq >/dev/null 2>&1; then
PG_NAME=$(yq eval 'select(.apiVersion == "postgresql.cnpg.io/v1") | .metadata.name' "$CNPG_FILE")
else
PG_NAME=$(awk '/postgresql\.cnpg\.io\/v1/{found=1} found && /^metadata:/{meta=1} meta && /^\s+name:/{print $2; exit}' "$CNPG_FILE")
fi
# Ricava il namespace dal Role namespace-deployer presente nel cluster
PG_NS=$(kubectl --kubeconfig=./kubeconfig get role namespace-deployer \
--no-headers \
-o custom-columns='NS:.metadata.namespace' 2>/dev/null | head -1 || true)
#PG_NS="${PG_NS:-default}"
if [ -z "$PG_NAME" ]; then
echo "⚠️ Impossibile estrarre metadata.name dal cluster CNPG, skip ConfigMap." >&2
else
echo " → cluster: $PG_NAME namespace: $PG_NS"
kubectl --kubeconfig=./kubeconfig apply -f - <<EOF
apiVersion: v1
kind: ConfigMap
metadata:
name: service-config
namespace: ${PG_NS}
data:
tipodb: "postgres"
urldb: "${PG_NAME}.${PG_NS}.svc.cluster.local"
EOF
echo "ConfigMap db-config deployata in namespace ${PG_NS}."
fi
fi
# ---------------------------------------------------------------------------
# Deploy di tutti i manifest Kubernetes