devzone 0.18.3 → 0.18.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/.devcontainer/cluster.sh
CHANGED
|
@@ -7,9 +7,11 @@
|
|
|
7
7
|
# Bibliothèque sourcée : l'appelant définit RACINE et ETAT.
|
|
8
8
|
# cluster_lu contexte choisi, rien s'il n'y en a pas
|
|
9
9
|
# cluster_ecrire CTX garde le choix dans l'état
|
|
10
|
-
#
|
|
11
|
-
#
|
|
12
|
-
#
|
|
10
|
+
# cluster_est_local CTX 0 si cluster local (config, sans réseau)
|
|
11
|
+
# cluster_candidats locaux, puis kind dédié, puis distants
|
|
12
|
+
# cluster_choisir [CTX] CTX validé (distant : confirmation),
|
|
13
|
+
# sinon choix gardé, sinon menu
|
|
14
|
+
# (terminal seulement), sinon défaut local
|
|
13
15
|
# cluster_preparer CTX crée le cluster kind dédié s'il manque
|
|
14
16
|
# cluster_liberer CTX supprime le kind dédié devenu vide
|
|
15
17
|
# kube_joignable_depuis_conteneur FICHIER réécrit 127.0.0.1/localhost
|
|
@@ -60,20 +62,64 @@ cluster_est_dedie() {
|
|
|
60
62
|
[ "$1" = "${CLUSTER_DEDIE}" ]
|
|
61
63
|
}
|
|
62
64
|
|
|
65
|
+
# Cluster local : lu dans la configuration KUBECONFIG, sans appel réseau.
|
|
66
|
+
# Le kind dédié est toujours local ; un cluster de l'hôte l'est si son
|
|
67
|
+
# serveur écoute sur une adresse de boucle (127.0.0.1, localhost, ::1,
|
|
68
|
+
# host.docker.internal).
|
|
69
|
+
cluster_est_local() {
|
|
70
|
+
local ctx="$1" cluster serveur hote
|
|
71
|
+
cluster_est_dedie "$ctx" && return 0
|
|
72
|
+
cluster="$(kubectl config view -o jsonpath="{.contexts[?(@.name==\"$ctx\")].context.cluster}" 2>/dev/null || true)"
|
|
73
|
+
[ -n "$cluster" ] || return 1
|
|
74
|
+
serveur="$(kubectl config view -o jsonpath="{.clusters[?(@.name==\"$cluster\")].cluster.server}" 2>/dev/null || true)"
|
|
75
|
+
[ -n "$serveur" ] || return 1
|
|
76
|
+
# Règle par le nom (ancienne règle de metrics-server.sh)
|
|
77
|
+
case "$ctx" in
|
|
78
|
+
kind-* | docker-desktop | rancher-desktop | orbstack | minikube) return 0 ;;
|
|
79
|
+
esac
|
|
80
|
+
# Extraction de l'hôte (adresses IPv6 entre crochets gérées)
|
|
81
|
+
hote="${serveur#*://}"
|
|
82
|
+
hote="${hote%%/*}"
|
|
83
|
+
if [[ "$hote" == \[* ]]; then
|
|
84
|
+
hote="${hote#[}"
|
|
85
|
+
hote="${hote%%]*}"
|
|
86
|
+
else
|
|
87
|
+
hote="${hote%%:*}"
|
|
88
|
+
fi
|
|
89
|
+
case "$hote" in
|
|
90
|
+
127.0.0.1 | localhost | ::1 | host.docker.internal) return 0 ;;
|
|
91
|
+
*-control-plane) return 0 ;;
|
|
92
|
+
esac
|
|
93
|
+
return 1
|
|
94
|
+
}
|
|
95
|
+
|
|
63
96
|
cluster_joignable() {
|
|
64
97
|
kubectl --context "$1" --request-timeout=3s get --raw /readyz >/dev/null 2>&1
|
|
65
98
|
}
|
|
66
99
|
|
|
67
|
-
# Contextes de l'hôte d'abord
|
|
100
|
+
# Contextes de l'hôte : locaux d'abord, puis le kind dédié, enfin les distants
|
|
68
101
|
cluster_candidats() {
|
|
69
102
|
local hote="${DEVZONE_KUBE_HOTE:-$HOME/.kube/hote.config}" c
|
|
70
103
|
if [ -f "$hote" ]; then
|
|
104
|
+
# 1. Clusters locaux de l'hôte (serveur sur une adresse de boucle)
|
|
71
105
|
for c in $(KUBECONFIG="$hote" kubectl config get-contexts -o name 2>/dev/null); do
|
|
72
106
|
cluster_est_dedie "$c" && continue
|
|
73
|
-
|
|
107
|
+
if cluster_est_local "$c" && cluster_joignable "$c"; then
|
|
108
|
+
echo "$c"
|
|
109
|
+
fi
|
|
74
110
|
done
|
|
75
111
|
fi
|
|
112
|
+
# 2. Cluster kind dédié
|
|
76
113
|
echo "$CLUSTER_DEDIE"
|
|
114
|
+
if [ -f "$hote" ]; then
|
|
115
|
+
# 3. Clusters distants de l'hôte
|
|
116
|
+
for c in $(KUBECONFIG="$hote" kubectl config get-contexts -o name 2>/dev/null); do
|
|
117
|
+
cluster_est_dedie "$c" && continue
|
|
118
|
+
if ! cluster_est_local "$c" && cluster_joignable "$c"; then
|
|
119
|
+
echo "$c"
|
|
120
|
+
fi
|
|
121
|
+
done
|
|
122
|
+
fi
|
|
77
123
|
return 0
|
|
78
124
|
}
|
|
79
125
|
|
|
@@ -86,8 +132,10 @@ cluster_menu() {
|
|
|
86
132
|
for c in "${candidats[@]}"; do
|
|
87
133
|
if cluster_est_dedie "$c"; then
|
|
88
134
|
echo " $i) $c cluster kind dédié, dans le conteneur (défaut)"
|
|
135
|
+
elif cluster_est_local "$c"; then
|
|
136
|
+
echo " $i) $c cluster local"
|
|
89
137
|
else
|
|
90
|
-
echo " $i) $c cluster
|
|
138
|
+
echo " $i) $c cluster distant"
|
|
91
139
|
fi
|
|
92
140
|
i=$((i + 1))
|
|
93
141
|
done
|
|
@@ -113,13 +161,36 @@ cluster_interactif() {
|
|
|
113
161
|
}
|
|
114
162
|
|
|
115
163
|
cluster_choisir() {
|
|
116
|
-
local voulu="${1:-}" c
|
|
164
|
+
local voulu="${1:-}" c reponse
|
|
117
165
|
if [ -n "$voulu" ]; then
|
|
118
166
|
while IFS= read -r c; do
|
|
119
|
-
[ "$c" = "$voulu" ] &&
|
|
167
|
+
[ "$c" = "$voulu" ] && break
|
|
120
168
|
done < <(cluster_candidats)
|
|
121
|
-
|
|
122
|
-
|
|
169
|
+
if [ "$c" != "$voulu" ]; then
|
|
170
|
+
echo "devzone : cluster inconnu ou injoignable : $voulu ; possibles : $(cluster_candidats | tr '\n' ' ')" >&2
|
|
171
|
+
return 2
|
|
172
|
+
fi
|
|
173
|
+
# Distant : confirmation requise (sauf DEVZONE_CLUSTER_DISTANT exact)
|
|
174
|
+
if ! cluster_est_local "$voulu"; then
|
|
175
|
+
if [ -n "${DEVZONE_CLUSTER_DISTANT:-}" ]; then
|
|
176
|
+
if [ "${DEVZONE_CLUSTER_DISTANT}" != "$voulu" ]; then
|
|
177
|
+
echo "devzone : cluster distant refusé : $voulu (DEVZONE_CLUSTER_DISTANT doit valoir exactement $voulu)" >&2
|
|
178
|
+
return 2
|
|
179
|
+
fi
|
|
180
|
+
elif cluster_interactif; then
|
|
181
|
+
printf 'cluster distant : %s ; tape son nom pour confirmer : ' "$voulu" >&2
|
|
182
|
+
read -r reponse || reponse=""
|
|
183
|
+
if [ "$reponse" != "$voulu" ]; then
|
|
184
|
+
echo "devzone : cluster distant refusé : $voulu" >&2
|
|
185
|
+
return 2
|
|
186
|
+
fi
|
|
187
|
+
else
|
|
188
|
+
echo "devzone : cluster distant refusé : $voulu (DEVZONE_CLUSTER_DISTANT pour confirmer)" >&2
|
|
189
|
+
return 2
|
|
190
|
+
fi
|
|
191
|
+
fi
|
|
192
|
+
echo "$voulu"
|
|
193
|
+
return 0
|
|
123
194
|
fi
|
|
124
195
|
c="$(cluster_lu)"
|
|
125
196
|
if [ -n "$c" ]; then
|
|
@@ -127,12 +198,12 @@ cluster_choisir() {
|
|
|
127
198
|
elif cluster_interactif; then
|
|
128
199
|
cluster_menu
|
|
129
200
|
else
|
|
130
|
-
# Défaut :
|
|
201
|
+
# Défaut : local seulement (jamais distant par défaut)
|
|
131
202
|
local hote_choix=""
|
|
132
203
|
if [ -f "${DEVZONE_KUBE_HOTE:-$HOME/.kube/hote.config}" ]; then
|
|
133
204
|
hote_choix="$(KUBECONFIG="${DEVZONE_KUBE_HOTE:-$HOME/.kube/hote.config}" kubectl config current-context 2>/dev/null || true)"
|
|
134
205
|
fi
|
|
135
|
-
if [ -n "$hote_choix" ] && cluster_joignable "$hote_choix"; then
|
|
206
|
+
if [ -n "$hote_choix" ] && cluster_est_local "$hote_choix" && cluster_joignable "$hote_choix"; then
|
|
136
207
|
echo "$hote_choix"
|
|
137
208
|
else
|
|
138
209
|
echo "$CLUSTER_DEDIE"
|
package/.devcontainer/devzone
CHANGED
|
@@ -725,6 +725,11 @@ etat() {
|
|
|
725
725
|
printf ' ○ module %-10s facultatif, %s : devzone activer %s\n' "$m" "$(description "$m")" "$m"
|
|
726
726
|
fi
|
|
727
727
|
done
|
|
728
|
+
# Cluster de devzone distant : avertissement dans le récapitulatif
|
|
729
|
+
cluster_actuel="$(cluster_lu)"
|
|
730
|
+
if [ -n "$cluster_actuel" ] && ! cluster_est_local "$cluster_actuel"; then
|
|
731
|
+
printf ' ⚠ cluster distant : %s — services sur un cluster distant\n' "$cluster_actuel"
|
|
732
|
+
fi
|
|
728
733
|
ports_etat="$(bash "$ICI/ports.sh" resume 2>/dev/null || true)"
|
|
729
734
|
case "$ports_etat" in
|
|
730
735
|
aucun*) printf ' ○ ports vers le poste %s\n' "$ports_etat" ;;
|
|
@@ -204,16 +204,19 @@ gitlab_seed() {
|
|
|
204
204
|
echo "✔ Seed GitLab terminé."
|
|
205
205
|
}
|
|
206
206
|
|
|
207
|
-
# ---- relais TCP 127.0.0.1:8929/2224 vers
|
|
207
|
+
# ---- relais TCP 127.0.0.1:8929/2224 vers le nœud kind ----
|
|
208
208
|
# Choix : un socat local détaché par setsid, PID et journal gardés dans
|
|
209
209
|
# workspace/.gitlab-<port>/ comme le relais de cluster.sh. relais_lancer ne
|
|
210
210
|
# convient pas : il fait un kubectl port-forward vers un service du cluster
|
|
211
|
-
# choisi par devzone, alors GitLab est dans le cluster kind `gitlab
|
|
212
|
-
#
|
|
211
|
+
# choisi par devzone, alors GitLab est dans le cluster kind `gitlab`.
|
|
212
|
+
# Le conteneur rejoint le réseau Docker `kind` du nœud (#327) : le relais vise
|
|
213
|
+
# alors <nœud>:80 et <nœud>:32022, indépendamment de la publication des ports
|
|
214
|
+
# de l'hôte (127.0.0.1 seulement). Si le réseau ne peut pas être rejoint, repli
|
|
215
|
+
# sur l'IPv4 de host.docker.internal, comme avant.
|
|
213
216
|
# Pourquoi ce relais : libcurl (curl et git en HTTP) résout tout nom
|
|
214
217
|
# *.localhost vers la boucle locale sans lire /etc/hosts (RFC 6761) ; depuis
|
|
215
218
|
# le conteneur, http://gitlab.localhost:8929 part donc sur son propre
|
|
216
|
-
# 127.0.0.1, où rien n'écoute. Le relais y ramène
|
|
219
|
+
# 127.0.0.1, où rien n'écoute. Le relais y ramène GitLab.
|
|
217
220
|
gitlab_hote_ipv4() {
|
|
218
221
|
local ip
|
|
219
222
|
# ahostsv4 seulement : sous Docker Desktop, getent hosts rend d'abord une
|
|
@@ -223,28 +226,62 @@ gitlab_hote_ipv4() {
|
|
|
223
226
|
printf '%s\n' "$ip"
|
|
224
227
|
}
|
|
225
228
|
|
|
229
|
+
gitlab_noeud() {
|
|
230
|
+
printf 'gitlab%s-control-plane\n' "$INSTANCE_SUFFIX"
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
# Rejoint le réseau Docker du nœud kind ; « already exists » vaut un succès
|
|
234
|
+
# (relance, démarrage). Échec : l'appelant passe par le repli.
|
|
235
|
+
gitlab_reseau_rejoindre() {
|
|
236
|
+
local sortie
|
|
237
|
+
if sortie="$(docker network connect kind "$(hostname)" 2>&1)"; then
|
|
238
|
+
return 0
|
|
239
|
+
fi
|
|
240
|
+
[[ "$sortie" == *"already exists"* ]]
|
|
241
|
+
}
|
|
242
|
+
|
|
226
243
|
gitlab_relais_port() {
|
|
227
|
-
local port="$1"
|
|
244
|
+
local port="$1" hote="$2" distant="$3" nom="gitlab-$1" dossier cible detache=()
|
|
228
245
|
dossier="$(relais_dossier "$nom")"
|
|
229
246
|
mkdir -p "$dossier"
|
|
230
|
-
|
|
247
|
+
cible="TCP:${hote}:${distant}"
|
|
248
|
+
# Cible inchangée et relais vivant : rien à faire. Cible changée (repli
|
|
249
|
+
# d'avant #327, nœud recréé…) : arrêter l'ancien relais et relancer.
|
|
250
|
+
if relais_actif "$nom" && [ "$(cat "$dossier/relais.cible" 2>/dev/null || true)" = "$cible" ]; then
|
|
251
|
+
return 0
|
|
252
|
+
fi
|
|
253
|
+
relais_arreter "$nom"
|
|
254
|
+
printf '%s\n' "$cible" >"$dossier/relais.cible"
|
|
231
255
|
# setsid : session à part, le relais survit à la fin du script qui l'a
|
|
232
256
|
# lancé ; absent sur macOS (tests bash 3.2), nohup suffit alors.
|
|
233
257
|
command -v setsid >/dev/null 2>&1 && detache=(setsid)
|
|
234
258
|
${detache[@]+"${detache[@]}"} nohup socat \
|
|
235
259
|
"TCP-LISTEN:${port},bind=127.0.0.1,fork,reuseaddr" \
|
|
236
|
-
"
|
|
260
|
+
"$cible" >"$dossier/relais.log" 2>&1 &
|
|
237
261
|
echo "$!" >"$dossier/relais.pid"
|
|
238
262
|
}
|
|
239
263
|
|
|
240
264
|
gitlab_relais_lancer() {
|
|
241
|
-
local
|
|
265
|
+
local noeud port distant ip
|
|
266
|
+
noeud="$(gitlab_noeud)"
|
|
267
|
+
if gitlab_reseau_rejoindre; then
|
|
268
|
+
for port in $GITLAB_PORTS; do
|
|
269
|
+
case "$port" in
|
|
270
|
+
8929) distant=80 ;;
|
|
271
|
+
2224) distant=32022 ;;
|
|
272
|
+
*) distant="$port" ;;
|
|
273
|
+
esac
|
|
274
|
+
gitlab_relais_port "$port" "$noeud" "$distant"
|
|
275
|
+
done
|
|
276
|
+
return 0
|
|
277
|
+
fi
|
|
242
278
|
if ! ip="$(gitlab_hote_ipv4)"; then
|
|
243
|
-
echo "devzone : gitlab : host.docker.internal introuvable (getent ahostsv4), relais non lancé" >&2
|
|
279
|
+
echo "devzone : gitlab : réseau kind non rejoignable et host.docker.internal introuvable (getent ahostsv4), relais non lancé" >&2
|
|
244
280
|
return 1
|
|
245
281
|
fi
|
|
282
|
+
echo "devzone : gitlab : réseau kind non rejoignable, repli sur l'IPv4 de host.docker.internal (${ip})" >&2
|
|
246
283
|
for port in $GITLAB_PORTS; do
|
|
247
|
-
gitlab_relais_port "$port" "$ip"
|
|
284
|
+
gitlab_relais_port "$port" "$ip" "$port"
|
|
248
285
|
done
|
|
249
286
|
}
|
|
250
287
|
|
|
@@ -460,6 +497,25 @@ gitlab_desinstaller() {
|
|
|
460
497
|
}
|
|
461
498
|
|
|
462
499
|
# ---- etat : vérifier l'état de GitLab ----
|
|
500
|
+
# Nœud encore publié sur toutes les interfaces (cluster créé avant #327) :
|
|
501
|
+
# seul docker port le dit ; la cible du relais, elle, ne dépend plus de la
|
|
502
|
+
# publication des ports de l'hôte.
|
|
503
|
+
gitlab_ports_exposes() {
|
|
504
|
+
local noeud sortie ligne
|
|
505
|
+
noeud="$(gitlab_noeud)"
|
|
506
|
+
sortie="$(docker port "$noeud" 2>/dev/null || true)"
|
|
507
|
+
while IFS= read -r ligne; do
|
|
508
|
+
case "$ligne" in
|
|
509
|
+
80/tcp* | 32022/tcp*)
|
|
510
|
+
case "$ligne" in
|
|
511
|
+
*"0.0.0.0"* | *"::"*) return 0 ;;
|
|
512
|
+
esac
|
|
513
|
+
;;
|
|
514
|
+
esac
|
|
515
|
+
done <<<"$sortie"
|
|
516
|
+
return 1
|
|
517
|
+
}
|
|
518
|
+
|
|
463
519
|
gitlab_etat() {
|
|
464
520
|
# Désactivé s'il n'y a pas de cluster gitlab
|
|
465
521
|
if ! kind get clusters 2>/dev/null | grep -qx "gitlab${INSTANCE_SUFFIX}"; then
|
|
@@ -480,10 +536,13 @@ gitlab_etat() {
|
|
|
480
536
|
fi
|
|
481
537
|
fi
|
|
482
538
|
echo "prêt : http://gitlab.localhost:8929, runner ${runner_status}"
|
|
483
|
-
|
|
539
|
+
else
|
|
540
|
+
echo "en échec : devzone appliquer"
|
|
484
541
|
fi
|
|
485
542
|
|
|
486
|
-
|
|
543
|
+
if gitlab_ports_exposes; then
|
|
544
|
+
echo "⚠ GitLab exposé au réseau local : devzone desactiver gitlab puis devzone activer gitlab (données de test perdues)"
|
|
545
|
+
fi
|
|
487
546
|
return 0
|
|
488
547
|
}
|
|
489
548
|
|
|
@@ -16,8 +16,10 @@ nodes:
|
|
|
16
16
|
extraPortMappings:
|
|
17
17
|
- containerPort: 80
|
|
18
18
|
hostPort: 8929
|
|
19
|
+
listenAddress: "127.0.0.1"
|
|
19
20
|
protocol: TCP
|
|
20
21
|
# Clone SSH : nodePort kind fixe 32022 → hostPort 2224 (port annoncé par GitLab)
|
|
21
22
|
- containerPort: 32022
|
|
22
23
|
hostPort: 2224
|
|
24
|
+
listenAddress: "127.0.0.1"
|
|
23
25
|
protocol: TCP
|
|
@@ -9,6 +9,9 @@
|
|
|
9
9
|
# une installation échoue (kube-config.sh l'appelle avec || true).
|
|
10
10
|
set -euo pipefail
|
|
11
11
|
|
|
12
|
+
# shellcheck source=SCRIPTDIR/cluster.sh
|
|
13
|
+
. "$(dirname "$0")/cluster.sh"
|
|
14
|
+
|
|
12
15
|
VERSION=v0.9.0
|
|
13
16
|
MANIFESTE="https://github.com/kubernetes-sigs/metrics-server/releases/download/${VERSION}/components.yaml"
|
|
14
17
|
|
|
@@ -23,7 +26,7 @@ if [ "${1:-}" = retirer ]; then
|
|
|
23
26
|
# Clusters locaux seulement : un retrait sur un cluster distant n'a rien
|
|
24
27
|
# à retirer (devzone n'y installe jamais)
|
|
25
28
|
mapfile -t contextes < <(printf '%s\n' ${connus[@]+"${connus[@]}"} |
|
|
26
|
-
|
|
29
|
+
while IFS= read -r c; do cluster_est_local "$c" && echo "$c"; done || true)
|
|
27
30
|
set -- ${contextes[@]+"${contextes[@]}"}
|
|
28
31
|
fi
|
|
29
32
|
code=0
|
|
@@ -52,7 +55,7 @@ if [ "$demandes" -eq 0 ]; then
|
|
|
52
55
|
# Clusters locaux seulement : jamais d'install automatique sur un cluster
|
|
53
56
|
# distant de l'hôte (prod, staging…) ; pour un autre, le nommer en argument
|
|
54
57
|
mapfile -t contextes < <(printf '%s\n' ${connus[@]+"${connus[@]}"} |
|
|
55
|
-
|
|
58
|
+
while IFS= read -r c; do cluster_est_local "$c" && echo "$c"; done || true)
|
|
56
59
|
set -- ${contextes[@]+"${contextes[@]}"}
|
|
57
60
|
fi
|
|
58
61
|
|
package/package.json
CHANGED