devzone 0.46.0 → 0.47.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.
@@ -1,15 +1,26 @@
1
1
  #!/usr/bin/env bash
2
- # Memory check of the services cluster (#608): a module refuses its
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
5
  # quantite_ki <quantite> Kubernetes quantity in Ki
6
- # memoire_cluster_ki sum of the allocatable memory, in Ki
6
+ # memoire_cluster_ki allocatable memory of the cluster, in Ki
7
7
  # verifier_memoire_module <module> <minimum_go> [astuce]
8
8
  # Messages in French. 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 memoire_cluster_ki (#612) and read by
12
+ # verifier_memoire_module, which calls the function directly: a call written
13
+ # memoire="$(memoire_cluster_ki)" would run it in a subshell and lose them.
14
+ # Callers that only need the number keep using $(memoire_cluster_ki): the
15
+ # value is still printed on stdout (argocd, gitlab, llm are unaffected).
16
+ # MEMOIRE_KI same value as on stdout, in Ki
17
+ # MEMOIRE_REGLE "maximum" when every node is a kind node (the nodes share
18
+ # one VM), "somme" otherwise
19
+ MEMOIRE_KI=""
20
+ MEMOIRE_REGLE=""
21
+
11
22
  # Converts a Kubernetes memory quantity (Ki, Mi, Gi, Ti, K, M, G, bytes)
12
- # into Ki, to add the allocatable memory of the nodes.
23
+ # into Ki, to total the allocatable memory of the nodes.
13
24
  quantite_ki() {
14
25
  local q="${1:-}" nombre
15
26
  case "$q" in
@@ -29,33 +40,73 @@ quantite_ki() {
29
40
  esac
30
41
  }
31
42
 
32
- # Sum of the allocatable memory of the services cluster nodes, in Ki.
33
- # Reading the nodes is reserved to the administrator (#430).
43
+ # Allocatable memory of the services cluster nodes, in Ki. Reading the nodes
44
+ # is reserved to the administrator (#430). One kubectl call gives, per node,
45
+ # its providerID and its allocatable memory on one "<providerID>|<memory>"
46
+ # line (#612). A kind cluster runs on a single Docker daemon: its nodes share
47
+ # the memory of one VM and each of them declares the whole VM, so adding them
48
+ # up lies. When every providerID starts with "kind://" the greatest node
49
+ # memory is returned (MEMOIRE_REGLE=maximum); as soon as one node has no such
50
+ # prefix or an empty providerID the sum is returned (MEMOIRE_REGLE=somme), as
51
+ # before. Known limit, documented: k3d and minikube in Docker mode share a VM
52
+ # too but are not kind, they stay on the sum. A line without the separator
53
+ # carries the memory alone, so it is a node without providerID (sum).
34
54
  memoire_cluster_ki() {
35
- local sortie valeur total=0
55
+ local sortie ligne providerID memoire noeud total=0 max=0 n=0 tous_kind=1
56
+ MEMOIRE_KI=""
57
+ MEMOIRE_REGLE=""
36
58
  sortie="$(compte_admin "$(compte_ctx)" get nodes \
37
- -o jsonpath='{range .items[*]}{.status.allocatable.memory}{"\n"}{end}' 2>/dev/null)" || return 1
59
+ -o jsonpath='{range .items[*]}{.spec.providerID}{"|"}{.status.allocatable.memory}{"\n"}{end}' 2>/dev/null)" || return 1
38
60
  [ -n "$sortie" ] || return 1
39
- while IFS= read -r valeur; do
40
- [ -n "$valeur" ] || continue
41
- total=$((total + $(quantite_ki "$valeur")))
61
+ while IFS= read -r ligne; do
62
+ [ -n "$ligne" ] || continue
63
+ case "$ligne" in
64
+ *'|'*)
65
+ providerID="${ligne%%|*}"
66
+ memoire="${ligne#*|}"
67
+ ;;
68
+ *)
69
+ providerID=""
70
+ memoire="$ligne"
71
+ ;;
72
+ esac
73
+ noeud="$(quantite_ki "$memoire")"
74
+ total=$((total + noeud))
75
+ if [ "$noeud" -gt "$max" ]; then max="$noeud"; fi
76
+ case "$providerID" in
77
+ kind://*) ;;
78
+ *) tous_kind=0 ;;
79
+ esac
80
+ n=$((n + 1))
42
81
  done <<<"$sortie"
43
- echo "$total"
82
+ if [ "$n" -gt 0 ] && [ "$tous_kind" -eq 1 ]; then
83
+ MEMOIRE_REGLE="maximum"
84
+ MEMOIRE_KI="$max"
85
+ else
86
+ MEMOIRE_REGLE="somme"
87
+ MEMOIRE_KI="$total"
88
+ fi
89
+ echo "$MEMOIRE_KI"
44
90
  }
