devzone 2.0.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 (90) hide show
  1. package/.devcontainer/agent-errors.sh +6 -6
  2. package/.devcontainer/agent-pod-manifest.sh +4 -4
  3. package/.devcontainer/agent-session.sh +2 -2
  4. package/.devcontainer/agent-state-json.sh +2 -2
  5. package/.devcontainer/agent-workspace.sh +1 -1
  6. package/.devcontainer/agent.sh +7 -7
  7. package/.devcontainer/ai/host-models.sh +2 -2
  8. package/.devcontainer/ai/plugins/devzone-guard-v2.js +3 -3
  9. package/.devcontainer/ai/plugins/devzone-guard.js +3 -3
  10. package/.devcontainer/argocd/argocd.sh +90 -89
  11. package/.devcontainer/argocd/catalog-argocd.sh +2 -2
  12. package/.devcontainer/argocd/services-hook.sh +3 -3
  13. package/.devcontainer/argocd/services.sh +1 -1
  14. package/.devcontainer/catalog/app.sh +114 -116
  15. package/.devcontainer/catalog/catalog-watcher.sh +62 -62
  16. package/.devcontainer/catalog/mysql/app.conf +1 -1
  17. package/.devcontainer/catalog/mysql/install.sh +40 -40
  18. package/.devcontainer/catalog/mysql/mysql.sh +141 -141
  19. package/.devcontainer/catalog/mysql/volume.sh +39 -39
  20. package/.devcontainer/catalog.sh +112 -112
  21. package/.devcontainer/chart-direct.sh +1 -1
  22. package/.devcontainer/cluster.sh +216 -218
  23. package/.devcontainer/clusters.sh +41 -41
  24. package/.devcontainer/devzone +92 -1495
  25. package/.devcontainer/devzone-ai-guard.sh +76 -0
  26. package/.devcontainer/devzone-ai.sh +201 -0
  27. package/.devcontainer/devzone-cluster.sh +210 -0
  28. package/.devcontainer/devzone-modules.sh +126 -0
  29. package/.devcontainer/devzone-platform.sh +189 -0
  30. package/.devcontainer/devzone-repair.sh +94 -0
  31. package/.devcontainer/devzone-services.sh +241 -0
  32. package/.devcontainer/devzone-skill.sh +97 -0
  33. package/.devcontainer/devzone-status.sh +140 -0
  34. package/.devcontainer/devzone-version.sh +78 -0
  35. package/.devcontainer/git-identity.sh +28 -0
  36. package/.devcontainer/gitlab/chart.sh +2 -2
  37. package/.devcontainer/gitlab/gitlab.sh +81 -82
  38. package/.devcontainer/gitlab/installation.sh +109 -109
  39. package/.devcontainer/gitlab/secrets.sh +47 -47
  40. package/.devcontainer/gitlab/seed.sh +77 -77
  41. package/.devcontainer/gitlab/test-gitlab.sh +242 -243
  42. package/.devcontainer/help.sh +1 -1
  43. package/.devcontainer/isolation.sh +30 -30
  44. package/.devcontainer/kind-wrapper.sh +17 -17
  45. package/.devcontainer/kube-account.sh +112 -113
  46. package/.devcontainer/kube-config.sh +45 -46
  47. package/.devcontainer/{invite-kube.sh → kube-prompt.sh} +6 -6
  48. package/.devcontainer/kube-reachable.sh +40 -40
  49. package/.devcontainer/memory.sh +1 -1
  50. package/.devcontainer/metrics-server.sh +2 -2
  51. package/.devcontainer/opencode.jsonc +2 -2
  52. package/.devcontainer/packages.sh +136 -135
  53. package/.devcontainer/password.sh +1 -1
  54. package/.devcontainer/ports-auto.sh +152 -153
  55. package/.devcontainer/ports-json.sh +16 -15
  56. package/.devcontainer/ports.sh +126 -122
  57. package/.devcontainer/post-create.sh +52 -52
  58. package/.devcontainer/postgres/postgres.sh +174 -174
  59. package/.devcontainer/rename-legacy-files.sh +103 -0
  60. package/.devcontainer/services-admin.sh +3 -3
  61. package/.devcontainer/skills/devzone/SKILL.md +40 -41
  62. package/.devcontainer/startup.sh +48 -49
  63. package/.devcontainer/state-gitops.sh +1 -1
  64. package/.devcontainer/state-json.sh +36 -62
  65. package/.devcontainer/state.sh +2 -2
  66. package/.devcontainer/workspace-init.sh +16 -2
  67. package/Makefile +1 -1
  68. package/README.md +195 -194
  69. package/charts/devzone-workspace/templates/statefulset.yaml +1 -1
  70. package/manage/devzone +5 -7
  71. package/manage/scripts/argocd-workspace.sh +1 -1
  72. package/manage/scripts/check-names.sh +6 -5
  73. package/manage/scripts/create-cluster.sh +1 -1
  74. package/manage/scripts/create-mode.sh +2 -2
  75. package/manage/scripts/devzone-create.sh +3 -3
  76. package/manage/scripts/devzone-manifest.sh +1 -1
  77. package/manage/scripts/devzone-update.sh +12 -8
  78. package/manage/scripts/launch.sh +7 -48
  79. package/manage/scripts/migrate-revert.sh +3 -3
  80. package/manage/scripts/migrate.sh +7 -13
  81. package/manage/scripts/ports-apps.sh +1 -1
  82. package/manage/scripts/ports-workspace.sh +7 -7
  83. package/manage/scripts/uninstall.sh +8 -8
  84. package/manage/scripts/workspace-egress.sh +2 -2
  85. package/manage/scripts/workspace-update.sh +5 -2
  86. package/manage/scripts/workspace-wait.sh +2 -2
  87. package/package.json +1 -1
  88. package/.devcontainer/docker-relay.sh +0 -149
  89. package/.devcontainer/docker-without-host.sh +0 -12
  90. package/.devcontainer/git-identite.sh +0 -28
