devzone 1.0.0 → 1.1.0
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/agent-erreurs.sh +72 -56
- package/.devcontainer/agent-etat-json.sh +45 -43
- package/.devcontainer/agent-modele.sh +3 -3
- package/.devcontainer/agent-session.sh +122 -125
- package/.devcontainer/agent-workspace.sh +53 -53
- package/.devcontainer/agent.sh +107 -109
- package/.devcontainer/argocd/argocd.sh +4 -4
- package/.devcontainer/catalogue/app.sh +1 -1
- package/.devcontainer/catalogue/catalogue-veilleur.sh +2 -2
- package/.devcontainer/catalogue/mysql/mysql.sh +1 -1
- package/.devcontainer/catalogue.sh +3 -3
- package/.devcontainer/cluster.sh +1 -1
- package/.devcontainer/devzone +14 -13
- package/.devcontainer/etat-json.sh +162 -162
- package/.devcontainer/etat-verrou.sh +25 -24
- package/.devcontainer/etat.sh +122 -123
- package/.devcontainer/gitlab/gitlab.sh +1 -1
- package/.devcontainer/gitlab/installation.sh +3 -3
- package/.devcontainer/gitlab/secrets.sh +1 -1
- package/.devcontainer/help.sh +1 -0
- package/.devcontainer/memoire.sh +58 -58
- package/.devcontainer/metrics-server.sh +52 -51
- package/.devcontainer/password.sh +88 -87
- package/.devcontainer/ports-auto.sh +6 -6
- package/.devcontainer/ports.sh +1 -1
- package/.devcontainer/postgres/postgres.sh +1 -1
- package/.devcontainer/services-admin.sh +3 -3
- package/README.md +2 -2
- package/charts/devzone-workspace/templates/statefulset.yaml +3 -0
- package/package.json +1 -1
package/.devcontainer/etat.sh
CHANGED
|
@@ -1,169 +1,168 @@
|
|
|
1
1
|
#!/usr/bin/env bash
|
|
2
|
-
#
|
|
3
|
-
#
|
|
4
|
-
#
|
|
5
|
-
#
|
|
6
|
-
#
|
|
7
|
-
#
|
|
8
|
-
#
|
|
9
|
-
#
|
|
10
|
-
#
|
|
11
|
-
#
|
|
12
|
-
#
|
|
13
|
-
#
|
|
14
|
-
#
|
|
15
|
-
#
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
# Verrou d'écriture (#476) : etat_verrou_prendre, etat_verrou_lacher
|
|
2
|
+
# Safe write of the module state (#417): the only place that sets, replaces
|
|
3
|
+
# or removes a line of $ETAT. A mkdir lock prevents two simultaneous writes,
|
|
4
|
+
# the temporary file is created in the state folder (the mv stays atomic: the
|
|
5
|
+
# file is never missing or incomplete for a reader) and a backup copy
|
|
6
|
+
# $ETAT.prec precedes each replacement. The same file creates the state when
|
|
7
|
+
# it is missing: former global state taken over once, backup copy restored,
|
|
8
|
+
# state rebuilt from the services cluster, otherwise first installation.
|
|
9
|
+
# Sourced library: the caller defines ETAT (file name kept: shared by callers).
|
|
10
|
+
# state_write <key> <value> sets or replaces the line <key>=<value>
|
|
11
|
+
# state_remove <key> removes the line <key>=
|
|
12
|
+
# state_replace <file> replaces the whole state with this file
|
|
13
|
+
# state_lock_take / state_lock_release write lock
|
|
14
|
+
# state_recovery_* state restored or rebuilt (step 4)
|
|
15
|
+
# state_init [modules…] creates the state if it is missing
|
|
16
|
+
|
|
17
|
+
# Write lock (#476): state_lock_take, state_lock_release
|
|
19
18
|
# shellcheck source=SCRIPTDIR/etat-verrou.sh
|
|
20
19
|
# shellcheck disable=SC1091
|
|
21
20
|
. "$(dirname "${BASH_SOURCE[0]}")/etat-verrou.sh"
|
|
22
21
|
|
|
23
|
-
#
|
|
24
|
-
|
|
22
|
+
# Abort under lock: the temporary file goes, the lock is released
|
|
23
|
+
state_abort() {
|
|
25
24
|
rm -f "${1:-}"
|
|
26
|
-
|
|
25
|
+
state_lock_release
|
|
27
26
|
return 1
|
|
28
27
|
}
|
|
29
28
|
|
|
30
|
-
#
|
|
31
|
-
|
|
29
|
+
# Backup copy of the current state, before replacement
|
|
30
|
+
state_backup() {
|
|
32
31
|
[ -f "$ETAT" ] || return 0
|
|
33
32
|
cp "$ETAT" "${ETAT}.prec"
|
|
34
33
|
}
|
|
35
34
|
|
|
36
|
-
#
|
|
37
|
-
|
|
38
|
-
local
|
|
35
|
+
# The state without the line $1, written to the temporary file $2
|
|
36
|
+
state_filter() {
|
|
37
|
+
local key="$1" dst="$2" code=0
|
|
39
38
|
[ -f "$ETAT" ] || return 0
|
|
40
|
-
grep -vE "^${
|
|
39
|
+
grep -vE "^${key}=" "$ETAT" >"$dst" || code=$?
|
|
41
40
|
[ "$code" -le 1 ] || return 1
|
|
42
41
|
return 0
|
|
43
42
|
}
|
|
44
43
|
|
|
45
|
-
#
|
|
46
|
-
|
|
44
|
+
# Under lock: replaces the whole state with a file, $ETAT.prec backed up
|
|
45
|
+
state_replace() {
|
|
47
46
|
local src="$1" tmp
|
|
48
47
|
[ -f "$src" ] || return 1
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
tmp="$(mktemp "${ETAT}.XXXXXX")" || {
|
|
52
|
-
cat "$src" >"$tmp" || {
|
|
53
|
-
mv "$tmp" "$ETAT" || {
|
|
54
|
-
|
|
48
|
+
state_lock_take || return 1
|
|
49
|
+
state_backup || { state_lock_release; return 1; }
|
|
50
|
+
tmp="$(mktemp "${ETAT}.XXXXXX")" || { state_lock_release; return 1; }
|
|
51
|
+
cat "$src" >"$tmp" || { state_abort "$tmp"; return 1; }
|
|
52
|
+
mv "$tmp" "$ETAT" || { state_abort "$tmp"; return 1; }
|
|
53
|
+
state_lock_release
|
|
55
54
|
return 0
|
|
56
55
|
}
|
|
57
56
|
|
|
58
|
-
#
|
|
59
|
-
|
|
60
|
-
local
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
tmp="$(mktemp "${ETAT}.XXXXXX")" || {
|
|
64
|
-
|
|
65
|
-
printf '%s=%s\n' "$
|
|
66
|
-
mv "$tmp" "$ETAT" || {
|
|
67
|
-
|
|
57
|
+
# Under lock: new value of a key, without losing the other lines
|
|
58
|
+
state_write() {
|
|
59
|
+
local key="$1" value="$2" tmp
|
|
60
|
+
state_lock_take || return 1
|
|
61
|
+
state_backup || { state_lock_release; return 1; }
|
|
62
|
+
tmp="$(mktemp "${ETAT}.XXXXXX")" || { state_lock_release; return 1; }
|
|
63
|
+
state_filter "$key" "$tmp" || { state_abort "$tmp"; return 1; }
|
|
64
|
+
printf '%s=%s\n' "$key" "$value" >>"$tmp" || { state_abort "$tmp"; return 1; }
|
|
65
|
+
mv "$tmp" "$ETAT" || { state_abort "$tmp"; return 1; }
|
|
66
|
+
state_lock_release
|
|
68
67
|
return 0
|
|
69
68
|
}
|
|
70
69
|
|
|
71
|
-
#
|
|
72
|
-
|
|
73
|
-
local
|
|
74
|
-
|
|
75
|
-
[ -f "$ETAT" ] || {
|
|
76
|
-
|
|
77
|
-
tmp="$(mktemp "${ETAT}.XXXXXX")" || {
|
|
78
|
-
|
|
79
|
-
mv "$tmp" "$ETAT" || {
|
|
80
|
-
|
|
70
|
+
# Under lock: removes a key (#417); without state, nothing to remove
|
|
71
|
+
state_remove() {
|
|
72
|
+
local key="$1" tmp
|
|
73
|
+
state_lock_take || return 1
|
|
74
|
+
[ -f "$ETAT" ] || { state_lock_release; return 0; }
|
|
75
|
+
state_backup || { state_lock_release; return 1; }
|
|
76
|
+
tmp="$(mktemp "${ETAT}.XXXXXX")" || { state_lock_release; return 1; }
|
|
77
|
+
state_filter "$key" "$tmp" || { state_abort "$tmp"; return 1; }
|
|
78
|
+
mv "$tmp" "$ETAT" || { state_abort "$tmp"; return 1; }
|
|
79
|
+
state_lock_release
|
|
81
80
|
return 0
|
|
82
81
|
}
|
|
83
82
|
|
|
84
|
-
#
|
|
85
|
-
|
|
83
|
+
# Marks a restored or rebuilt state: the watchers wait (#417)
|
|
84
|
+
state_recovery_mark() {
|
|
86
85
|
date +%s >"${ETAT}.recouvre" 2>/dev/null || true
|
|
87
86
|
}
|
|
88
87
|
|
|
89
|
-
# 0 (
|
|
90
|
-
|
|
91
|
-
local
|
|
88
|
+
# 0 (to wait) less than 60 s after a restore or a rebuild
|
|
89
|
+
state_recovery_wait() {
|
|
90
|
+
local mark
|
|
92
91
|
[ -f "${ETAT}.recouvre" ] || return 1
|
|
93
|
-
|
|
94
|
-
case "$
|
|
92
|
+
mark="$(cat "${ETAT}.recouvre" 2>/dev/null || true)"
|
|
93
|
+
case "$mark" in
|
|
95
94
|
'' | *[!0-9]*) return 1 ;;
|
|
96
95
|
esac
|
|
97
|
-
[ "$(( $(date +%s) -
|
|
96
|
+
[ "$(( $(date +%s) - mark ))" -lt 60 ]
|
|
98
97
|
}
|
|
99
98
|
|
|
100
|
-
# 0
|
|
101
|
-
|
|
99
|
+
# 0 if the restored or rebuilt state is not yet confirmed (#417)
|
|
100
|
+
state_recovery_pending() {
|
|
102
101
|
[ -f "${ETAT}.recouvre" ]
|
|
103
102
|
}
|
|
104
103
|
|
|
105
|
-
#
|
|
106
|
-
|
|
104
|
+
# The user confirmed the state (devzone apply): no more guard
|
|
105
|
+
state_recovery_confirm() {
|
|
107
106
|
rm -f "${ETAT}.recouvre" 2>/dev/null || true
|
|
108
107
|
return 0
|
|
109
108
|
}
|
|
110
109
|
|
|
111
|
-
#
|
|
112
|
-
|
|
110
|
+
# First installation (#417): the default state, written in one go
|
|
111
|
+
state_default() {
|
|
113
112
|
local stage code=0
|
|
114
113
|
stage="$(mktemp)" || return 1
|
|
115
114
|
printf 'ia=off\nkubernetes=off\ngitlab=off\n' >"$stage"
|
|
116
|
-
|
|
115
|
+
state_replace "$stage" || code=$?
|
|
117
116
|
rm -f "$stage"
|
|
118
117
|
return "$code"
|
|
119
118
|
}
|
|
120
119
|
|
|
121
|
-
#
|
|
122
|
-
#
|
|
123
|
-
|
|
124
|
-
local cluster="$1"
|
|
125
|
-
|
|
120
|
+
# Host context (host KUBECONFIG) that points to the given cluster: the
|
|
121
|
+
# cluster= line of the state expects this context, not "devzone" (services cluster)
|
|
122
|
+
host_context_of_cluster() {
|
|
123
|
+
local cluster="$1" host ctx
|
|
124
|
+
host="${DEVZONE_KUBE_HOTE:-$HOME/.kube/hote.config}"
|
|
126
125
|
while IFS= read -r ctx; do
|
|
127
126
|
[ -n "$ctx" ] || continue
|
|
128
|
-
#
|
|
129
|
-
#
|
|
127
|
+
# The "devzone" context is set on the services cluster: we look for the
|
|
128
|
+
# host context that points to it
|
|
130
129
|
[ "$ctx" = devzone ] && continue
|
|
131
|
-
if [ "$(KUBECONFIG="$
|
|
130
|
+
if [ "$(KUBECONFIG="$host" kubectl config view -o jsonpath="{.contexts[?(@.name==\"$ctx\")].context.cluster}" 2>/dev/null || true)" = "$cluster" ]; then
|
|
132
131
|
echo "$ctx"
|
|
133
132
|
return 0
|
|
134
133
|
fi
|
|
135
|
-
done < <(KUBECONFIG="$
|
|
134
|
+
done < <(KUBECONFIG="$host" kubectl config get-contexts -o name 2>/dev/null)
|
|
136
135
|
return 1
|
|
137
136
|
}
|
|
138
137
|
|
|
139
|
-
#
|
|
140
|
-
#
|
|
141
|
-
#
|
|
142
|
-
|
|
143
|
-
local
|
|
144
|
-
|
|
138
|
+
# State missing without backup copy (#417, step 3): rebuilt from the namespaces
|
|
139
|
+
# labelled devzone of the services cluster (module on if its namespace exists,
|
|
140
|
+
# cluster= of the devzone context); returns 1 otherwise.
|
|
141
|
+
state_rebuild() {
|
|
142
|
+
local namespaces m v stage seen=0 code=0 cluster_ctx cluster_host label
|
|
143
|
+
label="${CLUSTER_ETIQUETTE:-app.kubernetes.io/managed-by=devzone}"
|
|
145
144
|
command -v kubectl >/dev/null 2>&1 || return 1
|
|
146
|
-
|
|
147
|
-
[ -n "$
|
|
145
|
+
namespaces="$(kubectl get namespaces -l "$label" -o name 2>/dev/null || true)"
|
|
146
|
+
[ -n "$namespaces" ] || return 1
|
|
148
147
|
stage="$(mktemp)" || return 1
|
|
149
148
|
for m in "$@"; do
|
|
150
149
|
v=off
|
|
151
|
-
printf '%s\n' "$
|
|
150
|
+
printf '%s\n' "$namespaces" | grep -qx "namespace/devzone-$m" && { v=on; seen=1; }
|
|
152
151
|
printf '%s=%s\n' "$m" "$v" >>"$stage" || code=1
|
|
153
152
|
done
|
|
154
|
-
#
|
|
155
|
-
#
|
|
156
|
-
cluster_ctx="$(kubectl config view -o jsonpath="{.contexts[?(@.name
|
|
157
|
-
|
|
153
|
+
# devzone context -> services cluster; the cluster= expects the real host
|
|
154
|
+
# context that points to it (e.g. docker-desktop). Without host: no line.
|
|
155
|
+
cluster_ctx="$(kubectl config view -o jsonpath="{.contexts[?(@.name==\"devzone\")].context.cluster}" 2>/dev/null || true)"
|
|
156
|
+
cluster_host=""
|
|
158
157
|
if [ -n "$cluster_ctx" ]; then
|
|
159
|
-
|
|
160
|
-
if [ -n "$
|
|
161
|
-
printf 'cluster=%s\n' "$
|
|
158
|
+
cluster_host="$(host_context_of_cluster "$cluster_ctx")"
|
|
159
|
+
if [ -n "$cluster_host" ]; then
|
|
160
|
+
printf 'cluster=%s\n' "$cluster_host" >>"$stage" || code=1
|
|
162
161
|
fi
|
|
163
162
|
fi
|
|
164
|
-
if [ "$code" -eq 0 ] && [ "$
|
|
165
|
-
echo "devzone :
|
|
166
|
-
[ -n "$
|
|
163
|
+
if [ "$code" -eq 0 ] && [ "$seen" -eq 1 ] && state_replace "$stage"; then
|
|
164
|
+
echo "devzone : state rebuilt from the namespaces of the services cluster: $ETAT (confirm with devzone apply)" >&2
|
|
165
|
+
[ -n "$cluster_host" ] || echo "devzone : no host context points to the services cluster: no cluster= line in $ETAT" >&2
|
|
167
166
|
rm -f "$stage"
|
|
168
167
|
return 0
|
|
169
168
|
fi
|
|
@@ -171,50 +170,50 @@ etat_reconstruire() {
|
|
|
171
170
|
return 1
|
|
172
171
|
}
|
|
173
172
|
|
|
174
|
-
#
|
|
175
|
-
#
|
|
176
|
-
|
|
173
|
+
# First start (no state): former global state taken over once, otherwise backup
|
|
174
|
+
# copy restored, otherwise state rebuilt, otherwise everything disabled
|
|
175
|
+
state_init() {
|
|
177
176
|
[ -f "$ETAT" ] && return 0
|
|
178
177
|
|
|
179
|
-
# Migration
|
|
180
|
-
#
|
|
181
|
-
#
|
|
178
|
+
# Migration: former global state (~/.config/devzone/modules) to the state of
|
|
179
|
+
# the instance; moved, not copied: the first devzone started after the update
|
|
180
|
+
# keeps its choices
|
|
182
181
|
if [ -f "$HOME/.config/devzone/modules" ]; then
|
|
183
|
-
if
|
|
182
|
+
if state_replace "$HOME/.config/devzone/modules"; then
|
|
184
183
|
rm -f "$HOME/.config/devzone/modules"
|
|
185
184
|
return 0
|
|
186
185
|
fi
|
|
187
186
|
fi
|
|
188
187
|
|
|
189
|
-
|
|
188
|
+
state_lock_take || return 1
|
|
190
189
|
if [ -f "$ETAT" ]; then
|
|
191
|
-
|
|
190
|
+
state_lock_release
|
|
192
191
|
return 0
|
|
193
192
|
fi
|
|
194
|
-
# 1.
|
|
195
|
-
if [ -f "${ETAT}.prec" ] &&
|
|
196
|
-
echo "devzone :
|
|
197
|
-
|
|
198
|
-
|
|
193
|
+
# 1. Backup copy left by the last write (#417)
|
|
194
|
+
if [ -f "${ETAT}.prec" ] && state_replace "${ETAT}.prec"; then
|
|
195
|
+
echo "devzone : state restored from the backup copy: $ETAT (confirm with devzone apply)" >&2
|
|
196
|
+
state_recovery_mark
|
|
197
|
+
state_lock_release
|
|
199
198
|
return 0
|
|
200
199
|
fi
|
|
201
|
-
# 2.
|
|
202
|
-
if
|
|
203
|
-
|
|
204
|
-
|
|
200
|
+
# 2. Rebuild from the services cluster (#417)
|
|
201
|
+
if state_rebuild "$@"; then
|
|
202
|
+
state_recovery_mark
|
|
203
|
+
state_lock_release
|
|
205
204
|
return 0
|
|
206
205
|
fi
|
|
207
|
-
# 3.
|
|
208
|
-
if !
|
|
209
|
-
|
|
206
|
+
# 3. First installation: everything disabled (#417)
|
|
207
|
+
if ! state_default; then
|
|
208
|
+
state_lock_release
|
|
210
209
|
return 1
|
|
211
210
|
fi
|
|
212
|
-
|
|
213
|
-
#
|
|
214
|
-
#
|
|
215
|
-
#
|
|
211
|
+
state_lock_release
|
|
212
|
+
# Connection already set up by another devzone (shared volumes): reported
|
|
213
|
+
# once, when the state of this instance is created; stderr: init is also
|
|
214
|
+
# called inside $(value …)
|
|
216
215
|
if [ -f "$HOME/.claude/.credentials.json" ] || [ -f "$HOME/.local/share/opencode/auth.json" ]; then
|
|
217
|
-
echo "devzone :
|
|
216
|
+
echo "devzone : shared Claude Code/opencode connection found: devzone enable ia to use it here" >&2
|
|
218
217
|
fi
|
|
219
218
|
return 0
|
|
220
219
|
}
|
|
@@ -28,7 +28,7 @@ GITLAB_SECRETS_DIR="$RACINE/workspace/.gitlab"
|
|
|
28
28
|
|
|
29
29
|
# Vue regroupée des identifiants : un échec n'empêche jamais l'opération
|
|
30
30
|
regenerer_identifiants() {
|
|
31
|
-
|
|
31
|
+
password_regenerate ||
|
|
32
32
|
echo "devzone : gitlab : identifiants regroupés non mis à jour (devzone passwords)" >&2
|
|
33
33
|
}
|
|
34
34
|
|
|
@@ -6,8 +6,8 @@
|
|
|
6
6
|
# Le chart enveloppe charts/devzone-gitlab (#538) porte les dépendances et les
|
|
7
7
|
# valeurs ; chart.sh (helm direct) et argocd.sh (Application) l'installent.
|
|
8
8
|
|
|
9
|
-
# Shared memory check of the services cluster (#608):
|
|
10
|
-
#
|
|
9
|
+
# Shared memory check of the services cluster (#608): quantity_ki,
|
|
10
|
+
# memory_cluster_ki and check_module_memory.
|
|
11
11
|
# shellcheck source=SCRIPTDIR/../memoire.sh
|
|
12
12
|
# shellcheck disable=SC1091
|
|
13
13
|
. "$ICI/../memoire.sh"
|
|
@@ -36,7 +36,7 @@ gitlab_namespace_preparer() {
|
|
|
36
36
|
# l'accès (relais web/SSH, /etc/hosts) et le seed des données de test.
|
|
37
37
|
gitlab_installer() {
|
|
38
38
|
echo "▶ Vérification de la mémoire allouable du cluster des services…"
|
|
39
|
-
|
|
39
|
+
check_module_memory gitlab 8 || return 2
|
|
40
40
|
|
|
41
41
|
mkdir -p "$GITLAB_SECRETS_DIR"
|
|
42
42
|
gitlab_namespace_preparer
|
|
@@ -89,7 +89,7 @@ puts \"OK\""
|
|
|
89
89
|
mkdir -p "$GITLAB_SECRETS_DIR" || return 1
|
|
90
90
|
(umask 077 && printf '%s' "$mdp" >"$fichier") || return 1
|
|
91
91
|
chmod 600 "$fichier"
|
|
92
|
-
|
|
92
|
+
password_regenerate ||
|
|
93
93
|
echo "devzone : gitlab : identifiants regroupés non mis à jour (devzone passwords)" >&2
|
|
94
94
|
printf '%s\n' "$RACINE/.password"
|
|
95
95
|
}
|
package/.devcontainer/help.sh
CHANGED
|
@@ -6,6 +6,7 @@ devzone_aide() {
|
|
|
6
6
|
cat <<'AIDE'
|
|
7
7
|
Optional modules of devzone, enabled on demand, without rebuild:
|
|
8
8
|
devzone state of the modules
|
|
9
|
+
devzone --version version of the workspace image (DEVZONE_VERSION)
|
|
9
10
|
devzone platform GitHub (default) or GitLab
|
|
10
11
|
devzone platform github back to GitHub: glab and config removed
|
|
11
12
|
devzone platform gitlab GitLab, [--url URL] (default: gitlab module)
|
package/.devcontainer/memoire.sh
CHANGED
|
@@ -2,35 +2,35 @@
|
|
|
2
2
|
# Memory check of the services cluster (#608, #612): a module refuses its
|
|
3
3
|
# installation when the allocatable memory of the nodes is below its minimum.
|
|
4
4
|
# Sourced by the modules (gitlab, llm) and by the tests; bash 3.2 (macOS).
|
|
5
|
-
#
|
|
6
|
-
#
|
|
7
|
-
#
|
|
8
|
-
# Messages in
|
|
5
|
+
# quantity_ki <quantity> Kubernetes quantity in Ki
|
|
6
|
+
# memory_cluster_ki allocatable memory of the cluster, in Ki
|
|
7
|
+
# check_module_memory <module> <minimum_gi> [hint]
|
|
8
|
+
# Messages in English. Return 0 when the memory is enough, 2 when it is not or
|
|
9
9
|
# when the cluster is unreachable.
|
|
10
10
|
|
|
11
|
-
# Globals written by
|
|
12
|
-
#
|
|
13
|
-
#
|
|
14
|
-
# Callers that only need the number keep using $(
|
|
11
|
+
# Globals written by memory_cluster_ki (#612) and read by
|
|
12
|
+
# check_module_memory, which calls the function directly: a call written
|
|
13
|
+
# memory="$(memory_cluster_ki)" would run it in a subshell and lose them.
|
|
14
|
+
# Callers that only need the number keep using $(memory_cluster_ki): the
|
|
15
15
|
# value is still printed on stdout (argocd, gitlab, llm are unaffected).
|
|
16
|
-
#
|
|
17
|
-
#
|
|
18
|
-
#
|
|
19
|
-
|
|
20
|
-
|
|
16
|
+
# MEMORY_KI same value as on stdout, in Ki
|
|
17
|
+
# MEMORY_RULE "maximum" when every node is a kind node (the nodes share
|
|
18
|
+
# one VM), "sum" otherwise
|
|
19
|
+
MEMORY_KI=""
|
|
20
|
+
MEMORY_RULE=""
|
|
21
21
|
|
|
22
22
|
# Converts a Kubernetes memory quantity (Ki, Mi, Gi, Ti, K, M, G, bytes)
|
|
23
23
|
# into Ki, to total the allocatable memory of the nodes.
|
|
24
|
-
|
|
25
|
-
local q="${1:-}"
|
|
24
|
+
quantity_ki() {
|
|
25
|
+
local q="${1:-}" number
|
|
26
26
|
case "$q" in
|
|
27
|
-
*Ki)
|
|
28
|
-
*Mi)
|
|
29
|
-
*Gi)
|
|
30
|
-
*Ti)
|
|
31
|
-
*K | *k)
|
|
32
|
-
*M)
|
|
33
|
-
*G)
|
|
27
|
+
*Ki) number="${q%Ki}"; echo $((number)) ;;
|
|
28
|
+
*Mi) number="${q%Mi}"; echo $((number * 1024)) ;;
|
|
29
|
+
*Gi) number="${q%Gi}"; echo $((number * 1024 * 1024)) ;;
|
|
30
|
+
*Ti) number="${q%Ti}"; echo $((number * 1024 * 1024 * 1024)) ;;
|
|
31
|
+
*K | *k) number="${q%[Kk]}"; echo $((number * 1000 / 1024)) ;;
|
|
32
|
+
*M) number="${q%M}"; echo $((number * 1000 * 1000 / 1024)) ;;
|
|
33
|
+
*G) number="${q%G}"; echo $((number * 1000 * 1000 * 1000 / 1024)) ;;
|
|
34
34
|
*)
|
|
35
35
|
case "$q" in
|
|
36
36
|
'' | *[!0-9]*) echo 0 ;;
|
|
@@ -46,67 +46,67 @@ quantite_ki() {
|
|
|
46
46
|
# line (#612). A kind cluster runs on a single Docker daemon: its nodes share
|
|
47
47
|
# the memory of one VM and each of them declares the whole VM, so adding them
|
|
48
48
|
# up lies. When every providerID starts with "kind://" the greatest node
|
|
49
|
-
# memory is returned (
|
|
50
|
-
# prefix or an empty providerID the sum is returned (
|
|
49
|
+
# memory is returned (MEMORY_RULE=maximum); as soon as one node has no such
|
|
50
|
+
# prefix or an empty providerID the sum is returned (MEMORY_RULE=sum), as
|
|
51
51
|
# before. Known limit, documented: k3d and minikube in Docker mode share a VM
|
|
52
52
|
# too but are not kind, they stay on the sum. A line without the separator
|
|
53
53
|
# carries the memory alone, so it is a node without providerID (sum).
|
|
54
|
-
|
|
55
|
-
local
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
54
|
+
memory_cluster_ki() {
|
|
55
|
+
local output line providerID memory node total=0 max=0 n=0 all_kind=1
|
|
56
|
+
MEMORY_KI=""
|
|
57
|
+
MEMORY_RULE=""
|
|
58
|
+
output="$(compte_admin "$(compte_ctx)" get nodes \
|
|
59
59
|
-o jsonpath='{range .items[*]}{.spec.providerID}{"|"}{.status.allocatable.memory}{"\n"}{end}' 2>/dev/null)" || return 1
|
|
60
|
-
[ -n "$
|
|
61
|
-
while IFS= read -r
|
|
62
|
-
[ -n "$
|
|
63
|
-
case "$
|
|
60
|
+
[ -n "$output" ] || return 1
|
|
61
|
+
while IFS= read -r line; do
|
|
62
|
+
[ -n "$line" ] || continue
|
|
63
|
+
case "$line" in
|
|
64
64
|
*'|'*)
|
|
65
|
-
providerID="${
|
|
66
|
-
|
|
65
|
+
providerID="${line%%|*}"
|
|
66
|
+
memory="${line#*|}"
|
|
67
67
|
;;
|
|
68
68
|
*)
|
|
69
69
|
providerID=""
|
|
70
|
-
|
|
70
|
+
memory="$line"
|
|
71
71
|
;;
|
|
72
72
|
esac
|
|
73
|
-
|
|
74
|
-
total=$((total +
|
|
75
|
-
if [ "$
|
|
73
|
+
node="$(quantity_ki "$memory")"
|
|
74
|
+
total=$((total + node))
|
|
75
|
+
if [ "$node" -gt "$max" ]; then max="$node"; fi
|
|
76
76
|
case "$providerID" in
|
|
77
77
|
kind://*) ;;
|
|
78
|
-
*)
|
|
78
|
+
*) all_kind=0 ;;
|
|
79
79
|
esac
|
|
80
80
|
n=$((n + 1))
|
|
81
|
-
done <<<"$
|
|
82
|
-
if [ "$n" -gt 0 ] && [ "$
|
|
83
|
-
|
|
84
|
-
|
|
81
|
+
done <<<"$output"
|
|
82
|
+
if [ "$n" -gt 0 ] && [ "$all_kind" -eq 1 ]; then
|
|
83
|
+
MEMORY_RULE="maximum"
|
|
84
|
+
MEMORY_KI="$max"
|
|
85
85
|
else
|
|
86
|
-
|
|
87
|
-
|
|
86
|
+
MEMORY_RULE="sum"
|
|
87
|
+
MEMORY_KI="$total"
|
|
88
88
|
fi
|
|
89
|
-
echo "$
|
|
89
|
+
echo "$MEMORY_KI"
|
|
90
90
|
}
|
|
91
91
|
|
|
92
|
-
# Refuses the installation of <module> under <
|
|
92
|
+
# Refuses the installation of <module> under <minimum_gi> GiB of allocatable
|
|
93
93
|
# memory. The message says the minimum, the available memory and how to enlarge
|
|
94
|
-
# the cluster; [
|
|
94
|
+
# the cluster; [hint] adds an optional hint (for example --preset light).
|
|
95
95
|
# On a kind cluster (#612) the available memory is the one of a single node
|
|
96
96
|
# and the message says so. Return 0 when the memory is enough, 2 when it is
|
|
97
97
|
# not or the cluster is unreachable.
|
|
98
|
-
|
|
99
|
-
local
|
|
100
|
-
if !
|
|
101
|
-
echo "devzone : ${
|
|
98
|
+
check_module_memory() {
|
|
99
|
+
local module_name="$1" minimum_gi="$2" hint="${3:-}" memory precision=""
|
|
100
|
+
if ! memory_cluster_ki >/dev/null; then
|
|
101
|
+
echo "devzone : ${module_name} : services cluster unreachable: devzone cluster" >&2
|
|
102
102
|
return 2
|
|
103
103
|
fi
|
|
104
|
-
|
|
105
|
-
if [ "$
|
|
106
|
-
precision=" (
|
|
104
|
+
memory="$MEMORY_KI"
|
|
105
|
+
if [ "$MEMORY_RULE" = "maximum" ]; then
|
|
106
|
+
precision=" (memory of a single node: kind cluster, shared VM)"
|
|
107
107
|
fi
|
|
108
|
-
if [ "$
|
|
109
|
-
echo "devzone : ${
|
|
108
|
+
if [ "$memory" -lt "$((minimum_gi * 1048576))" ]; then
|
|
109
|
+
echo "devzone : ${module_name} : at least ${minimum_gi} GiB of allocatable memory is needed in the cluster (available: $((memory / 1048576)) GiB)${precision} ; enlarge the cluster (Docker Desktop → Settings → Resources) then retry: devzone enable ${module_name}${hint:+ ; hint: ${hint}}" >&2
|
|
110
110
|
return 2
|
|
111
111
|
fi
|
|
112
112
|
return 0
|