45
91
 
46
92
  # Refuses the installation of <module> under <minimum_go> GiB of allocatable
47
93
  # memory. The message says the minimum, the available memory and how to enlarge
48
94
  # the cluster; [astuce] adds an optional hint (for example --preset light).
49
- # Return 0 when the memory is enough, 2 when it is not or the cluster is
50
- # unreachable.
95
+ # On a kind cluster (#612) the available memory is the one of a single node
96
+ # and the message says so. Return 0 when the memory is enough, 2 when it is
97
+ # not or the cluster is unreachable.
51
98
  verifier_memoire_module() {
52
- local nom_module="$1" minimum_go="$2" astuce="${3:-}" memoire
53
- if ! memoire="$(memoire_cluster_ki)"; then
99
+ local nom_module="$1" minimum_go="$2" astuce="${3:-}" memoire precision=""
100
+ if ! memoire_cluster_ki >/dev/null; then
54
101
  echo "devzone : ${nom_module} : cluster des services injoignable : devzone cluster" >&2
55
102
  return 2
56
103
  fi
104
+ memoire="$MEMOIRE_KI"
105
+ if [ "$MEMOIRE_REGLE" = "maximum" ]; then
106
+ precision=" (mémoire d'un seul nœud : cluster kind, VM partagée)"
107
+ fi
57
108
  if [ "$memoire" -lt "$((minimum_go * 1048576))" ]; then
58
- echo "devzone : ${nom_module} : il faut au moins ${minimum_go} Go de mémoire allouable dans le cluster (disponible : $((memoire / 1048576)) Go) ; agrandir le cluster (Docker Desktop → Settings → Resources) puis relancer : devzone enable ${nom_module}${astuce:+ ; astuce : ${astuce}}" >&2
109
+ echo "devzone : ${nom_module} : il faut au moins ${minimum_go} Go de mémoire allouable dans le cluster (disponible : $((memoire / 1048576)) Go)${precision} ; agrandir le cluster (Docker Desktop → Settings → Resources) puis relancer : devzone enable ${nom_module}${astuce:+ ; astuce : ${astuce}}" >&2
59
110
  return 2
60
111
  fi
61
112
  return 0
package/README.md CHANGED
@@ -60,6 +60,8 @@ Mesures du 16/11/2026. Le chiffre LLM vient des valeurs du chart (non mesuré en
60
60
  | LLM modèle 7B (7 milliards de paramètres, fichier Q4_K_M) | 6 Gi | 12 Go |
61
61
  | LLM --preset light (modèle 3B) | 3 Gi demandés, 4 Gi en limite | 8 Go |
62
62
 
63
+ Sur Docker Desktop (kind), le contrôle compare le minimum à la mémoire d'un seul nœud, donc à la VM ; sur un cluster de vraies machines, à la somme des nœuds.
64
+
63
65
  - **Réglage de la RAM** :
64
66
  - **Mac** (Docker Desktop) : *Settings → Resources > Memory*. Autre méthode : modifier `MemoryMiB` dans le fichier `settings-store.json` de Docker Desktop (Docker totalement quitté sinon il réécrit la valeur).
65
67
  - **Windows** : fichier `%UserProfile%\.wslconfig` avec `[wsl2]` et `memory=<N>GB`, puis `wsl --shutdown`. WSL2 prend 50 % de la RAM par défaut.
@@ -359,7 +361,7 @@ L'utilisateur d'un projet possède **sa** base (il y crée tables, index, donné
359
361
 
360
362
  ## Voir mon application dans le navigateur
361
363
 
362
- Sur le poste Kubernetes, `devzone workspace start` lance un veilleur de ports : chaque port TCP ≥ 1024 qui écoute dans le pod est relayé sur `127.0.0.1` du poste, au même numéro, par `kubectl port-forward`. Un serveur lancé dans le pod (`npm run dev`, port 5173) répond donc sur `http://localhost:5173`, sans commande. Les services activés (PostgreSQL, MySQL, Argo CD) sont relayés aussi, sur leur port habituel. Le veilleur se pilote avec `devzone workspace ports start|stop|status` ; détails dans la [référence](manage/docs/reference.md#applications-et-services-sur-localhost-du-poste).
364
+ Sur le poste Kubernetes, `devzone workspace start` lance un veilleur de ports : chaque port TCP ≥ 1024 qui écoute dans le pod est relayé sur `127.0.0.1` du poste, au même numéro, par `kubectl port-forward`. Un serveur lancé dans le pod (`npm run dev`, port 5173) répond donc sur `http://localhost:5173`, sans commande. Les services activés (PostgreSQL, MySQL, Argo CD) sont relayés aussi, sur leur port habituel. Les Services des applications déployées dans le cluster sont relayés de la même façon, chacun sur un port local (80 → 8080 ; un port déjà pris ailleurs devient un autre port) : `devzone workspace ports status` affiche leur URL `http://127.0.0.1:<port>`. Un Service peut être exclu avec l'annotation `devzone.io/relay: "false"`. Le veilleur se pilote avec `devzone workspace ports start|stop|status` ; détails dans la [référence](manage/docs/reference.md#applications-et-services-sur-localhost-du-poste).
363
365
 
364
366
  Sur le poste Docker, une application lancée **dans** le conteneur (par exemple un Spring Boot avec `./gradlew bootRun` sur le port 8080) n'est pas joignable depuis le poste : le conteneur devzone ne publie aucun port. Dès qu'elle écoute dans le conteneur, le **veilleur de ports automatiques** (`.devcontainer/ports-auto.sh`) pose un relais `alpine/socat` (version figée) sur le Docker de l'hôte, de `127.0.0.1:<port>` du poste vers le port du conteneur : `http://localhost:<port>` **sans commande**. Le relais disparaît quand l'application s'arrête.
365
367
 
@@ -0,0 +1,109 @@
1
+ #!/usr/bin/env bash
2
+ # Applications of the Kubernetes workspace relayed on workstation localhost (#611).
3
+ # Sourced by ports-workspace.sh, never run alone. One kubectl get svc -A per
4
+ # round: each TCP port of each Service gets a local port, kept stable in
5
+ # .devzone.ports-workspace/apps/<namespace>.<service>.<port> while the Service
6
+ # exists. Output lines: "portlocal|namespace|svc/name|remoteport", as pw_services.
7
+
8
+ PA_MAX=30
9
+ # Namespaces never relayed: system ones, and those of the devzone modules
10
+ # (relayed by pw_services, or without any interface).
11
+ PA_NS_SKIP=" kube-system kube-public kube-node-lease local-path-storage devzone-system devzone-workspace devzone-postgres devzone-mysql devzone-argocd devzone-gitlab devzone-llm "
12
+
13
+ # Services of the cluster, one "namespace|name|clusterIP|type|relay annotation|port/proto," line each.
14
+ pa_discover() {
15
+ pw_kubectl get svc -A -o 'jsonpath={range .items[*]}{.metadata.namespace}|{.metadata.name}|{.spec.clusterIP}|{.spec.type}|{.metadata.annotations.devzone\.io/relay}|{range .spec.ports[*]}{.port}/{.protocol},{end}{"\n"}{end}' 2>/dev/null
16
+ }
17
+
18
+ # Is the Service excluded? $1 namespace, $2 name, $3 clusterIP, $4 type, $5 relay annotation.
19
+ pa_excluded() {
20
+ case "$PA_NS_SKIP" in *" $1 "*) return 0 ;; esac
21
+ [ "$1/$2" != default/kubernetes ] || return 0
22
+ [ "$5" != false ] || return 0
23
+ case "$4" in ExternalName) return 0 ;; esac
24
+ case "$3" in '' | None) return 0 ;; esac
25
+ return 1
26
+ }
27
+
28
+ # Is local port $1 free for an application? Not in the list "$2" (" p p "), not taken on the workstation.
29
+ pa_free() {
30
+ case "$2" in *" $1 "*) return 1 ;; esac
31
+ ! pw_taken "$1"
32
+ }
33
+
34
+ # First free local port for Service port $1, given the ports in use "$2": the port itself
35
+ # when >= 1024, else $1 + 8000 (80 -> 8080), then incrementing; past 65000, from 20000.
36
+ pa_new() {
37
+ local c=$(($1 + 8000)) i=0
38
+ if [ "$1" -ge 1024 ] && pa_free "$1" "$2"; then
39
+ echo "$1"
40
+ return 0
41
+ fi
42
+ [ "$c" -le 65000 ] || c=20000
43
+ while [ "$i" -lt 60000 ]; do
44
+ if pa_free "$c" "$2"; then
45
+ echo "$c"
46
+ return 0
47
+ fi
48
+ c=$((c + 1))
49
+ i=$((i + 1))
50
+ [ "$c" -le 65000 ] || c=20000
51
+ done
52
+ return 1
53
+ }
54
+
55
+ # One round of applications, from the ports already wanted "$1" (services, pod).
56
+ # Prints the relay lines; writes apps/ (stable local port) and plafond/ (cap marker),
57
+ # removes the state of Services gone, warns once per port over the cap of PA_MAX.
58
+ pa_round() {
59
+ local d used excl ns name ip type annot ports pp port key stored loc n=0 seen="" f
60
+ d="$(pw_dir)"
61
+ mkdir -p "$d/apps" "$d/plafond"
62
+ excl="$(grep -E '^ports_exclus=' .devzone.modules 2>/dev/null | tail -1 | cut -d= -f2- | tr ',' ' ')"
63
+ used=" $1 $excl "
64
+ while IFS='|' read -r ns name ip type annot ports; do
65
+ [ -n "$ns" ] || continue
66
+ pa_excluded "$ns" "$name" "$ip" "$type" "$annot" && continue
67
+ for pp in ${ports//,/ }; do
68
+ case "$pp" in */TCP) ;; *) continue ;; esac
69
+ port="${pp%/*}"
70
+ case "$port" in '' | *[!0-9]*) continue ;; esac
71
+ key="$ns.$name.$port"
72
+ seen="$seen $key "
73
+ stored="$(cat "$d/apps/$key" 2>/dev/null || true)"
74
+ loc=""
75
+ case "$stored" in '' | *[!0-9]*) ;; *) case "$used" in *" $stored "*) ;; *) loc="$stored" ;; esac ;; esac
76
+ if [ -z "$loc" ]; then
77
+ loc="$(pa_new "$port" "$used")" || { echo "⚠ no free local port for $ns/$name:$port" >&2; continue; }
78
+ fi
79
+ used="$used $loc "
80
+ [ "$loc" = "$stored" ] || printf '%s' "$loc" >"$d/apps/$key"
81
+ if [ "$n" -lt "$PA_MAX" ]; then
82
+ n=$((n + 1))
83
+ rm -f "$d/plafond/$key"
84
+ echo "$loc|$ns|svc/$name|$port"
85
+ elif [ ! -e "$d/plafond/$key" ]; then
86
+ : >"$d/plafond/$key"
87
+ echo "⚠ cap of $PA_MAX application relays reached, $ns/$name:$port not relayed" >&2
88
+ fi
89
+ done
90
+ done <<<"$(pa_discover)"
91
+ for f in "$d"/apps/* "$d"/plafond/*; do
92
+ [ -e "$f" ] || continue
93
+ case "$seen" in *" $(basename "$f") "*) ;; *) rm -f "$f" ;; esac
94
+ done
95
+ }
96
+
97
+ # Status lines of relayed applications: local URL, then namespace/service:port.
98
+ pa_status() {
99
+ local d f key rest loc
100
+ d="$(pw_dir)"
101
+ for f in "$d"/apps/*; do
102
+ [ -e "$f" ] || continue
103
+ loc="$(cat "$f")"
104
+ pw_alive "$(cat "$d/relais/$loc" 2>/dev/null)" || continue
105
+ key="$(basename "$f")"
106
+ rest="${key#*.}"
107
+ echo " http://127.0.0.1:$loc ${key%%.*}/${rest%%.*}:${rest#*.}"
108
+ done
109
+ }
@@ -13,6 +13,9 @@ PW_NS="devzone-workspace"
13
13
  PW_INTERNAL=" 2475 1234 "
14
14
  # pgAdmin service port: read from the service, without it nothing is relayed.
15
15
  PW_JSONPATH='jsonpath={.spec.ports[0].port}'
16
+ # Cluster Services relayed as applications (#611).
17
+ # shellcheck source=manage/scripts/ports-apps.sh
18
+ . "$(dirname "${BASH_SOURCE[0]}")/ports-apps.sh"
16
19
 
17
20
  # Watcher state folder: lock, pid, relays, reported ports, log.
18
21
  pw_dir() { printf '%s' "${DEVZONE_PORTS_WORKSPACE_DIR:-$PWD/.devzone.ports-workspace}"; }
@@ -125,6 +128,11 @@ pw_round() {
125
128
  wanted="$wanted $p "
126
129
  pw_relay "$p" "$PW_NS" "pod/$PW_POD"
127
130
  done
131
+ while IFS='|' read -r p ns target remote; do
132
+ [ -n "$p" ] || continue
133
+ wanted="$wanted $p "
134
+ pw_relay "$p" "$ns" "$target" "$remote"
135
+ done <<<"$(pa_round "$wanted")"
128
136
  for f in "$d"/relais/* "$d"/pris/*; do
129
137
  [ -e "$f" ] || continue
130
138
  l="$(basename "$f")"
@@ -197,6 +205,7 @@ ports_status() {
197
205
  for f in "$d"/pris/*; do
198
206
  if [ -e "$f" ]; then echo " ⚠ port $(basename "$f") already in use on the workstation, not relayed"; fi
199
207
  done
208
+ pa_status
200
209
  return 0
201
210
  }
202
211
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "devzone",
3
- "version": "0.46.0",
3
+ "version": "0.47.0",
4
4
  "description": "Ton poste de développement Linux, prêt en une commande, identique sur Mac, Windows et Linux.",
5
5
  "license": "GPL-3.0-only",
6
6
  "repository": {