@@ -13,7 +13,7 @@ devzone_aide() {
13
13
  devzone enable <module> enable and apply at once
14
14
  devzone disable <module> [--yes] disable and apply at once (--yes: also deletes the data)
15
15
  devzone apply install what is enabled (post-create.sh)
16
- devzone repair repair Docker relay, gitlab, postgres, ports, passwords
16
+ devzone repair repair gitlab, postgres, ports, passwords
17
17
  devzone start full start (startup scripts and summary)
18
18
  devzone metrics [context…] install metrics-server (kubectl top, k9s)
19
19
  devzone use CTX [--confirm CTX] switch the kubectl working cluster
@@ -1,14 +1,14 @@
1
1
  #!/usr/bin/env bash
2
- # Isolement network et autorisation d'acces entre namespaces devzone.
3
- # Fichier <= 250 lignes : fonctions namespace_isoler, autoriser, interdire.
4
- # Ces fonctions modifient des NetworkPolicies dans le cluster Kubernetes.
5
- # Aides de manage/test/commun.bash : relais_docker_isole, kube_isole.
2
+ # Network isolation and access authorization between devzone namespaces.
3
+ # File <= 250 lines: functions namespace_isolate, allow, forbid.
4
+ # These functions modify NetworkPolicies in the Kubernetes cluster.
5
+ # Helpers of manage/test/commun.bash: kube_isole.
6
6
 
7
- # Pose une NetworkPolicy isolante dans un namespace.
8
- # Seuls les pods du meme namespace peuvent joindre les services.
9
- namespace_isoler() {
7
+ # Sets an isolating NetworkPolicy in a namespace.
8
+ # Only the pods of the same namespace can reach the services.
9
+ namespace_isolate() {
10
10
  local ns="${1:-}"
11
- [ -n "$ns" ] || { echo "devzone : namespace manquant" >&2; return 2; }
11
+ [ -n "$ns" ] || { echo "devzone : namespace missing" >&2; return 2; }
12
12
 
13
13
  kubectl --context devzone -n "$ns" apply -f - <<EOF
14
14
  apiVersion: networking.k8s.io/v1
@@ -25,41 +25,41 @@ spec:
25
25
  EOF
26
26
  }
27
27
 
28
- # Ajoute une règle namespaceSelector dans la NetworkPolicy du namespace cible,
29
- # permettant l'accès depuis l'extérieur de ce namespace.
30
- # Sans cette règle, une application dans un autre namespace ne peut pas
31
- # joindre les services devzone (postgres, etc.).
32
- autoriser() {
33
- local ns_cible="${1:-}" patch sortie
34
- [ -n "$ns_cible" ] || { echo "devzone : namespace cible manquant" >&2; return 2; }
28
+ # Adds a namespaceSelector rule to the NetworkPolicy of the target namespace,
29
+ # allowing access from outside this namespace.
30
+ # Without this rule, an application in another namespace cannot reach the
31
+ # devzone services (postgres, etc.).
32
+ allow() {
33
+ local target_ns="${1:-}" patch output
34
+ [ -n "$target_ns" ] || { echo "devzone : target namespace missing" >&2; return 2; }
35
35
 
36
- kubectl --context devzone -n "$ns_cible" get networkpolicy devzone-meme-namespace \
37
- -o yaml 2>/dev/null | kubectl --context devzone -n "$ns_cible" apply -f - >/dev/null 2>&1 ||
38
- { echo "devzone : impossible d'appliquer la NetworkPolicy isolante dans $ns_cible" >&2; return 1; }
36
+ kubectl --context devzone -n "$target_ns" get networkpolicy devzone-meme-namespace \
37
+ -o yaml 2>/dev/null | kubectl --context devzone -n "$target_ns" apply -f - >/dev/null 2>&1 ||
38
+ { echo "devzone : cannot apply the isolating NetworkPolicy in $target_ns" >&2; return 1; }
39
39
 
40
40
  patch="$(jq -nc '{"spec":{"ingress":[{"from":[{"podSelector":{},
41
41
  "namespaceSelector":{"matchLabels":{"app.kubernetes.io/managed-by":"devzone"}}}]}]}}')"
42
- if ! sortie="$(kubectl --context devzone -n "$ns_cible" patch networkpolicy devzone-meme-namespace \
42
+ if ! output="$(kubectl --context devzone -n "$target_ns" patch networkpolicy devzone-meme-namespace \
43
43
  -p "$patch" 2>&1)"; then
44
- echo "devzone : impossible d'autoriser l'accès vers $ns_cible : $sortie" >&2
44
+ echo "devzone : cannot allow access to $target_ns : $output" >&2
45
45
  return 1
46
46
  fi
47
47
 
48
- echo "devzone : règle autorisée vers $ns_cible"
48
+ echo "devzone : rule allowed to $target_ns"
49
49
  }
50
50
 
