devzone 1.1.0 → 3.0.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.
Files changed (118) hide show
  1. package/.devcontainer/Dockerfile +4 -4
  2. package/.devcontainer/{agent-erreurs.sh → agent-errors.sh} +6 -6
  3. package/.devcontainer/agent-local.sh +2 -2
  4. package/.devcontainer/{agent-modele.messages → agent-model.messages} +1 -1
  5. package/.devcontainer/{agent-modele.sh → agent-model.sh} +5 -5
  6. package/.devcontainer/agent-pod-manifest.sh +4 -4
  7. package/.devcontainer/{agent-droits.sh → agent-rights.sh} +2 -2
  8. package/.devcontainer/agent-session.sh +3 -3
  9. package/.devcontainer/{agent-etat-json.sh → agent-state-json.sh} +6 -6
  10. package/.devcontainer/agent-workspace.sh +1 -1
  11. package/.devcontainer/agent.sh +14 -14
  12. package/.devcontainer/{ia/docker-garde.sh → ai/docker-guard.sh} +1 -1
  13. package/.devcontainer/{ia → ai}/host-models.sh +2 -2
  14. package/.devcontainer/{ia/plugins/devzone-garde-v2.js → ai/plugins/devzone-guard-v2.js} +7 -7
  15. package/.devcontainer/{ia/plugins/devzone-garde.js → ai/plugins/devzone-guard.js} +6 -6
  16. package/.devcontainer/argocd/argocd.sh +94 -93
  17. package/.devcontainer/argocd/{catalogue-argocd.sh → catalog-argocd.sh} +3 -3
  18. package/.devcontainer/argocd/services-hook.sh +8 -8
  19. package/.devcontainer/argocd/services.sh +1 -1
  20. package/.devcontainer/catalog/app.sh +209 -0
  21. package/.devcontainer/catalog/catalog-watcher.sh +130 -0
  22. package/.devcontainer/{catalogue → catalog}/mysql/app.conf +1 -1
  23. package/.devcontainer/catalog/mysql/install.sh +87 -0
  24. package/.devcontainer/catalog/mysql/mysql.sh +262 -0
  25. package/.devcontainer/catalog/mysql/volume.sh +71 -0
  26. package/.devcontainer/catalog.sh +231 -0
  27. package/.devcontainer/chart-direct.sh +1 -1
  28. package/.devcontainer/cluster.sh +222 -224
  29. package/.devcontainer/clusters.sh +41 -41
  30. package/.devcontainer/devcontainer.json +1 -1
  31. package/.devcontainer/devzone +103 -1506
  32. package/.devcontainer/devzone-ai-guard.sh +76 -0
  33. package/.devcontainer/devzone-ai.sh +201 -0
  34. package/.devcontainer/devzone-cluster.sh +210 -0
  35. package/.devcontainer/devzone-modules.sh +126 -0
  36. package/.devcontainer/devzone-platform.sh +189 -0
  37. package/.devcontainer/devzone-repair.sh +94 -0
  38. package/.devcontainer/devzone-services.sh +241 -0
  39. package/.devcontainer/devzone-skill.sh +97 -0
  40. package/.devcontainer/devzone-status.sh +140 -0
  41. package/.devcontainer/devzone-version.sh +78 -0
  42. package/.devcontainer/git-identity.sh +28 -0
  43. package/.devcontainer/gitlab/argocd.sh +2 -2
  44. package/.devcontainer/gitlab/chart.sh +2 -2
  45. package/.devcontainer/gitlab/gitlab.sh +83 -84
  46. package/.devcontainer/gitlab/installation.sh +111 -111
  47. package/.devcontainer/gitlab/secrets.sh +47 -47
  48. package/.devcontainer/gitlab/seed.sh +77 -77
  49. package/.devcontainer/gitlab/test-gitlab.sh +242 -243
  50. package/.devcontainer/help.sh +1 -1
  51. package/.devcontainer/isolation.sh +65 -0
  52. package/.devcontainer/kind-wrapper.sh +45 -0
  53. package/.devcontainer/kube-account.sh +199 -0
  54. package/.devcontainer/kube-config.sh +45 -46
  55. package/.devcontainer/{invite-kube.sh → kube-prompt.sh} +6 -6
  56. package/.devcontainer/kube-reachable.sh +64 -0
  57. package/.devcontainer/{memoire.sh → memory.sh} +1 -1
  58. package/.devcontainer/metrics-server.sh +2 -2
  59. package/.devcontainer/opencode.jsonc +2 -2
  60. package/.devcontainer/packages.sh +228 -0
  61. package/.devcontainer/password.sh +1 -1
  62. package/.devcontainer/ports-auto.sh +152 -153
  63. package/.devcontainer/ports-json.sh +16 -15
  64. package/.devcontainer/ports.sh +127 -123
  65. package/.devcontainer/post-create.sh +52 -52
  66. package/.devcontainer/postgres/postgres.sh +176 -176
  67. package/.devcontainer/rename-legacy-files.sh +103 -0
  68. package/.devcontainer/services-admin.sh +5 -5
  69. package/.devcontainer/skills/devzone/SKILL.md +40 -41
  70. package/.devcontainer/startup.sh +65 -0
  71. package/.devcontainer/{etat-gitops.sh → state-gitops.sh} +1 -1
  72. package/.devcontainer/{etat-json.sh → state-json.sh} +39 -65
  73. package/.devcontainer/{etat-verrou.sh → state-lock.sh} +1 -1
  74. package/.devcontainer/{etat.sh → state.sh} +4 -4
  75. package/.devcontainer/workspace-init.sh +17 -3
  76. package/Makefile +8 -8
  77. package/README.md +195 -194
  78. package/charts/devzone-workspace/templates/statefulset.yaml +1 -1
  79. package/manage/devzone +8 -10
  80. package/manage/scripts/argocd-workspace.sh +1 -1
  81. package/manage/scripts/check-go-layout.sh +40 -0
  82. package/manage/scripts/check-names.sh +61 -0
  83. package/manage/scripts/create-cluster.sh +1 -1
  84. package/manage/scripts/create-mode.sh +2 -2
  85. package/manage/scripts/devzone-create.sh +5 -5
  86. package/manage/scripts/devzone-manifest.sh +3 -3
  87. package/manage/scripts/devzone-update.sh +12 -8
  88. package/manage/scripts/docker-workstation.sh +2 -2
  89. package/manage/scripts/docker.sh +2 -2
  90. package/manage/scripts/{lancer.sh → launch.sh} +10 -51
  91. package/manage/scripts/{migrer-retour.sh → migrate-revert.sh} +4 -4
  92. package/manage/scripts/{migrer.sh → migrate.sh} +8 -14
  93. package/manage/scripts/ports-apps.sh +1 -1
  94. package/manage/scripts/ports-workspace.sh +7 -7
  95. package/manage/scripts/{desinstaller.sh → uninstall.sh} +8 -8
  96. package/manage/scripts/workspace-egress.sh +2 -2
  97. package/manage/scripts/workspace-update.sh +5 -2
  98. package/manage/scripts/workspace-wait.sh +2 -2
  99. package/manage/workspace.sh +4 -4
  100. package/package.json +1 -1
  101. package/.devcontainer/catalogue/app.sh +0 -211
  102. package/.devcontainer/catalogue/catalogue-veilleur.sh +0 -130
  103. package/.devcontainer/catalogue/mysql/installer.sh +0 -87
  104. package/.devcontainer/catalogue/mysql/mysql.sh +0 -262
  105. package/.devcontainer/catalogue/mysql/volume.sh +0 -71
  106. package/.devcontainer/catalogue.sh +0 -231
  107. package/.devcontainer/demarrage.sh +0 -66
  108. package/.devcontainer/docker-relais.sh +0 -149
  109. package/.devcontainer/docker-sans-hote.sh +0 -12
  110. package/.devcontainer/git-identite.sh +0 -28
  111. package/.devcontainer/isolement.sh +0 -65
  112. package/.devcontainer/kind-enveloppe.sh +0 -45
  113. package/.devcontainer/kube-compte.sh +0 -200
  114. package/.devcontainer/kube-joignable.sh +0 -64
  115. package/.devcontainer/paquets.sh +0 -227
  116. /package/.devcontainer/{ia/docker-garde.message → ai/docker-guard.message} +0 -0
  117. /package/.devcontainer/{ia → ai}/host-check.message +0 -0
  118. /package/.devcontainer/{ia → ai}/host-check.sh +0 -0
