devzone 0.18.4 → 0.18.6
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"
|
|
@@ -140,6 +211,20 @@ cluster_choisir() {
|
|
|
140
211
|
fi
|
|
141
212
|
}
|
|
142
213
|
|
|
214
|
+
# Cree un cluster kind sans basculer le contexte courant de kubectl.
|
|
215
|
+
# Le code de kind est rendu meme sous set -e : la restauration a lieu avant.
|
|
216
|
+
kind_creer_sans_basculer() {
|
|
217
|
+
local precedent code=0
|
|
218
|
+
precedent="$(kubectl config current-context 2>/dev/null || true)"
|
|
219
|
+
kind create cluster "$@" || code=$?
|
|
220
|
+
if [ -n "$precedent" ]; then
|
|
221
|
+
kubectl config use-context "$precedent" >/dev/null 2>&1 || true
|
|
222
|
+
else
|
|
223
|
+
KUBECONFIG="$HOME/.kube/config" kubectl config unset current-context >/dev/null 2>&1 || true
|
|
224
|
+
fi
|
|
225
|
+
return "$code"
|
|
226
|
+
}
|
|
227
|
+
|
|
143
228
|
cluster_preparer() {
|
|
144
229
|
local ctx="$1"
|
|
145
230
|
if [ "$ctx" = "$CLUSTER_DEDIE" ]; then
|
|
@@ -151,10 +236,10 @@ cluster_preparer() {
|
|
|
151
236
|
# Docker de l'hôte chargé (son Kubernetes, d'autres clusters) : l'API du
|
|
152
237
|
# nœud peut redémarrer pendant l'initialisation et kind abandonne à
|
|
153
238
|
# quelques secondes près. Une seconde tentative, sur un cluster neuf.
|
|
154
|
-
if !
|
|
239
|
+
if ! kind_creer_sans_basculer --name "devzone${INSTANCE_SUFFIX}" --wait 120s; then
|
|
155
240
|
echo "▶ Nouvelle tentative de création du cluster kind…"
|
|
156
241
|
kind delete cluster --name "devzone${INSTANCE_SUFFIX}" >/dev/null 2>&1 || true
|
|
157
|
-
|
|
242
|
+
kind_creer_sans_basculer --name "devzone${INSTANCE_SUFFIX}" --wait 120s || return 1
|
|
158
243
|
fi
|
|
159
244
|
kube_joignable_depuis_conteneur "$HOME/.kube/config"
|
|
160
245
|
fi
|
package/.devcontainer/devzone
CHANGED
|
@@ -670,7 +670,7 @@ worktrees_absents() {
|
|
|
670
670
|
# État complet : ✔ prêt, ✖ nécessaire, ○ facultatif, ⚠ à corriger ; chaque
|
|
671
671
|
# point à faire avec sa commande (affiché à chaque démarrage)
|
|
672
672
|
etat() {
|
|
673
|
-
local nom email statut m retards chemin ports_etat relais_marque
|
|
673
|
+
local nom email statut m retards chemin ports_etat relais_marque ctx_travail ctx_hote
|
|
674
674
|
echo "devzone : état (devzone pour le réafficher)"
|
|
675
675
|
nom="$(git config --get user.name || true)"
|
|
676
676
|
email="$(git config --get user.email || true)"
|
|
@@ -725,6 +725,21 @@ 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
|
|
733
|
+
# Cluster de travail interne (kind) : avertissement dans le recapitulatif
|
|
734
|
+
ctx_travail="$(kubectl config current-context 2>/dev/null || true)"
|
|
735
|
+
case "$ctx_travail" in
|
|
736
|
+
kind-gitlab* | kind-devzone*)
|
|
737
|
+
ctx_hote="$(KUBECONFIG="${DEVZONE_KUBE_HOTE:-$HOME/.kube/hote.config}" kubectl config current-context 2>/dev/null || true)"
|
|
738
|
+
if [ -n "$ctx_hote" ] && cluster_joignable "$ctx_hote"; then
|
|
739
|
+
printf ' ⚠ cluster de travail : %s (cluster interne de devzone) ; revenir : kubectl config use-context %s\n' "$ctx_travail" "$ctx_hote"
|
|
740
|
+
fi
|
|
741
|
+
;;
|
|
742
|
+
esac
|
|
728
743
|
ports_etat="$(bash "$ICI/ports.sh" resume 2>/dev/null || true)"
|
|
729
744
|
case "$ports_etat" in
|
|
730
745
|
aucun*) printf ' ○ ports vers le poste %s\n' "$ports_etat" ;;
|
|
@@ -390,7 +390,7 @@ gitlab_installer() {
|
|
|
390
390
|
local cree=false
|
|
391
391
|
if ! kind get clusters 2>/dev/null | grep -qx "gitlab${INSTANCE_SUFFIX}"; then
|
|
392
392
|
echo "▶ Création du cluster kind gitlab…"
|
|
393
|
-
|
|
393
|
+
kind_creer_sans_basculer --name "gitlab${INSTANCE_SUFFIX}" --config "$ICI/kind.yaml" --wait 120s
|
|
394
394
|
kube_joignable_depuis_conteneur "$HOME/.kube/config"
|
|
395
395
|
cree=true
|
|
396
396
|
fi
|
|
@@ -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