51
- # Retire la règle namespaceSelector de la NetworkPolicy,
52
- # bloquant à nouveau l'accès depuis le namespace specifie.
53
- interdire() {
54
- local ns_cible="${1:-}" patch sortie
55
- [ -n "$ns_cible" ] || { echo "devzone : namespace cible manquant" >&2; return 2; }
51
+ # Removes the namespaceSelector rule from the NetworkPolicy,
52
+ # blocking access again from the given namespace.
53
+ forbid() {
54
+ local target_ns="${1:-}" patch output
55
+ [ -n "$target_ns" ] || { echo "devzone : target namespace missing" >&2; return 2; }
56
56
 
57
57
  patch="$(jq -nc '{"spec":{"ingress":[{"from":[{"podSelector":{}}]}]}}')"
58
- if ! sortie="$(kubectl --context devzone -n "$ns_cible" patch networkpolicy devzone-meme-namespace \
58
+ if ! output="$(kubectl --context devzone -n "$target_ns" patch networkpolicy devzone-meme-namespace \
59
59
  -p "$patch" 2>&1)"; then
60
- echo "devzone : impossible d'interdire l'accès vers $ns_cible : $sortie" >&2
60
+ echo "devzone : cannot forbid access to $target_ns : $output" >&2
61
61
  return 1
62
62
  fi
63
63
 
64
- echo "devzone : règle interdite vers $ns_cible"
65
- }
64
+ echo "devzone : rule forbidden to $target_ns"
65
+ }
@@ -1,12 +1,12 @@
1
1
  #!/usr/bin/env bash
2
- # Enveloppe de kind (#291), installée comme /usr/local/bin/kind ; le vrai
3
- # binaire est kind-reel. Avec le Docker de l'hôte, un cluster créé par
4
- # « kind create cluster » écrit server: https://127.0.0.1:<port> : injoignable
5
- # depuis le conteneur. Après une création ou un export de kubeconfig réussis,
6
- # l'adresse est rendue joignable (kube-reachable.sh). Tout le reste passe tel quel.
2
+ # kind wrapper (#291), installed as /usr/local/bin/kind; the real binary is
3
+ # kind-reel. With the host's Docker, a cluster created by « kind create cluster »
4
+ # writes server: https://127.0.0.1:<port>: unreachable from the container. After
5
+ # a successful creation or kubeconfig export, the address is made reachable
6
+ # (kube-reachable.sh). Everything else passes through unchanged.
7
7
  set -uo pipefail
8
8
 
9
- KIND_REEL="${DEVZONE_KIND_REEL:-/usr/local/bin/kind-reel}"
9
+ KIND_REEL="${DEVZONE_KIND_REAL:-/usr/local/bin/kind-reel}"
10
10
  ICI="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
11
11
  if [ -f "$ICI/kube-reachable.sh" ]; then
12
12
  # shellcheck source=SCRIPTDIR/kube-reachable.sh
@@ -25,21 +25,21 @@ case "${1:-} ${2:-}" in
25
25
  *) exit 0 ;;
26
26
  esac
27
27
 
28
- # Fichier écrit par kind : --kubeconfig s'il est donné, sinon le premier de
29
- # KUBECONFIG, sinon ~/.kube/config (même règle que kind)
30
- fichier=""
31
- precedent=""
28
+ # File written by kind: --kubeconfig if given, otherwise the first of KUBECONFIG,
29
+ # otherwise ~/.kube/config (same rule as kind)
30
+ file=""
31
+ previous=""
32
32
  for arg in "$@"; do
33
33
  case "$arg" in
34
- --kubeconfig=*) fichier="${arg#--kubeconfig=}" ;;
34
+ --kubeconfig=*) file="${arg#--kubeconfig=}" ;;
35
35
  esac
36
- [ "$precedent" = "--kubeconfig" ] && fichier="$arg"
37
- precedent="$arg"
36
+ [ "$previous" = "--kubeconfig" ] && file="$arg"
37
+ previous="$arg"
38
38
  done
39
- if [ -z "$fichier" ] && [ -n "${KUBECONFIG:-}" ]; then
40
- fichier="${KUBECONFIG%%:*}"
39
+ if [ -z "$file" ] && [ -n "${KUBECONFIG:-}" ]; then
40
+ file="${KUBECONFIG%%:*}"
41
41
  fi
42
- [ -n "$fichier" ] || fichier="$HOME/.kube/config"
42
+ [ -n "$file" ] || file="$HOME/.kube/config"
43
43
 
44
- kube_joignable_depuis_conteneur "$fichier"
44
+ kube_reachable_from_container "$file"
45
45
  exit 0
@@ -1,44 +1,43 @@
1
1
  #!/usr/bin/env bash
2
- # Compte Kubernetes limité (#430) : le contexte devzone (projets, relais,
3
- # agents) ne peut agir que dans les namespaces devzone-*. Le compte est le
4
- # ServiceAccount devzone-agent du namespace devzone-system, lié au ClusterRole
5
- # edit (ni RBAC ni quotas) dans chaque namespace de devzone par un RoleBinding,
6
- # avec un jeton TokenRequest de 24 h renouvelé au démarrage (startup.sh) et
7
- # par « devzone repair ». Les installeurs utilisent seuls le contexte
8
- # administrateur (contexte de l hôte dans ~/.kube/hote.config, cluster kind
9
- # dans ~/.kube/config) ; les shells et les agents n'ont que ~/.kube/config.
10
- # Bibliothèque sourcée par cluster.sh ; exécutable pour le jeton :
11
- # kube-account.sh jeton
2
+ # Limited Kubernetes account (#430): the devzone context (projects, relays,
3
+ # agents) can only act in the devzone-* namespaces. The account is the
4
+ # ServiceAccount devzone-agent of the devzone-system namespace, bound to the
5
+ # edit ClusterRole (no RBAC, no quotas) in each devzone namespace by a
6
+ # RoleBinding, with a 24 h TokenRequest token renewed at startup (startup.sh) and
7
+ # by « devzone repair ». The installers alone use the admin context (host context
8
+ # in ~/.kube/hote.config, kind cluster in ~/.kube/config); shells and agents only
9
+ # have ~/.kube/config.
10
+ # Library sourced by cluster.sh; executable for the token:
11
+ # kube-account.sh jeton (argument kept: called by startup.sh and devzone repair)
12
12
 