@@ -1,111 +1,109 @@
1
1
  #!/usr/bin/env bash
2
- # Cluster de devzone (#280) : le cluster où se déploient les modules qui
3
- # fournissent un service (postgres ; gitlab avec #279). Un seul choix par
4
- # instance, gardé dans l'état (ligne « cluster=<contexte kubectl> ») : les
5
- # services d'une instance vivent au même endroit et se déplacent ensemble
6
- # (devzone cluster CTX).
7
- # Bibliothèque sourcée : l'appelant définit RACINE et ETAT.
8
- # cluster_lu contexte choisi, rien s'il n'y en a pas
9
- # cluster_ecrire CTX garde le choix dans l'état
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] [--confirm CTX]
13
- # CTX validé (distant : confirmation),
14
- # sinon choix gardé, sinon menu
15
- # (terminal seulement), sinon défaut local
16
- # cluster_preparer CTX crée le cluster kind dédié s'il manque
17
- # cluster_liberer CTX supprime le kind dédié devenu vide
18
- # kube_joignable_depuis_conteneur FICHIER réécrit 127.0.0.1/localhost
19
- # relais_lancer NOM CTX NS CIBLE PORTS… port-forward gardé en vie
20
- # relais_actif NOM / relais_arreter NOM
21
- # compte_* (kube-compte.sh #430) compte limité et contexte administrateur
2
+ # devzone cluster (#280): the cluster where the modules that provide a service
3
+ # are deployed (postgres; gitlab with #279). A single choice per instance, kept
4
+ # in the state (line « cluster=<kubectl context> »): the services of an instance
5
+ # live in the same place and move together (devzone cluster CTX).
6
+ # Sourced library: the caller defines RACINE and ETAT.
7
+ # cluster_saved chosen context, nothing if there is none
8
+ # cluster_save CTX keeps the choice in the state
9
+ # cluster_is_local CTX 0 if local cluster (config, no network)
10
+ # cluster_candidates local, then dedicated kind, then remote
11
+ # cluster_choose [CTX] [--confirm CTX]
12
+ # CTX validated (remote: confirmation),
13
+ # otherwise kept choice, otherwise menu
14
+ # (terminal only), otherwise local default
15
+ # cluster_prepare CTX creates the dedicated kind cluster if missing
16
+ # cluster_release CTX deletes the dedicated kind cluster once empty
17
+ # kube_reachable_from_container FILE rewrites 127.0.0.1/localhost
18
+ # relay_start NAME CTX NS TARGET PORTS… port-forward kept alive
19
+ # relay_active NAME / relay_stop NAME
20
+ # account_* (kube-account.sh #430) limited account and admin context
22
21
 
