devzone 0.30.0 → 0.30.1
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/catalogue/app.sh +8 -1
- package/.devcontainer/catalogue/mysql/installer.sh +57 -0
- package/.devcontainer/catalogue/mysql/manifeste.yaml +2 -2
- package/.devcontainer/catalogue/mysql/mysql.sh +11 -25
- package/.devcontainer/catalogue/mysql/volume.sh +71 -0
- package/.devcontainer/catalogue.sh +16 -0
- package/package.json +1 -1
|
@@ -54,10 +54,17 @@ app_installer() {
|
|
|
54
54
|
kubectl --context devzone label namespace "$ns" "$CLUSTER_ETIQUETTE" --overwrite >/dev/null
|
|
55
55
|
namespace_isoler "$ns" >/dev/null
|
|
56
56
|
app_secret "$app" "$ns"
|
|
57
|
+
local claim=donnees
|
|
58
|
+
if [ "$app" = mysql ]; then
|
|
59
|
+
# shellcheck source=SCRIPTDIR/mysql/volume.sh
|
|
60
|
+
# shellcheck disable=SC1091
|
|
61
|
+
. "$(dossier_catalogue)/mysql/volume.sh"
|
|
62
|
+
claim="$(mysql_claim_choisir "$ns")" || return 2
|
|
63
|
+
fi
|
|
57
64
|
man="$(mktemp)"
|
|
58
65
|
sed -e "s|__APP__|$app|g" -e "s|__NS__|$ns|g" -e "s|__IMAGE__|$image|g" \
|
|
59
66
|
-e "s|__PORT__|$port|g" -e "s|__MEMOIRE__|$(app_lire "$app" memoire)|g" \
|
|
60
|
-
-e "s|__TAILLE__|$(app_lire "$app" taille)|g" \
|
|
67
|
+
-e "s|__TAILLE__|$(app_lire "$app" taille)|g" -e "s|__CLAIM__|$claim|g" \
|
|
61
68
|
"$(dossier_catalogue)/$app/manifeste.yaml" >"$man" &&
|
|
62
69
|
kubectl --context devzone -n "$ns" apply -f "$man" >/dev/null
|
|
63
70
|
rm -f "$man"
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
#!/usr/bin/env bash
|
|
2
|
+
# Installation MySQL (#440) : secret, manifeste et réinstallation sur un volume.
|
|
3
|
+
|
|
4
|
+
# Secret admin (mysql-admin) : root.env ou secret existant, jamais régénéré.
|
|
5
|
+
mysql_secret() {
|
|
6
|
+
local mdp fichier="$SECRETS/admin-password"
|
|
7
|
+
mkdir -p "$SECRETS"
|
|
8
|
+
chmod 700 "$SECRETS"
|
|
9
|
+
if k get secret mysql-admin >/dev/null 2>&1; then
|
|
10
|
+
mdp="$(k get secret mysql-admin -o jsonpath='{.data.password}' | base64 -d | tr -d '\n')"
|
|
11
|
+
(umask 077 && printf '%s' "$mdp" >"$fichier")
|
|
12
|
+
return 0
|
|
13
|
+
fi
|
|
14
|
+
mdp="$(sed -n 's/^MYSQL_PASSWORD=//p' "$SECRETS/root.env" 2>/dev/null | tail -1 || true)"
|
|
15
|
+
if [ -z "$mdp" ] && [ -s "$fichier" ]; then mdp="$(cat "$fichier")"; fi
|
|
16
|
+
if [ -z "$mdp" ]; then
|
|
17
|
+
(umask 077 && openssl rand -hex 24 | tr -d '\n' >"$fichier")
|
|
18
|
+
k create secret generic mysql-admin --from-file=password="$fichier" >/dev/null
|
|
19
|
+
elif [ ! -s "$fichier" ]; then
|
|
20
|
+
(umask 077 && printf '%s' "$mdp" >"$fichier")
|
|
21
|
+
fi
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
# Applique le manifeste avec le préfixe de claim choisi (#440)
|
|
25
|
+
mysql_appliquer_manifeste() {
|
|
26
|
+
local ns="$1" claim="$2"
|
|
27
|
+
sed -e "s|__APP__|mysql|g" -e "s|__NS__|$ns|g" -e "s|__IMAGE__|$MYSQL_IMAGE|g" \
|
|
28
|
+
-e "s|__PORT__|$MYSQL_PORT|g" -e "s|__MEMOIRE__|$MYSQL_MEMOIRE|g" \
|
|
29
|
+
-e "s|__TAILLE__|$MYSQL_TAILLE|g" -e "s|__CLAIM__|$claim|g" \
|
|
30
|
+
"$ICI/manifeste.yaml" | kubectl --context devzone -n "$ns" apply -f - >/dev/null
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
# (Ré)installe MySQL sur le claim demandé, données du PVC gardées (#440)
|
|
34
|
+
mysql_installer_claim() {
|
|
35
|
+
local ns="$1" claim="$2" CTX
|
|
36
|
+
CTX="$(contexte)"
|
|
37
|
+
if ! contexte_devzone_poser "$CTX"; then
|
|
38
|
+
echo "devzone : catalogue mysql : impossible de poser le contexte devzone sur $CTX" >&2
|
|
39
|
+
return 1
|
|
40
|
+
fi
|
|
41
|
+
echo "▶ MySQL sur le cluster $CTX (namespace $ns, volume ${claim}-mysql-0)…"
|
|
42
|
+
kubectl --context devzone create namespace "$ns" --dry-run=client -o yaml |
|
|
43
|
+
kubectl --context devzone apply -f - >/dev/null
|
|
44
|
+
kubectl --context devzone label namespace "$ns" "$CLUSTER_ETIQUETTE" --overwrite >/dev/null
|
|
45
|
+
namespace_isoler "$ns" >/dev/null
|
|
46
|
+
mysql_secret
|
|
47
|
+
k delete statefulset mysql --ignore-not-found >/dev/null 2>&1 || true
|
|
48
|
+
mysql_appliquer_manifeste "$ns" "$claim"
|
|
49
|
+
if ! k rollout status statefulset/mysql --timeout="${MYSQL_ATTENTE}s" >/dev/null; then
|
|
50
|
+
echo "devzone : catalogue mysql : pas prêt après ${MYSQL_ATTENTE}s : kubectl --context $CTX -n $ns describe pod mysql-0" >&2
|
|
51
|
+
return 1
|
|
52
|
+
fi
|
|
53
|
+
mysql_secret
|
|
54
|
+
relais_lancer mysql "$CTX" "$ns" svc/mysql 3306:3306
|
|
55
|
+
echo "✔ MySQL prêt : 127.0.0.1:$MYSQL_PORT dans le conteneur"
|
|
56
|
+
regenerer_identifiants
|
|
57
|
+
}
|
|
@@ -63,11 +63,11 @@ spec:
|
|
|
63
63
|
cpu: 100m
|
|
64
64
|
memory: __MEMOIRE__
|
|
65
65
|
volumeMounts:
|
|
66
|
-
- name:
|
|
66
|
+
- name: __CLAIM__
|
|
67
67
|
mountPath: /var/lib/mysql
|
|
68
68
|
volumeClaimTemplates:
|
|
69
69
|
- metadata:
|
|
70
|
-
name:
|
|
70
|
+
name: __CLAIM__
|
|
71
71
|
labels:
|
|
72
72
|
app.kubernetes.io/managed-by: devzone
|
|
73
73
|
spec:
|
|
@@ -13,6 +13,12 @@ ETAT="${DEVZONE_ETAT:-$RACINE/.devzone.modules}"
|
|
|
13
13
|
# shellcheck source=SCRIPTDIR/../../isolement.sh
|
|
14
14
|
# shellcheck disable=SC1091
|
|
15
15
|
. "$ICI/../../isolement.sh"
|
|
16
|
+
# shellcheck source=SCRIPTDIR/volume.sh
|
|
17
|
+
# shellcheck disable=SC1091
|
|
18
|
+
. "$ICI/volume.sh"
|
|
19
|
+
# shellcheck source=SCRIPTDIR/installer.sh
|
|
20
|
+
# shellcheck disable=SC1091
|
|
21
|
+
. "$ICI/installer.sh"
|
|
16
22
|
NS=devzone-mysql
|
|
17
23
|
SECRETS="$RACINE/workspace/.mysql"
|
|
18
24
|
MYSQL_PORT="${MYSQL_PORT:-3306}"
|
|
@@ -67,27 +73,8 @@ nombre_bases() {
|
|
|
67
73
|
n="$(mysql_admin -N -B -e "SHOW DATABASES" 2>/dev/null | grep -vE '^(information_schema|mysql|performance_schema|sys)$' | grep -c . || true)"
|
|
68
74
|
echo "${n:-0}"
|
|
69
75
|
}
|
|
70
|
-
# Secret admin (mysql-admin) : root.env ou secret existant, jamais régénéré.
|
|
71
|
-
mysql_secret() {
|
|
72
|
-
local mdp fichier="$SECRETS/admin-password"
|
|
73
|
-
mkdir -p "$SECRETS"
|
|
74
|
-
chmod 700 "$SECRETS"
|
|
75
|
-
if k get secret mysql-admin >/dev/null 2>&1; then
|
|
76
|
-
mdp="$(k get secret mysql-admin -o jsonpath='{.data.password}' | base64 -d | tr -d '\n')"
|
|
77
|
-
(umask 077 && printf '%s' "$mdp" >"$fichier")
|
|
78
|
-
return 0
|
|
79
|
-
fi
|
|
80
|
-
mdp="$(sed -n 's/^MYSQL_PASSWORD=//p' "$SECRETS/root.env" 2>/dev/null | tail -1 || true)"
|
|
81
|
-
if [ -z "$mdp" ] && [ -s "$fichier" ]; then mdp="$(cat "$fichier")"; fi
|
|
82
|
-
if [ -z "$mdp" ]; then
|
|
83
|
-
(umask 077 && openssl rand -hex 24 | tr -d '\n' >"$fichier")
|
|
84
|
-
k create secret generic mysql-admin --from-file=password="$fichier" >/dev/null
|
|
85
|
-
elif [ ! -s "$fichier" ]; then
|
|
86
|
-
(umask 077 && printf '%s' "$mdp" >"$fichier")
|
|
87
|
-
fi
|
|
88
|
-
}
|
|
89
76
|
installer() {
|
|
90
|
-
local CTX
|
|
77
|
+
local CTX claim
|
|
91
78
|
CTX="$(contexte)"
|
|
92
79
|
if ! contexte_devzone_poser "$CTX"; then
|
|
93
80
|
echo "devzone : catalogue mysql : impossible de poser le contexte devzone sur $CTX" >&2
|
|
@@ -102,10 +89,8 @@ installer() {
|
|
|
102
89
|
echo "devzone : catalogue mysql : installation existante dans $NS, adoptée (volume et root.env gardés)"
|
|
103
90
|
else
|
|
104
91
|
mysql_secret
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
-e "s|__TAILLE__|$MYSQL_TAILLE|g" \
|
|
108
|
-
"$ICI/manifeste.yaml" | kubectl --context devzone -n "$NS" apply -f - >/dev/null
|
|
92
|
+
claim="$(mysql_claim_choisir "$NS")" || return 2
|
|
93
|
+
mysql_appliquer_manifeste "$NS" "$claim"
|
|
109
94
|
if ! k rollout status statefulset/mysql --timeout="${MYSQL_ATTENTE}s" >/dev/null; then
|
|
110
95
|
echo "devzone : catalogue mysql : pas prêt après ${MYSQL_ATTENTE}s : kubectl --context $CTX -n $NS describe pod mysql-0" >&2
|
|
111
96
|
return 1
|
|
@@ -241,10 +226,11 @@ case "${1:-}" in
|
|
|
241
226
|
creer) creer "${@:2}" ;;
|
|
242
227
|
liste) liste ;;
|
|
243
228
|
supprimer) supprimer "${@:2}" ;;
|
|
229
|
+
volume) mysql_volume "$NS" "${@:2}" ;;
|
|
244
230
|
relais-lancer) relais ;;
|
|
245
231
|
relais-arreter) relais_arreter mysql ;;
|
|
246
232
|
*)
|
|
247
|
-
echo "devzone : catalogue mysql : creer <projet> [--nouveau-mdp] | liste | supprimer <projet> [--oui]" >&2
|
|
233
|
+
echo "devzone : catalogue mysql : creer <projet> [--nouveau-mdp] | liste | supprimer <projet> [--oui] | volume [<nom>] [--supprimer <nom>] [--oui]" >&2
|
|
248
234
|
exit 1
|
|
249
235
|
;;
|
|
250
236
|
esac
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
#!/usr/bin/env bash
|
|
2
|
+
# Volumes MySQL (#440) : choix, liste et suppression des PVC -mysql-0.
|
|
3
|
+
|
|
4
|
+
# Liste les PVC du namespace mysql dont le nom finit par -mysql-0
|
|
5
|
+
mysql_volumes() {
|
|
6
|
+
local ns="$1"
|
|
7
|
+
kubectl --context devzone -n "$ns" get pvc -o jsonpath='{range .items[*]}{.metadata.name}{"\n"}{end}' 2>/dev/null |
|
|
8
|
+
grep -E '\-mysql-0$' || true
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
# Préfixe de claim : 1 PVC → son préfixe, 0 → donnees, >1 → refus (code 2)
|
|
12
|
+
mysql_claim_choisir() {
|
|
13
|
+
local ns="$1" liste nb
|
|
14
|
+
liste="$(mysql_volumes "$ns")"
|
|
15
|
+
if [ -z "$liste" ]; then echo donnees; return 0; fi
|
|
16
|
+
nb="$(printf '%s\n' "$liste" | grep -c .)"
|
|
17
|
+
if [ "$nb" -eq 1 ]; then echo "${liste%-mysql-0}"; return 0; fi
|
|
18
|
+
echo "devzone : catalogue mysql : plusieurs volumes trouvés :" >&2
|
|
19
|
+
printf '%s\n' "$liste" | sed 's/^/ /' >&2
|
|
20
|
+
echo "devzone : catalogue mysql : choisir avec devzone mysql volume <nom>" >&2
|
|
21
|
+
return 2
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
# Claim porté par le StatefulSet (vide si absent)
|
|
25
|
+
mysql_claim_monte() {
|
|
26
|
+
local ns="$1"
|
|
27
|
+
kubectl --context devzone -n "$ns" get statefulset mysql \
|
|
28
|
+
-o jsonpath='{.spec.volumeClaimTemplates[0].metadata.name}' 2>/dev/null || true
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
# Sous-commande volume : liste ou sélectionne/supprime un PVC
|
|
32
|
+
mysql_volume() {
|
|
33
|
+
local ns="$1" nom="" oui="" supprimer="" arg reponse pvc monte claim
|
|
34
|
+
shift
|
|
35
|
+
for arg in "$@"; do
|
|
36
|
+
case "$arg" in
|
|
37
|
+
--supprimer) supprimer=1 ;;
|
|
38
|
+
--oui) oui=1 ;;
|
|
39
|
+
*) nom="$arg" ;;
|
|
40
|
+
esac
|
|
41
|
+
done
|
|
42
|
+
if [ -n "$supprimer" ]; then
|
|
43
|
+
[ -n "$nom" ] || refuse "volume --supprimer : nom manquant"
|
|
44
|
+
pvc="$nom"
|
|
45
|
+
[[ "$pvc" == *-mysql-0 ]] || pvc="$pvc-mysql-0"
|
|
46
|
+
monte="$(mysql_claim_monte "$ns")"
|
|
47
|
+
[ "${pvc%-mysql-0}" != "$monte" ] || refuse "volume monté, suppression refusée : $nom"
|
|
48
|
+
if [ -z "$oui" ]; then
|
|
49
|
+
cluster_interactif || refuse "confirmation impossible sans terminal : devzone mysql volume --supprimer $nom --oui"
|
|
50
|
+
printf 'Supprimer le volume %s ? [o/N] ' "$pvc" >&2
|
|
51
|
+
read -r reponse || reponse=""
|
|
52
|
+
case "$reponse" in
|
|
53
|
+
o | O | oui) ;;
|
|
54
|
+
*) echo "Abandon : rien n'a été supprimé."; return 0 ;;
|
|
55
|
+
esac
|
|
56
|
+
fi
|
|
57
|
+
kubectl --context devzone -n "$ns" delete pvc "$pvc" >/dev/null
|
|
58
|
+
echo "✔ volume $pvc supprimé"
|
|
59
|
+
return 0
|
|
60
|
+
fi
|
|
61
|
+
if [ -z "$nom" ]; then
|
|
62
|
+
monte="$(mysql_claim_monte "$ns")"
|
|
63
|
+
mysql_volumes "$ns" | awk -v m="$monte-mysql-0" 'NF { mark = ($0 == m) ? " (monté)" : ""; printf " %s%s\n", $0, mark; n++ } END { if (!n) print " (aucun volume)" }'
|
|
64
|
+
return 0
|
|
65
|
+
fi
|
|
66
|
+
contexte >/dev/null
|
|
67
|
+
installe || refuse "module inactif : devzone activer mysql"
|
|
68
|
+
claim="$nom"
|
|
69
|
+
[[ "$claim" == *-mysql-0 ]] && claim="${claim%-mysql-0}"
|
|
70
|
+
mysql_installer_claim "$ns" "$claim"
|
|
71
|
+
}
|
|
@@ -140,6 +140,21 @@ app_relais_arrete() {
|
|
|
140
140
|
! relais_actif "$app"
|
|
141
141
|
}
|
|
142
142
|
|
|
143
|
+
# Avertit des PVC mysql non montés par le StatefulSet (#440)
|
|
144
|
+
catalogue_mysql_volumes_inutilises() {
|
|
145
|
+
local ns monte pvc liste
|
|
146
|
+
ns="$(app_ns mysql)"
|
|
147
|
+
kubectl --context devzone get namespace "$ns" >/dev/null 2>&1 || return 0
|
|
148
|
+
monte="$(kubectl --context devzone -n "$ns" get statefulset mysql -o jsonpath='{.spec.volumeClaimTemplates[0].metadata.name}' 2>/dev/null || true)"
|
|
149
|
+
[ -n "$monte" ] || return 0
|
|
150
|
+
liste="$(kubectl --context devzone -n "$ns" get pvc -o jsonpath='{range .items[*]}{.metadata.name}{"\n"}{end}' 2>/dev/null | grep -E '\-mysql-0$' || true)"
|
|
151
|
+
while IFS= read -r pvc; do
|
|
152
|
+
[ -n "$pvc" ] || continue
|
|
153
|
+
[ "$pvc" != "${monte}-mysql-0" ] || continue
|
|
154
|
+
printf ' ⚠ volume %s non utilisé : devzone mysql volume\n' "$pvc"
|
|
155
|
+
done <<<"$liste"
|
|
156
|
+
}
|
|
157
|
+
|
|
143
158
|
# Lignes Applications du récapitulatif de devzone : ○ disponible, ✔ installée
|
|
144
159
|
# (adresse du relais), ✖ en échec, ⚠ attendue
|
|
145
160
|
catalogue_resume() {
|
|
@@ -161,6 +176,7 @@ catalogue_resume() {
|
|
|
161
176
|
"$app" "$(head -1 "$(fichier_echec "$app")")" ;;
|
|
162
177
|
esac
|
|
163
178
|
done <<<"$(catalogue_apps)"
|
|
179
|
+
catalogue_mysql_volumes_inutilises 2>/dev/null || true
|
|
164
180
|
}
|
|
165
181
|
|
|
166
182
|
# Rubrique applications de devzone etat --json : mêmes champs que modules
|