13
- COMPTES_NS=devzone-system
14
- COMPTES_SA=devzone-agent
15
- COMPTES_DUREE=24h
16
- COMPTES_CONFIG="${DEVZONE_KUBE_CONFIG:-$HOME/.kube/config}"
13
+ ACCOUNT_NS=devzone-system
14
+ ACCOUNT_SA=devzone-agent
15
+ ACCOUNT_DURATION=24h
16
+ ACCOUNT_CONFIG="${DEVZONE_KUBE_CONFIG:-$HOME/.kube/config}"
17
17
 
18
- # Fichier kubeconfig qui porte le contexte administrateur ctx : hote.config
19
- # s'il y figure (clusters de l'hôte), sinon ~/.kube/config (clusters kind du
20
- # conteneur).
21
- compte_config_admin() {
22
- local ctx="$1" hote="${DEVZONE_KUBE_HOTE:-$HOME/.kube/hote.config}"
23
- if [ -n "$ctx" ] && [ -f "$hote" ]; then
24
- if KUBECONFIG="$hote" kubectl config get-contexts -o name 2>/dev/null | grep -qx -- "$ctx"; then
25
- echo "$hote"
18
+ # kubeconfig file that holds the admin context ctx: hote.config if it lists it
19
+ # (host clusters), otherwise ~/.kube/config (kind clusters of the container).
20
+ account_admin_config() {
21
+ local ctx="$1" host="${DEVZONE_KUBE_HOST:-$HOME/.kube/hote.config}"
22
+ if [ -n "$ctx" ] && [ -f "$host" ]; then
23
+ if KUBECONFIG="$host" kubectl config get-contexts -o name 2>/dev/null | grep -qx -- "$ctx"; then
24
+ echo "$host"
26
25
  return 0
27
26
  fi
28
27
  fi
29
- echo "$COMPTES_CONFIG"
28
+ echo "$ACCOUNT_CONFIG"
30
29
  }
31
30
 
32
- # kubectl sur le contexte administrateur : kubeconfig explicite qui porte ce
33
- # contexte, jamais le KUBECONFIG combiné (l'administrateur ne passe jamais par
34
- # le compte limité). Sans contexte connu : celui de kubectl.
35
- compte_admin() {
31
+ # kubectl on the admin context: explicit kubeconfig that holds this context,
32
+ # never the combined KUBECONFIG (the admin never goes through the limited
33
+ # account). Without a known context: the one kubectl uses.
34
+ account_admin() {
36
35
  local ctx="$1" conf
37
36
  shift
38
37
  if [ -z "$ctx" ]; then
39
38
  ctx="$(kubectl config current-context 2>/dev/null || true)"
40
39
  fi
41
- conf="$(compte_config_admin "$ctx")"
40
+ conf="$(account_admin_config "$ctx")"
42
41
  if [ -n "$ctx" ]; then
43
42
  kubectl --kubeconfig="$conf" --context "$ctx" "$@"
44
43
  else
@@ -46,16 +45,16 @@ compte_admin() {
46
45
  fi
47
46
  }
48
47
 
49
- # helm sur le contexte administrateur ctx : les charts créent des CRD, des
50
- # ClusterRoles ou des RoleBindings, hors des droits du compte limité (edit).
51
- # Usage : compte_helm <ctx> <args helm…>
52
- compte_helm() {
48
+ # helm on the admin context ctx: the charts create CRDs, ClusterRoles or
49
+ # RoleBindings, beyond the limited account's rights (edit).
50
+ # Usage: account_helm <ctx> <helm args…>
51
+ account_helm() {
53
52
  local ctx="$1" conf
54
53
  shift
55
54
  if [ -z "$ctx" ]; then
56
55
  ctx="$(kubectl config current-context 2>/dev/null || true)"
57
56
  fi
58
- conf="$(compte_config_admin "$ctx")"
57
+ conf="$(account_admin_config "$ctx")"
59
58
  if [ -n "$ctx" ]; then
60
59
  helm --kubeconfig "$conf" --kube-context "$ctx" "$@"
61
60
  else
@@ -63,11 +62,11 @@ compte_helm() {
63
62
  fi
64
63
  }
65
64
 
66
- # Contexte administrateur d'une installation : le cluster des services choisi
67
- # (cluster_lu de cluster.sh), sinon le contexte courant de kubectl.
68
- compte_ctx() {
65
+ # Admin context of an installation: the chosen services cluster (cluster_saved
66
+ # of cluster.sh), otherwise the current kubectl context.
67
+ account_context() {
69
68
  local ctx
70
- ctx="$(cluster_lu 2>/dev/null || true)"
69
+ ctx="$(cluster_saved 2>/dev/null || true)"
71
70
  if [ -n "$ctx" ]; then
72
71
  echo "$ctx"
73
72
  return 0
@@ -75,126 +74,126 @@ compte_ctx() {
75
74
  kubectl config current-context 2>/dev/null || true
76
75
  }
77
76
 
78
- # Pose le compte limité avec le contexte administrateur : namespace
79
- # devzone-system et ServiceAccount devzone-agent (idempotent, repris au
80
- # démarrage et à chaque installation).
81
- compte_poser() {
77
+ # Sets up the limited account with the admin context: devzone-system namespace
78
+ # and devzone-agent ServiceAccount (idempotent, resumed at startup and at each
79
+ # installation).
80
+ account_setup() {
82
81
  local ctx="$1"
83
- compte_admin "$ctx" create namespace "$COMPTES_NS" --dry-run=client -o yaml |
84
- compte_admin "$ctx" apply -f - >/dev/null || return 1
85
- compte_admin "$ctx" -n "$COMPTES_NS" create serviceaccount "$COMPTES_SA" \
86
- --dry-run=client -o yaml | compte_admin "$ctx" apply -f - >/dev/null || return 1
82
+ account_admin "$ctx" create namespace "$ACCOUNT_NS" --dry-run=client -o yaml |
83
+ account_admin "$ctx" apply -f - >/dev/null || return 1
84
+ account_admin "$ctx" -n "$ACCOUNT_NS" create serviceaccount "$ACCOUNT_SA" \
85
+ --dry-run=client -o yaml | account_admin "$ctx" apply -f - >/dev/null || return 1
87
86
  }
88
87
 
89
- # Autorise le compte dans le namespace ns : RoleBinding devzone-agent vers le
90
- # ClusterRole edit (lecture, écriture, secrets, NetworkPolicies — ni RBAC ni
91
- # quotas), posé avec le contexte administrateur après la création du namespace.
92
- # Le compte est posé d'abord s'il manque : une installation sur un cluster
93
- # encore vierge rend le compte utilisable au prochain renouvellement de jeton.
94
- compte_autoriser() {
88
+ # Allows the account in namespace ns: devzone-agent RoleBinding to the edit
89
+ # ClusterRole (read, write, secrets, NetworkPolicies — no RBAC, no quotas), set
90
+ # with the admin context after the namespace is created.
91
+ # The account is set up first if missing: an installation on a still blank
92
+ # cluster makes the account usable at the next token renewal.
93
+ account_allow() {
95
94
  local ctx="$1" ns="$2"
96
- compte_poser "$ctx" || return 1
97
- compte_admin "$ctx" -n "$ns" create rolebinding "$COMPTES_SA" \
98
- --clusterrole=edit --serviceaccount="$COMPTES_NS:$COMPTES_SA" \
99
- --dry-run=client -o yaml | compte_admin "$ctx" apply -f - >/dev/null || return 1
95
+ account_setup "$ctx" || return 1
96
+ account_admin "$ctx" -n "$ns" create rolebinding "$ACCOUNT_SA" \
97
+ --clusterrole=edit --serviceaccount="$ACCOUNT_NS:$ACCOUNT_SA" \
98
+ --dry-run=client -o yaml | account_admin "$ctx" apply -f - >/dev/null || return 1
100
99
  }
101
100
 
102
- # Retire l'autorisation du compte dans le namespace ns (désinstallation) :
103
- # RoleBinding supprimé avec le contexte administrateur.
104
- compte_retirer() {
101
+ # Removes the account's permission in namespace ns (uninstall): RoleBinding
102
+ # deleted with the admin context.
103
+ account_remove() {
105
104
  local ctx="$1" ns="$2"
106
- compte_admin "$ctx" -n "$ns" delete rolebinding "$COMPTES_SA" \
105
+ account_admin "$ctx" -n "$ns" delete rolebinding "$ACCOUNT_SA" \
107
106
  --ignore-not-found >/dev/null || return 1
108
107
  }
109
108
 
110
- # Crée et étiquette le namespace ns par l'administrateur puis autorise le compte.
111
- compte_namespace() {
109
+ # Creates and labels namespace ns as administrator, then allows the account.
110
+ account_namespace() {
112
111
  local ctx="$1" ns="$2"
113
- compte_admin "$ctx" create namespace "$ns" --dry-run=client -o yaml |
114
- compte_admin "$ctx" apply -f - >/dev/null || return 1
115
- compte_admin "$ctx" label namespace "$ns" "$CLUSTER_ETIQUETTE" --overwrite >/dev/null || return 1
116
- compte_autoriser "$ctx" "$ns" || return 1
112
+ account_admin "$ctx" create namespace "$ns" --dry-run=client -o yaml |
113
+ account_admin "$ctx" apply -f - >/dev/null || return 1
114
+ account_admin "$ctx" label namespace "$ns" "$CLUSTER_LABEL" --overwrite >/dev/null || return 1
115
+ account_allow "$ctx" "$ns" || return 1
117
116
  }
118
117
 
119
- # Rattrape les namespaces devzone existants : RoleBinding posée dans chaque
120
- # namespace étiqueté CLUSTER_ETIQUETTE (idempotent), pour les installations
121
- # antérieures au compte limité.
122
- compte_rattraper() {
123
- local ctx="$1" ns etiquette="${CLUSTER_ETIQUETTE:-app.kubernetes.io/managed-by=devzone}"
118
+ # Catches up the existing devzone namespaces: RoleBinding set in each namespace
119
+ # labelled CLUSTER_LABEL (idempotent), for the installations prior to the
120
+ # limited account.
121
+ account_catch_up() {
122
+ local ctx="$1" ns label="${CLUSTER_LABEL:-app.kubernetes.io/managed-by=devzone}"
124
123
  while IFS= read -r ns; do
125
124
  [ -n "$ns" ] || continue
126
125
  ns="${ns#namespace/}"
127
- compte_admin "$ctx" -n "$ns" create rolebinding "$COMPTES_SA" \
128
- --clusterrole=edit --serviceaccount="$COMPTES_NS:$COMPTES_SA" \
129
- --dry-run=client -o yaml | compte_admin "$ctx" apply -f - >/dev/null || return 1
130
- done < <(compte_admin "$ctx" get namespaces -l "$etiquette" -o name 2>/dev/null || true)
126
+ account_admin "$ctx" -n "$ns" create rolebinding "$ACCOUNT_SA" \
127
+ --clusterrole=edit --serviceaccount="$ACCOUNT_NS:$ACCOUNT_SA" \
128
+ --dry-run=client -o yaml | account_admin "$ctx" apply -f - >/dev/null || return 1
129
+ done < <(account_admin "$ctx" get namespaces -l "$label" -o name 2>/dev/null || true)
131
130
  }
132
131
 
133
- # Renouvelle le jeton du compte (TokenRequest de 24 h) et l'écrit dans le
134
- # contexte devzone de ~/.kube/config : user devzone-agent, même cluster que le
135
- # contexte administrateur (entrée cluster copiée : server, autorité de
136
- # certificat et tls-server-name du contexte de l'hôte).
137
- compte_jeton() {
138
- local ctx="$1" conf jeton cluster serveur tls ca_donnees ca_fichier
139
- local entree=()
140
- conf="$(compte_config_admin "$ctx")"
141
- jeton="$(compte_admin "$ctx" create token "$COMPTES_SA" -n "$COMPTES_NS" \
142
- --duration="$COMPTES_DUREE")" || return 1
143
- if [ -z "$jeton" ]; then
144
- echo "devzone : jeton du compte limité vide" >&2
132
+ # Renews the account's token (24 h TokenRequest) and writes it into the devzone
133
+ # context of ~/.kube/config: user devzone-agent, same cluster as the admin
134
+ # context (cluster entry copied: server, certificate authority and
135
+ # tls-server-name of the host context).
136
+ account_token() {
137
+ local ctx="$1" conf token cluster server tls ca_data ca_file
138
+ local entry=()
139
+ conf="$(account_admin_config "$ctx")"
140
+ token="$(account_admin "$ctx" create token "$ACCOUNT_SA" -n "$ACCOUNT_NS" \
141
+ --duration="$ACCOUNT_DURATION")" || return 1
142
+ if [ -z "$token" ]; then
143
+ echo "devzone : limited account token is empty" >&2
145
144
  return 1
146
145
  fi
147
146
  cluster="$(KUBECONFIG="$conf" kubectl config view \
148
147
  -o jsonpath="{.contexts[?(@.name==\"$ctx\")].context.cluster}" 2>/dev/null || true)"
149
148
  if [ -z "$cluster" ]; then
150
- echo "devzone : cluster du contexte $ctx introuvable dans $conf" >&2
149
+ echo "devzone : cluster of context $ctx not found in $conf" >&2
151
150
  return 1
152
151
  fi
153
- serveur="$(KUBECONFIG="$conf" kubectl config view \
152
+ server="$(KUBECONFIG="$conf" kubectl config view \
154
153
  -o jsonpath="{.clusters[?(@.name==\"$cluster\")].cluster.server}" 2>/dev/null || true)"
155
- if [ -z "$serveur" ]; then
156
- echo "devzone : serveur du cluster $cluster introuvable dans $conf" >&2
154
+ if [ -z "$server" ]; then
155
+ echo "devzone : server of cluster $cluster not found in $conf" >&2
157
156
  return 1
158
157
  fi
159
- ca_donnees="$(KUBECONFIG="$conf" kubectl config view \
158
+ ca_data="$(KUBECONFIG="$conf" kubectl config view \
160
159
  -o jsonpath="{.clusters[?(@.name==\"$cluster\")].cluster.certificate-authority-data}" 2>/dev/null || true)"
161
- ca_fichier="$(KUBECONFIG="$conf" kubectl config view \
160
+ ca_file="$(KUBECONFIG="$conf" kubectl config view \
162
161
  -o jsonpath="{.clusters[?(@.name==\"$cluster\")].cluster.certificate-authority}" 2>/dev/null || true)"
163
- entree=(--server="$serveur")
164
- if [ -n "$ca_donnees" ]; then
165
- entree+=(--certificate-authority-data="$ca_donnees")
166
- elif [ -n "$ca_fichier" ]; then
167
- entree+=(--certificate-authority="$ca_fichier" --embed-certs=true)
162
+ entry=(--server="$server")
163
+ if [ -n "$ca_data" ]; then
164
+ entry+=(--certificate-authority-data="$ca_data")
165
+ elif [ -n "$ca_file" ]; then
166
+ entry+=(--certificate-authority="$ca_file" --embed-certs=true)
168
167
  fi
169
168
  tls="$(KUBECONFIG="$conf" kubectl config view \
170
169
  -o jsonpath="{.clusters[?(@.name==\"$cluster\")].cluster.tls-server-name}" 2>/dev/null || true)"
171
170
  if [ -n "$tls" ]; then
172
- entree+=(--tls-server-name="$tls")
171
+ entry+=(--tls-server-name="$tls")
173
172
  fi
174
- KUBECONFIG="$COMPTES_CONFIG" kubectl config set-cluster "$cluster" \
175
- ${entree[@]+"${entree[@]}"} >/dev/null
176
- KUBECONFIG="$COMPTES_CONFIG" kubectl config set-credentials "$COMPTES_SA" \
177
- --token="$jeton" >/dev/null
178
- KUBECONFIG="$COMPTES_CONFIG" kubectl config set-context devzone \
179
- --cluster="$cluster" --user="$COMPTES_SA" >/dev/null
173
+ KUBECONFIG="$ACCOUNT_CONFIG" kubectl config set-cluster "$cluster" \
174
+ ${entry[@]+"${entry[@]}"} >/dev/null
175
+ KUBECONFIG="$ACCOUNT_CONFIG" kubectl config set-credentials "$ACCOUNT_SA" \
176
+ --token="$token" >/dev/null
177
+ KUBECONFIG="$ACCOUNT_CONFIG" kubectl config set-context devzone \
178
+ --cluster="$cluster" --user="$ACCOUNT_SA" >/dev/null
180
179
  }
181
180
 
182
- # Exécution directe : jeton du compte renouvelé au démarrage (startup.sh) et
183
- # par « devzone repair ». Sans cluster des services choisi : rien à faire.
184
- # Quand le fichier est sourcé, $0 diffère de BASH_SOURCE : rien ne s'exécute.
181
+ # Direct execution: account token renewed at startup (startup.sh) and by
182
+ # « devzone repair ». Without a chosen services cluster: nothing to do.
183
+ # When the file is sourced, $0 differs from BASH_SOURCE: nothing runs.
185
184
  if [[ "${BASH_SOURCE[0]}" == "$0" ]]; then
186
185
  if [ "${1:-}" != jeton ]; then
187
- echo "devzone : kube-compte : jeton" >&2
186
+ echo "devzone : kube-account : jeton" >&2
188
187
  exit 1
189
188
  fi
190
189
  ICI="$(cd "$(dirname "$0")" && pwd)"
191
- RACINE="${DEVZONE_RACINE:-$(dirname "$ICI")}"
192
- ETAT="${DEVZONE_ETAT:-$RACINE/.devzone.modules}"
190
+ RACINE="${DEVZONE_ROOT:-$(dirname "$ICI")}"
191
+ ETAT="${DEVZONE_STATE:-$RACINE/.devzone.modules}"
193
192
  ctx="$(grep -E '^cluster=' "$ETAT" 2>/dev/null | tail -1 | cut -d= -f2- || true)"
194
193
  if [ -z "$ctx" ]; then
195
194
  exit 0
196
195
  fi
197
- compte_poser "$ctx" || exit 1
198
- compte_rattraper "$ctx" || exit 1
199
- compte_jeton "$ctx" || exit 1
196
+ account_setup "$ctx" || exit 1
197
+ account_catch_up "$ctx" || exit 1
198
+ account_token "$ctx" || exit 1
200
199
  fi
@@ -1,14 +1,14 @@
1
1
  #!/usr/bin/env bash
2
- # Clusters Kubernetes du conteneur, à chaque démarrage (le port du cluster de
3
- # l'hôte peut changer) :
4
- # - ~/.kube/hote.config : copie du ~/.kube de l'hôte (monté en lecture seule) où
5
- # 127.0.0.1/localhost deviennent host.docker.internal, l'hôte vu du conteneur ;
6
- # tls-server-name garde le nom attendu par le certificat
7
- # - ~/.kube/config : clusters kind du conteneur, jamais touché ici
8
- # KUBECONFIG (devcontainer.json) combine les deux.
9
- # Module kubernetes (devzone enable kubernetes) : connexion au cluster de
10
- # l'hôte et metrics-server seulement s'il est actif ; les contextes kind sont
11
- # toujours remis (un cluster créé à la main reste utilisable).
2
+ # Kubernetes clusters of the container, at each startup (the port of the host
3
+ # cluster can change):
4
+ # - ~/.kube/hote.config: copy of the host's ~/.kube (mounted read-only) where
5
+ # 127.0.0.1/localhost become host.docker.internal, the host seen from the container;
6
+ # tls-server-name keeps the name expected by the certificate
7
+ # - ~/.kube/config: kind clusters of the container, never touched here
8
+ # KUBECONFIG (devcontainer.json) combines the two.
9
+ # kubernetes module (devzone enable kubernetes): connection to the host cluster
10
+ # and metrics-server only if it is enabled; the kind contexts are always restored
11
+ # (a cluster created by hand stays usable).
12
12
  set -euo pipefail
13
13
 
14
14
  ICI="$(dirname "$0")"
@@ -17,63 +17,62 @@ ICI="$(dirname "$0")"
17
17
  module=off
18
18
  bash "$ICI/devzone" is-enabled kubernetes && module=on
19
19
 
20
- # DEVZONE_KUBE_SOURCE : tests fonctionnels (jamais le cluster de l'hôte)
20
+ # DEVZONE_KUBE_SOURCE: functional tests (never the host cluster)
21
21
  SOURCE="${DEVZONE_KUBE_SOURCE:-$HOME/.kube-host/config}"
22
- HOTE="$HOME/.kube/hote.config"
22
+ HOST_CONFIG="$HOME/.kube/hote.config"
23
23
 
24
24
  mkdir -p "$HOME/.kube"
25
- rm -f "$HOTE"
26
- # Doit exister : sinon kind écrit dans hote.config, effacé au prochain démarrage
25
+ rm -f "$HOST_CONFIG"
26
+ # Must exist: otherwise kind writes into hote.config, erased at the next startup
27
27
  [ -f "$HOME/.kube/config" ] || install -m 600 /dev/null "$HOME/.kube/config"
28
28
 
29
29
  if [ "$module" = on ] && [ -f "$SOURCE" ]; then
30
- install -m 600 "$SOURCE" "$HOTE"
31
- kube_joignable_depuis_conteneur "$HOTE"
32
- contexte_devzone_poser
30
+ install -m 600 "$SOURCE" "$HOST_CONFIG"
31
+ kube_reachable_from_container "$HOST_CONFIG"
32
+ devzone_context_set
33
33
  fi
34
34
 
35
- # Réécriture de 127.0.0.1/localhost → host.docker.internal pour les clusters
36
- # kind, dont l'API server est à 127.0.0.1:<port> mais injoignable depuis le
37
- # conteneur. Idempotent.
38
- kube_joignable_depuis_conteneur "$HOME/.kube/config"
35
+ # Rewrite 127.0.0.1/localhost → host.docker.internal for the kind clusters, whose
36
+ # API server is at 127.0.0.1:<port> but unreachable from the container. Idempotent.
37
+ kube_reachable_from_container "$HOME/.kube/config"
39
38
 
40
- # Clusters kind qui ont survécu au redémarrage : contexte remis dans ~/.kube/config
41
- # (le Docker interne peut mettre quelques secondes à démarrer)
39
+ # kind clusters that survived the restart: context restored in ~/.kube/config
40
+ # (the internal Docker may take a few seconds to start)
42
41
  for _ in 1 2 3 4 5 6 7 8 9 10; do docker info >/dev/null 2>&1 && break; sleep 1; done
43
- choix="$(KUBECONFIG="$HOME/.kube/config" kubectl config current-context 2>/dev/null || true)"
42
+ choice="$(KUBECONFIG="$HOME/.kube/config" kubectl config current-context 2>/dev/null || true)"
44
43
  for cluster in $(kind get clusters 2>/dev/null); do
45
44
  kind export kubeconfig --name "$cluster" --kubeconfig "$HOME/.kube/config" >/dev/null 2>&1 || true
46
45
  done
47
- # Les kubeconfigs exportés par kind portent server: https://127.0.0.1:<port> ;
48
- # les rendre joignables depuis le conteneur.
49
- kube_joignable_depuis_conteneur "$HOME/.kube/config"
46
+ # The kubeconfigs exported by kind carry server: https://127.0.0.1:<port>;
47
+ # make them reachable from the container.
48
+ kube_reachable_from_container "$HOME/.kube/config"
50
49
 
51
- # Cluster actif : celui choisi avant (kubectl config use-context), sinon celui
52
- # de l'hôte s'il en a un (current-context de hote.config), sinon kind
53
- export KUBECONFIG="$HOME/.kube/config:$HOTE"
54
- if [ -n "$choix" ] && kubectl config use-context "$choix" >/dev/null 2>&1; then
50
+ # Active cluster: the one chosen before (kubectl config use-context), otherwise
51
+ # the host's if it has one (current-context of hote.config), otherwise kind
52
+ export KUBECONFIG="$HOME/.kube/config:$HOST_CONFIG"
53
+ if [ -n "$choice" ] && kubectl config use-context "$choice" >/dev/null 2>&1; then
55
54
  :
56
- elif [ -f "$HOTE" ] && [ -n "$(KUBECONFIG="$HOTE" kubectl config current-context 2>/dev/null)" ]; then
55
+ elif [ -f "$HOST_CONFIG" ] && [ -n "$(KUBECONFIG="$HOST_CONFIG" kubectl config current-context 2>/dev/null)" ]; then
57
56
  KUBECONFIG="$HOME/.kube/config" kubectl config unset current-context >/dev/null
58
57
  fi
59
58
 
60
- # Clusters joignables, parmi ceux de l'hôte et ceux de kind
61
- joignables=0
62
- for contexte in $(kubectl config get-contexts -o name 2>/dev/null); do
63
- if kubectl --context "$contexte" --request-timeout=3s get --raw /readyz >/dev/null 2>&1; then
64
- echo "kube-config : cluster joignable : $contexte"
65
- joignables=$((joignables + 1))
66
- elif [[ "$contexte" == kind-* ]]; then
67
- echo "kube-config : cluster kind en cours de démarrage : $contexte"
68
- joignables=$((joignables + 1))
59
+ # Reachable clusters, among those of the host and those of kind
60
+ reachable=0
61
+ for context in $(kubectl config get-contexts -o name 2>/dev/null); do
62
+ if kubectl --context "$context" --request-timeout=3s get --raw /readyz >/dev/null 2>&1; then
63
+ echo "kube-config : cluster reachable : $context"
64
+ reachable=$((reachable + 1))
65
+ elif [[ "$context" == kind-* ]]; then
66
+ echo "kube-config : kind cluster starting: $context"
67
+ reachable=$((reachable + 1))
69
68
  fi
70
69
  done
71
- # Module désactivé : le récapitulatif de devzone le signale
70
+ # Module disabled: the devzone summary reports it
72
71
  [ "$module" = on ] || exit 0
73
- echo "kube-config : cluster actif : $(kubectl config current-context 2>/dev/null || echo aucun)"
74
- if [ "$joignables" -eq 0 ]; then
75
- echo "kube-config : aucun cluster joignable ; en créer un dans le conteneur : kind create cluster"
72
+ echo "kube-config : active cluster: $(kubectl config current-context 2>/dev/null || echo none)"
73
+ if [ "$reachable" -eq 0 ]; then
74
+ echo "kube-config : no reachable cluster; create one in the container: kind create cluster"
76
75
  fi
77
76
 
78
- # CPU/RAM dans k9s : metrics-server sur les clusters joignables qui ne l'ont pas
77
+ # CPU/RAM in k9s: metrics-server on the reachable clusters that do not have it
79
78
  bash "$ICI/metrics-server.sh" || true