23
- # Clusters kind et de l'hôte, comme remoteEnv de devcontainer.json : un
24
- # docker exec ou un script lancé hors du terminal du conteneur ne l'a pas,
25
- # et le relais doit voir le cluster de l'hôte
22
+ # Kind and host clusters, as remoteEnv of devcontainer.json: a docker exec or a
23
+ # script run outside the container terminal does not have it, and the relay
24
+ # must see the host cluster
26
25
  : "${KUBECONFIG:=$HOME/.kube/config:$HOME/.kube/hote.config}"
27
26
  export KUBECONFIG
28
27
 
29
- # État des modules : défini par l'appelant ; valeur par défaut pour les tests
30
- : "${ETAT:=${DEVZONE_ETAT:-$HOME/.devzone.modules}}"
28
+ # Module state: defined by the caller; default value for the tests
29
+ : "${ETAT:=${DEVZONE_STATE:-$HOME/.devzone.modules}}"
31
30
 
32
- # Écriture sûre de l'état (#417) : verrou, temporaire dans le dossier de
33
- # l'état, copie de secours .prec — partagée par devzone, ports et ports-auto
34
- # shellcheck source=SCRIPTDIR/etat.sh
31
+ # Safe state write (#417): lock, temporary file in the state folder, backup copy
32
+ # .prec — shared by devzone, ports and ports-auto
33
+ # shellcheck source=SCRIPTDIR/state.sh
35
34
  # shellcheck disable=SC1091
36
- . "$(dirname "${BASH_SOURCE[0]}")/etat.sh"
35
+ . "$(dirname "${BASH_SOURCE[0]}")/state.sh"
37
36
 
38
- # Nom d'instance : vide ou « devzone » = instance par défaut (pas de suffixe)
37
+ # Instance name: empty or « devzone » = default instance (no suffix)
39
38
  : "${DEVZONE_INSTANCE:=}"
40
39
  INSTANCE_SUFFIX=""
41
40
  if [ -n "$DEVZONE_INSTANCE" ] && [ "$DEVZONE_INSTANCE" != "devzone" ]; then
42
41
  INSTANCE_SUFFIX="-${DEVZONE_INSTANCE}"
43
42
  fi
44
43
 
45
- # Cluster kind dédié, créé sur le Docker de l'hôte ; nom suffixé par instance
46
- CLUSTER_DEDIE=kind-devzone${INSTANCE_SUFFIX}
47
- # Étiquette posée sur tout namespace créé par devzone : un kind dédié sans
48
- # namespace étiqueté n'a plus d'usage et peut être supprimé
49
- CLUSTER_ETIQUETTE=app.kubernetes.io/managed-by=devzone
44
+ # Dedicated kind cluster, created on the host Docker; name suffixed per instance
45
+ CLUSTER_DEDICATED=kind-devzone${INSTANCE_SUFFIX}
46
+ # Label set on every namespace created by devzone : a dedicated kind without a
47
+ # labelled namespace has no use left and can be deleted
48
+ CLUSTER_LABEL=app.kubernetes.io/managed-by=devzone
50
49
 
51
- # Réécriture 127.0.0.1 → host.docker.internal (#291) : partagée avec
52
- # l'enveloppe kind, qui l'applique aussi aux clusters créés à la main
53
- # shellcheck source=SCRIPTDIR/kube-joignable.sh
54
- . "$(dirname "${BASH_SOURCE[0]}")/kube-joignable.sh"
50
+ # Rewrite 127.0.0.1 → host.docker.internal (#291): shared with the kind wrapper,
51
+ # which applies it too to clusters created by hand
52
+ # shellcheck source=SCRIPTDIR/kube-reachable.sh
53
+ . "$(dirname "${BASH_SOURCE[0]}")/kube-reachable.sh"
55
54
 
56
- # Compte Kubernetes limité (#430) : compte_poser, compte_autoriser,
57
- # compte_retirer, compte_jeton, compte_admin (contexte administrateur) ;
58
- # les installeurs l'utilisent, cluster_liberer aussi
59
- # shellcheck source=SCRIPTDIR/kube-compte.sh
60
- . "$(dirname "${BASH_SOURCE[0]}")/kube-compte.sh"
55
+ # Limited Kubernetes account (#430): account_setup, account_allow,
56
+ # account_remove, account_token, account_admin (admin context); the installers
57
+ # use it, cluster_release too
58
+ # shellcheck source=SCRIPTDIR/kube-account.sh
59
+ . "$(dirname "${BASH_SOURCE[0]}")/kube-account.sh"
61
60
 
62
- cluster_lu() {
61
+ cluster_saved() {
63
62
  grep -E '^cluster=' "$ETAT" 2>/dev/null | tail -1 | cut -d= -f2- || true
64
63
  }
65
64
 
66
- cluster_ecrire() {
65
+ cluster_save() {
67
66
  state_write cluster "$1"
68
67
  }
69
68
 
70
- cluster_est_dedie() {
71
- [ "$1" = "${CLUSTER_DEDIE}" ]
69
+ cluster_is_dedicated() {
70
+ [ "$1" = "${CLUSTER_DEDICATED}" ]
72
71
  }
73
72
 
74
- # Cluster local : lu dans la configuration KUBECONFIG, sans appel réseau.
75
- # Le kind dédié est toujours local ; un cluster de l'hôte l'est si son
76
- # serveur écoute sur une adresse de boucle (127.0.0.1, localhost, ::1,
77
- # host.docker.internal).
78
- cluster_est_local() {
79
- local ctx="$1" cluster serveur hote
80
- cluster_est_dedie "$ctx" && return 0
73
+ # Local cluster: read from the KUBECONFIG configuration, without network call.
74
+ # The dedicated kind is always local; a host cluster is local when its server
75
+ # listens on a loopback address (127.0.0.1, localhost, ::1, host.docker.internal).
76
+ cluster_is_local() {
77
+ local ctx="$1" cluster server host
78
+ cluster_is_dedicated "$ctx" && return 0
81
79
  cluster="$(kubectl config view -o jsonpath="{.contexts[?(@.name==\"$ctx\")].context.cluster}" 2>/dev/null || true)"
82
80
  [ -n "$cluster" ] || return 1
83
- serveur="$(kubectl config view -o jsonpath="{.clusters[?(@.name==\"$cluster\")].cluster.server}" 2>/dev/null || true)"
84
- [ -n "$serveur" ] || return 1
85
- # Règle par le nom (ancienne règle de metrics-server.sh)
81
+ server="$(kubectl config view -o jsonpath="{.clusters[?(@.name==\"$cluster\")].cluster.server}" 2>/dev/null || true)"
82
+ [ -n "$server" ] || return 1
83
+ # Rule by name (old rule of metrics-server.sh)
86
84
  case "$ctx" in
87
85
  kind-* | docker-desktop | rancher-desktop | orbstack | minikube) return 0 ;;
88
86
  esac
89
- # Extraction de l'hôte (adresses IPv6 entre crochets gérées)
90
- hote="${serveur#*://}"
91
- hote="${hote%%/*}"
92
- if [[ "$hote" == \[* ]]; then
93
- hote="${hote#[}"
94
- hote="${hote%%]*}"
87
+ # Host extraction (IPv6 addresses in brackets handled)
88
+ host="${server#*://}"
89
+ host="${host%%/*}"
90
+ if [[ "$host" == \[* ]]; then
91
+ host="${host#[}"
92
+ host="${host%%]*}"
95
93
  else
96
- hote="${hote%%:*}"
94
+ host="${host%%:*}"
97
95
  fi
98
- case "$hote" in
96
+ case "$host" in
99
97
  127.0.0.1 | localhost | ::1 | host.docker.internal) return 0 ;;
100
98
  *-control-plane) return 0 ;;
101
99
  esac
102
100
  return 1
103
101
  }
104
102
 
105
- # Pose le contexte « devzone » (cluster + user) sur le contexte donné (défaut :
106
- # le courant) : après une installation sur une machine neuve, --context devzone
107
- # vise d'emblée le cluster des services choisi (#396)
108
- contexte_devzone_poser() {
103
+ # Sets the « devzone » context (cluster + user) on the given context (default:
104
+ # the current one): after an installation on a new machine, --context devzone
105
+ # targets the chosen services cluster from the start (#396)
106
+ devzone_context_set() {
109
107
  local ctx cluster user
110
108
  ctx="${1:-$(kubectl config current-context 2>/dev/null || true)}"
111
109
  if [ -z "$ctx" ]; then
@@ -120,29 +118,29 @@ contexte_devzone_poser() {
120
118
  fi
121
119
  }
122
120
 
123
- cluster_joignable() {
121
+ cluster_reachable() {
124
122
  kubectl --context "$1" --request-timeout=3s get --raw /readyz >/dev/null 2>&1
125
123
  }
126
124
 
127
- # Contextes de l'hôte : locaux d'abord, puis le kind dédié, enfin les distants
128
- cluster_candidats() {
129
- local hote="${DEVZONE_KUBE_HOTE:-$HOME/.kube/hote.config}" c
130
- if [ -f "$hote" ]; then
131
- # 1. Clusters locaux de l'hôte (serveur sur une adresse de boucle)
132
- for c in $(KUBECONFIG="$hote" kubectl config get-contexts -o name 2>/dev/null); do
133
- cluster_est_dedie "$c" && continue
134
- if cluster_est_local "$c" && cluster_joignable "$c"; then
125
+ # Host contexts: local ones first, then the dedicated kind, finally the remote ones
126
+ cluster_candidates() {
127
+ local host="${DEVZONE_KUBE_HOST:-$HOME/.kube/hote.config}" c
128
+ if [ -f "$host" ]; then
129
+ # 1. Local clusters of the host (server on a loopback address)
130
+ for c in $(KUBECONFIG="$host" kubectl config get-contexts -o name 2>/dev/null); do
131
+ cluster_is_dedicated "$c" && continue
132
+ if cluster_is_local "$c" && cluster_reachable "$c"; then
135
133
  echo "$c"
136
134
  fi
137
135
  done
138
136
  fi
139
- # 2. Cluster kind dédié
140
- echo "$CLUSTER_DEDIE"
141
- if [ -f "$hote" ]; then
142
- # 3. Clusters distants de l'hôte
143
- for c in $(KUBECONFIG="$hote" kubectl config get-contexts -o name 2>/dev/null); do
144
- cluster_est_dedie "$c" && continue
145
- if ! cluster_est_local "$c" && cluster_joignable "$c"; then
137
+ # 2. Dedicated kind cluster
138
+ echo "$CLUSTER_DEDICATED"
139
+ if [ -f "$host" ]; then
140
+ # 3. Remote clusters of the host
141
+ for c in $(KUBECONFIG="$host" kubectl config get-contexts -o name 2>/dev/null); do
142
+ cluster_is_dedicated "$c" && continue
143
+ if ! cluster_is_local "$c" && cluster_reachable "$c"; then
146
144
  echo "$c"
147
145
  fi
148
146
  done
@@ -150,220 +148,220 @@ cluster_candidats() {
150
148
  return 0
151
149
  }
152
150
 
153
- # Menu sur stderr (stdout porte la réponse) ; Entrée = premier candidat
151
+ # Menu on stderr (stdout carries the answer); Enter = first candidate
154
152
  cluster_menu() {
155
- local candidats=() c i=1 reponse
156
- while IFS= read -r c; do candidats+=("$c"); done < <(cluster_candidats)
153
+ local candidates=() c i=1 answer
154
+ while IFS= read -r c; do candidates+=("$c"); done < <(cluster_candidates)
157
155
  {
158
- echo "devzone : sur quel cluster installer les services de devzone ?"
159
- for c in "${candidats[@]}"; do
160
- if cluster_est_dedie "$c"; then
161
- echo " $i) $c cluster kind dédié, dans le conteneur (défaut)"
162
- elif cluster_est_local "$c"; then
163
- echo " $i) $c cluster local"
156
+ echo "devzone : on which cluster should the devzone services be installed?"
157
+ for c in "${candidates[@]}"; do
158
+ if cluster_is_dedicated "$c"; then
159
+ echo " $i) $c dedicated kind cluster, in the container (default)"
160
+ elif cluster_is_local "$c"; then
161
+ echo " $i) $c local cluster"
164
162
  else
165
- echo " $i) $c cluster distant"
163
+ echo " $i) $c remote cluster"
166
164
  fi
167
165
  i=$((i + 1))
168
166
  done
169
- [ -f "${DEVZONE_KUBE_HOTE:-$HOME/.kube/hote.config}" ] ||
170
- echo " (clusters de l'hôte invisibles : devzone enable kubernetes)"
167
+ [ -f "${DEVZONE_KUBE_HOST:-$HOME/.kube/hote.config}" ] ||
168
+ echo " (host clusters not visible: devzone enable kubernetes)"
171
169
  } >&2
172
- printf 'Numéro [1] : ' >&2
173
- read -r reponse || reponse=""
174
- reponse="${reponse:-1}"
175
- case "$reponse" in
176
- *[!0-9]* | 0) echo "devzone : choix invalide : $reponse" >&2; return 2 ;;
170
+ printf 'Number [1]: ' >&2
171
+ read -r answer || answer=""
172
+ answer="${answer:-1}"
173
+ case "$answer" in
174
+ *[!0-9]* | 0) echo "devzone : invalid choice: $answer" >&2; return 2 ;;
177
175
  esac
178
- if [ "$reponse" -gt "${#candidats[@]}" ]; then
179
- echo "devzone : choix invalide : $reponse" >&2
176
+ if [ "$answer" -gt "${#candidates[@]}" ]; then
177
+ echo "devzone : invalid choice: $answer" >&2
180
178
  return 2
181
179
  fi
182
- echo "${candidats[$((reponse - 1))]}"
180
+ echo "${candidates[$((answer - 1))]}"
183
181
  }
184
182
 
185
- # Terminal interactif ; DEVZONE_INTERACTIF=1 pour les tests (stdin redirigé)
186
- cluster_interactif() {
187
- [ "${DEVZONE_INTERACTIF:-}" = 1 ] || [ -t 0 ]
183
+ # Interactive terminal; DEVZONE_INTERACTIVE=1 for the tests (stdin redirected)
184
+ cluster_interactive() {
185
+ [ "${DEVZONE_INTERACTIVE:-}" = 1 ] || [ -t 0 ]
188
186
  }
189
187
 
190
- cluster_choisir() {
191
- local voulu="" confirmer="" c reponse arg
188
+ cluster_choose() {
189
+ local wanted="" confirm="" c answer arg
192
190
  while [ "$#" -gt 0 ]; do
193
191
  arg="$1"
194
192
  shift
195
193
  case "$arg" in
196
194
  --confirm)
197
195
  if [ "$#" -eq 0 ]; then
198
- echo "devzone : --confirm attend un contexte" >&2
196
+ echo "devzone : --confirm needs a context" >&2
199
197
  return 2
200
198
  fi
201
- confirmer="$1"
199
+ confirm="$1"
202
200
  shift
203
201
  ;;
204
- --confirm=*) confirmer="${arg#*=}" ;;
202
+ --confirm=*) confirm="${arg#*=}" ;;
205
203
  -*)
206
- echo "devzone : argument inconnu : $arg (cluster_choisir [CTX] [--confirm CTX])" >&2
204
+ echo "devzone : unknown argument: $arg (cluster_choose [CTX] [--confirm CTX])" >&2
207
205
  return 2
208
206
  ;;
209
207
  *)
210
- if [ -n "$voulu" ]; then
211
- echo "devzone : argument inconnu : $arg (cluster_choisir [CTX] [--confirm CTX])" >&2
208
+ if [ -n "$wanted" ]; then
209
+ echo "devzone : unknown argument: $arg (cluster_choose [CTX] [--confirm CTX])" >&2
212
210
  return 2
213
211
  fi
214
- voulu="$arg"
212
+ wanted="$arg"
215
213
  ;;
216
214
  esac
217
215
  done
218
- if [ -n "$voulu" ]; then
216
+ if [ -n "$wanted" ]; then
219
217
  while IFS= read -r c; do
220
- [ "$c" = "$voulu" ] && break
221
- done < <(cluster_candidats)
222
- if [ "$c" != "$voulu" ]; then
223
- echo "devzone : cluster inconnu ou injoignable : $voulu ; possibles : $(cluster_candidats | tr '\n' ' ')" >&2
218
+ [ "$c" = "$wanted" ] && break
219
+ done < <(cluster_candidates)
220
+ if [ "$c" != "$wanted" ]; then
221
+ echo "devzone : unknown or unreachable cluster: $wanted; candidates: $(cluster_candidates | tr '\n' ' ')" >&2
224
222
  return 2
225
223
  fi
226
- # Distant : confirmation requise. --confirm ne vaut que s'il est
227
- # exactement le contexte demandé ; DEVZONE_CLUSTER_DISTANT reste
228
- # accepté pour les tests et la CI.
229
- if ! cluster_est_local "$voulu"; then
230
- if [ -n "$confirmer" ]; then
231
- if [ "$confirmer" != "$voulu" ]; then
232
- echo "devzone : cluster distant refusé : $voulu (--confirm $voulu)" >&2
224
+ # Remote: confirmation required. --confirm counts only if it is exactly
225
+ # the requested context; DEVZONE_CLUSTER_REMOTE is still accepted for
226
+ # the tests and CI
227
+ if ! cluster_is_local "$wanted"; then
228
+ if [ -n "$confirm" ]; then
229
+ if [ "$confirm" != "$wanted" ]; then
230
+ echo "devzone : remote cluster refused: $wanted (--confirm $wanted)" >&2
233
231
  return 2
234
232
  fi
235
- elif [ -n "${DEVZONE_CLUSTER_DISTANT:-}" ]; then
236
- if [ "${DEVZONE_CLUSTER_DISTANT}" != "$voulu" ]; then
237
- echo "devzone : cluster distant refusé : $voulu (DEVZONE_CLUSTER_DISTANT doit valoir exactement $voulu)" >&2
233
+ elif [ -n "${DEVZONE_CLUSTER_REMOTE:-}" ]; then
234
+ if [ "${DEVZONE_CLUSTER_REMOTE}" != "$wanted" ]; then
235
+ echo "devzone : remote cluster refused: $wanted (DEVZONE_CLUSTER_REMOTE must be exactly $wanted)" >&2
238
236
  return 2
239
237
  fi
240
- elif cluster_interactif; then
241
- printf 'cluster distant : %s ; tape son nom pour confirmer : ' "$voulu" >&2
242
- read -r reponse || reponse=""
243
- if [ "$reponse" != "$voulu" ]; then
244
- echo "devzone : cluster distant refusé : $voulu (--confirm $voulu)" >&2
238
+ elif cluster_interactive; then
239
+ printf 'remote cluster: %s ; type its name to confirm: ' "$wanted" >&2
240
+ read -r answer || answer=""
241
+ if [ "$answer" != "$wanted" ]; then
242
+ echo "devzone : remote cluster refused: $wanted (--confirm $wanted)" >&2
245
243
  return 2
246
244
  fi
247
245
  else
248
- echo "devzone : cluster distant refusé : $voulu (--confirm $voulu)" >&2
246
+ echo "devzone : remote cluster refused: $wanted (--confirm $wanted)" >&2
249
247
  return 2
250
248
  fi
251
249
  fi
252
- echo "$voulu"
250
+ echo "$wanted"
253
251
  return 0
254
252
  fi
255
- c="$(cluster_lu)"
253
+ c="$(cluster_saved)"
256
254
  if [ -n "$c" ]; then
257
255
  echo "$c"
258
- elif cluster_interactif; then
256
+ elif cluster_interactive; then
259
257
  cluster_menu
260
258
  else
261
- # Défaut : local seulement (jamais distant par défaut)
262
- local hote_choix=""
263
- if [ -f "${DEVZONE_KUBE_HOTE:-$HOME/.kube/hote.config}" ]; then
264
- hote_choix="$(KUBECONFIG="${DEVZONE_KUBE_HOTE:-$HOME/.kube/hote.config}" kubectl config current-context 2>/dev/null || true)"
259
+ # Default: local only (never remote by default)
260
+ local host_choice=""
261
+ if [ -f "${DEVZONE_KUBE_HOST:-$HOME/.kube/hote.config}" ]; then
262
+ host_choice="$(KUBECONFIG="${DEVZONE_KUBE_HOST:-$HOME/.kube/hote.config}" kubectl config current-context 2>/dev/null || true)"
265
263
  fi
266
- if [ -n "$hote_choix" ] && cluster_est_local "$hote_choix" && cluster_joignable "$hote_choix"; then
267
- echo "$hote_choix"
264
+ if [ -n "$host_choice" ] && cluster_is_local "$host_choice" && cluster_reachable "$host_choice"; then
265
+ echo "$host_choice"
268
266
  else
269
- echo "$CLUSTER_DEDIE"
267
+ echo "$CLUSTER_DEDICATED"
270
268
  fi
271
269
  fi
272
270
  }
273
271
 
274
- # Lance kind sans basculer le contexte courant de kubectl (#366) : le contexte
275
- # d'avant est remis, ou retiré s'il n'y en avait pas. Le code de kind est rendu
276
- # meme sous set -e : la restauration a lieu avant.
277
- kind_sans_basculer() {
278
- local precedent code=0
279
- precedent="$(kubectl config current-context 2>/dev/null || true)"
272
+ # Runs kind without switching kubectl's current context (#366): the previous
273
+ # one is restored, or removed if there was none. The kind exit code is returned
274
+ # even under set -e: the restore happens first.
275
+ kind_keep_context() {
276
+ local previous code=0
277
+ previous="$(kubectl config current-context 2>/dev/null || true)"
280
278
  kind "$@" || code=$?
281
- if [ -n "$precedent" ]; then
282
- kubectl config use-context "$precedent" >/dev/null 2>&1 || true
279
+ if [ -n "$previous" ]; then
280
+ kubectl config use-context "$previous" >/dev/null 2>&1 || true
283
281
  else
284
282
  KUBECONFIG="$HOME/.kube/config" kubectl config unset current-context >/dev/null 2>&1 || true
285
283
  fi
286
284
  return "$code"
287
285
  }
288
286
 
289
- # Cree un cluster kind sans basculer le contexte courant de kubectl.
290
- kind_creer_sans_basculer() {
291
- kind_sans_basculer create cluster "$@"
287
+ # Creates a kind cluster without switching kubectl's current context.
288
+ kind_create_keep_context() {
289
+ kind_keep_context create cluster "$@"
292
290
  }
293
291
 
294
- cluster_preparer() {
292
+ cluster_prepare() {
295
293
  local ctx="$1"
296
- if [ "$ctx" = "$CLUSTER_DEDIE" ]; then
294
+ if [ "$ctx" = "$CLUSTER_DEDICATED" ]; then
297
295
  if ! kind get clusters 2>/dev/null | grep -qx "devzone${INSTANCE_SUFFIX}"; then
298
- echo "▶ Création du cluster kind devzone (environ 1 min)…"
299
- # Sur le Docker de l'hôte, l'API écoute sur 127.0.0.1 du poste :
300
- # kube_joignable_depuis_conteneur la rend joignable du conteneur
301
- # (host.docker.internal), sans l'exposer sur le réseau local.
302
- # Docker de l'hôte chargé (son Kubernetes, d'autres clusters) : l'API du
303
- # nœud peut redémarrer pendant l'initialisation et kind abandonne à
304
- # quelques secondes près. Une seconde tentative, sur un cluster neuf.
305
- if ! kind_creer_sans_basculer --name "devzone${INSTANCE_SUFFIX}" --wait 120s; then
306
- echo "▶ Nouvelle tentative de création du cluster kind…"
296
+ echo "▶ Creating the kind devzone cluster (about 1 min)…"
297
+ # On the host Docker, the API listens on the workstation's 127.0.0.1:
298
+ # kube_reachable_from_container makes it reachable from the container
299
+ # (host.docker.internal), without exposing it on the local network.
300
+ # Busy host Docker (its Kubernetes, other clusters): the node API can
301
+ # restart during initialization and kind gives up within seconds. A
302
+ # second attempt, on a fresh cluster.
303
+ if ! kind_create_keep_context --name "devzone${INSTANCE_SUFFIX}" --wait 120s; then
304
+ echo "▶ Retrying the kind cluster creation…"
307
305
  kind delete cluster --name "devzone${INSTANCE_SUFFIX}" >/dev/null 2>&1 || true
308
- kind_creer_sans_basculer --name "devzone${INSTANCE_SUFFIX}" --wait 120s || return 1
306
+ kind_create_keep_context --name "devzone${INSTANCE_SUFFIX}" --wait 120s || return 1
309
307
  fi
310
- kube_joignable_depuis_conteneur "$HOME/.kube/config"
308
+ kube_reachable_from_container "$HOME/.kube/config"
311
309
  fi
312
- elif ! cluster_joignable "$ctx"; then
313
- echo "devzone : cluster $ctx injoignable (module kubernetes actif ? cluster démarré ?)" >&2
310
+ elif ! cluster_reachable "$ctx"; then
311
+ echo "devzone : cluster $ctx unreachable (kubernetes module enabled? cluster started?)" >&2
314
312
  return 1
315
313
  fi
316
- # S'il vient d'être créé, le cluster des services doit tout de suite porter
317
- # le contexte devzone, sans quoi l'installation vise l'ancien cluster (#396)
318
- contexte_devzone_poser "$ctx" || echo "devzone : contexte devzone non posé sur $ctx" >&2
314
+ # If it has just been created, the services cluster must carry the devzone
315
+ # context at once, otherwise the installation targets the old cluster (#396)
316
+ devzone_context_set "$ctx" || echo "devzone : devzone context not set on $ctx" >&2
319
317
  }
320
318
 
321
- # Kind dédié sans plus aucun namespace de devzone : supprimé (il n'occupe
322
- # que de la mémoire). Jamais un cluster de l'hôte.
323
- cluster_liberer() {
324
- local ctx="$1" reste
325
- cluster_est_dedie "$ctx" || return 0
319
+ # Dedicated kind with no devzone namespace left: deleted (it only uses memory).
320
+ # Never a host cluster.
321
+ cluster_release() {
322
+ local ctx="$1" left
323
+ cluster_is_dedicated "$ctx" || return 0
326
324
  kind get clusters 2>/dev/null | grep -qx "devzone${INSTANCE_SUFFIX}" || return 0
327
- # Lecture des namespaces étiquetés par l'administrateur (#430) : la liste
328
- # des namespaces est refusée au compte limité
329
- reste="$(compte_admin "$ctx" get namespaces -l "$CLUSTER_ETIQUETTE" -o name 2>/dev/null || true)"
330
- if [ -z "$reste" ]; then
325
+ # Reading the namespaces labelled by the administrator (#430): the namespace
326
+ # list is refused to the limited account
327
+ left="$(account_admin "$ctx" get namespaces -l "$CLUSTER_LABEL" -o name 2>/dev/null || true)"
328
+ if [ -z "$left" ]; then
331
329
  kind delete cluster --name "devzone${INSTANCE_SUFFIX}" >/dev/null 2>&1 || true
332
- echo "▶ Cluster kind devzone supprimé (plus aucun service)."
330
+ echo "▶ kind devzone cluster removed (no service left)."
333
331
  fi
334
332
  }
335
333
 
336
- # ---- Relais : port d'un service du cluster sur 127.0.0.1 du conteneur ----
337
- # kubectl port-forward marche sur tout cluster dont l'API répond (kind dédié
338
- # comme cluster de l'hôte), sans exposer de port sur les nœuds. Il s'arrête
339
- # quand le pod redémarre : la boucle le relance. PID et journal dans
340
- # workspace/.<nom>/ (dossier du module, ignoré par git).
341
- relais_dossier() {
334
+ # ---- Relay: port of a cluster service on the container's 127.0.0.1 ----
335
+ # kubectl port-forward works on every cluster whose API answers (dedicated kind
336
+ # or host cluster), without exposing a port on the nodes. It stops when the pod
337
+ # restarts: the loop restarts it. PID and log in workspace/.<name>/ (module
338
+ # folder, ignored by git).
339
+ relay_dir() {
342
340
  echo "$RACINE/workspace/.$1"
343
341
  }
344
342
 
345
- relais_actif() {
343
+ relay_active() {
346
344
  local pid
347
- pid="$(cat "$(relais_dossier "$1")/relais.pid" 2>/dev/null || true)"
345
+ pid="$(cat "$(relay_dir "$1")/relais.pid" 2>/dev/null || true)"
348
346
  [ -n "$pid" ] && kill -0 "$pid" 2>/dev/null
349
347
  }
350
348
 
351
- relais_lancer() {
352
- local nom="$1" ctx="$2" ns="$3" cible="$4" dossier
349
+ relay_start() {
350
+ local name="$1" ctx="$2" ns="$3" target="$4" dir
353
351
  shift 4
354
- dossier="$(relais_dossier "$nom")"
355
- mkdir -p "$dossier"
356
- relais_actif "$nom" && return 0
357
- # setsid : session à part, le relais survit à la fin du script qui l'a
358
- # lancé (postStartCommand, make shell) ; absent sur macOS (tests bash 3.2)
359
- local detache=()
360
- command -v setsid >/dev/null 2>&1 && detache=(setsid)
361
- # port-forward vise un pod précis et ne voit sa disparition qu'à la
362
- # connexion suivante, qui échoue. Pour un service, la boucle suit donc le
363
- # pod prêt derrière lui (UID dans ses endpoints) : attend qu'il y en ait
364
- # un, puis relance port-forward dès qu'il change (pod redémarré).
365
- # shellcheck disable=SC2016 # variables développées par le bash du relais
366
- ${detache[@]+"${detache[@]}"} nohup bash -c '
352
+ dir="$(relay_dir "$name")"
353
+ mkdir -p "$dir"
354
+ relay_active "$name" && return 0
355
+ # setsid: separate session, the relay survives the end of the script that
356
+ # started it (postStartCommand, make shell); absent on macOS (bash 3.2 tests)
357
+ local detached=()
358
+ command -v setsid >/dev/null 2>&1 && detached=(setsid)
359
+ # port-forward targets one precise pod and sees its disappearance only at the
360
+ # next connection, which fails. For a service, the loop therefore follows the
361
+ # ready pod behind it (UID in its endpoints): waits until there is one, then
362
+ # restarts port-forward as soon as it changes (pod restarted).
363
+ # shellcheck disable=SC2016 # variables expanded by the relay's bash
364
+ ${detached[@]+"${detached[@]}"} nohup bash -c '
367
365
  pod() {
368
366
  case "$2" in
369
367
  svc/*) kubectl --context "$0" -n "$1" get endpoints "${2#svc/}" -o jsonpath="{.subsets[*].addresses[*].targetRef.uid}" 2>/dev/null ;;
@@ -382,22 +380,22 @@ relais_lancer() {
382
380
  wait "$pf" 2>/dev/null
383
381
  sleep 1
384
382
  done' \
385
- "$ctx" "$ns" "$cible" "$@" >"$dossier/relais.log" 2>&1 &
386
- echo "$!" >"$dossier/relais.pid"
383
+ "$ctx" "$ns" "$target" "$@" >"$dir/relais.log" 2>&1 &
384
+ echo "$!" >"$dir/relais.pid"
387
385
  }
388
386
 
389
- relais_arreter() {
390
- local fichier pid enfants
391
- fichier="$(relais_dossier "$1")/relais.pid"
392
- pid="$(cat "$fichier" 2>/dev/null || true)"
387
+ relay_stop() {
388
+ local file pid children
389
+ file="$(relay_dir "$1")/relais.pid"
390
+ pid="$(cat "$file" 2>/dev/null || true)"
393
391
  if [ -n "$pid" ]; then
394
- # Enfants (port-forward) relevés avant : une fois la boucle tuée, ils
395
- # sont rattachés à init et pgrep -P ne les voit plus. La boucle
396
- # d'abord, sinon elle relancerait le port-forward.
397
- enfants="$(pgrep -P "$pid" 2>/dev/null || true)"
392
+ # Children (port-forward) listed before: once the loop is killed, they
393
+ # are reattached to init and pgrep -P no longer sees them. The loop first,
394
+ # otherwise it would restart the port-forward.
395
+ children="$(pgrep -P "$pid" 2>/dev/null || true)"
398
396
  kill "$pid" 2>/dev/null || true
399
- # shellcheck disable=SC2086 # liste de PID
400
- [ -z "$enfants" ] || kill $enfants 2>/dev/null || true
397
+ # shellcheck disable=SC2086 # list of PIDs
398
+ [ -z "$children" ] || kill $children 2>/dev/null || true
401
399
  fi
402
- rm -f "$fichier"
400
+ rm -f "$file"
403
401
  }