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
@@ -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
@@ -0,0 +1,65 @@
1
+ #!/usr/bin/env bash
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
+
7
+ # Sets an isolating NetworkPolicy in a namespace.
8
+ # Only the pods of the same namespace can reach the services.
9
+ namespace_isolate() {
10
+ local ns="${1:-}"
11
+ [ -n "$ns" ] || { echo "devzone : namespace missing" >&2; return 2; }
12
+
13
+ kubectl --context devzone -n "$ns" apply -f - <<EOF
14
+ apiVersion: networking.k8s.io/v1
15
+ kind: NetworkPolicy
16
+ metadata:
17
+ name: devzone-meme-namespace
18
+ labels:
19
+ app.kubernetes.io/managed-by: devzone
20
+ spec:
21
+ podSelector: {}
22
+ ingress:
23
+ - from:
24
+ - podSelector: {}
25
+ EOF
26
+ }
27
+
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
+
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
+
40
+ patch="$(jq -nc '{"spec":{"ingress":[{"from":[{"podSelector":{},
41
+ "namespaceSelector":{"matchLabels":{"app.kubernetes.io/managed-by":"devzone"}}}]}]}}')"
42
+ if ! output="$(kubectl --context devzone -n "$target_ns" patch networkpolicy devzone-meme-namespace \
43
+ -p "$patch" 2>&1)"; then
44
+ echo "devzone : cannot allow access to $target_ns : $output" >&2
45
+ return 1
46
+ fi
47
+
48
+ echo "devzone : rule allowed to $target_ns"
49
+ }
50
+
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
+
57
+ patch="$(jq -nc '{"spec":{"ingress":[{"from":[{"podSelector":{}}]}]}}')"
58
+ if ! output="$(kubectl --context devzone -n "$target_ns" patch networkpolicy devzone-meme-namespace \
59
+ -p "$patch" 2>&1)"; then
60
+ echo "devzone : cannot forbid access to $target_ns : $output" >&2
61
+ return 1
62
+ fi
63
+
64
+ echo "devzone : rule forbidden to $target_ns"
65
+ }
@@ -0,0 +1,45 @@
1
+ #!/usr/bin/env bash
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
+ set -uo pipefail
8
+
9
+ KIND_REEL="${DEVZONE_KIND_REAL:-/usr/local/bin/kind-reel}"
10
+ ICI="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
11
+ if [ -f "$ICI/kube-reachable.sh" ]; then
12
+ # shellcheck source=SCRIPTDIR/kube-reachable.sh
13
+ . "$ICI/kube-reachable.sh"
14
+ else
15
+ # shellcheck source=/dev/null
16
+ . /usr/local/lib/devzone/kube-reachable.sh
17
+ fi
18
+
19
+ "$KIND_REEL" "$@"
20
+ code=$?
21
+ [ "$code" -eq 0 ] || exit "$code"
22
+
23
+ case "${1:-} ${2:-}" in
24
+ "create cluster" | "export kubeconfig") ;;
25
+ *) exit 0 ;;
26
+ esac
27
+
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
+ for arg in "$@"; do
33
+ case "$arg" in
34
+ --kubeconfig=*) file="${arg#--kubeconfig=}" ;;
35
+ esac
36
+ [ "$previous" = "--kubeconfig" ] && file="$arg"
37
+ previous="$arg"
38
+ done
39
+ if [ -z "$file" ] && [ -n "${KUBECONFIG:-}" ]; then
40
+ file="${KUBECONFIG%%:*}"
41
+ fi
42
+ [ -n "$file" ] || file="$HOME/.kube/config"
43
+
44
+ kube_reachable_from_container "$file"
45
+ exit 0
@@ -0,0 +1,199 @@
1
+ #!/usr/bin/env bash
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
+
13
+ ACCOUNT_NS=devzone-system
14
+ ACCOUNT_SA=devzone-agent
15
+ ACCOUNT_DURATION=24h
16
+ ACCOUNT_CONFIG="${DEVZONE_KUBE_CONFIG:-$HOME/.kube/config}"
17
+
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"
25
+ return 0
26
+ fi
27
+ fi
28
+ echo "$ACCOUNT_CONFIG"
29
+ }
30
+
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() {
35
+ local ctx="$1" conf
36
+ shift
37
+ if [ -z "$ctx" ]; then
38
+ ctx="$(kubectl config current-context 2>/dev/null || true)"
39
+ fi
40
+ conf="$(account_admin_config "$ctx")"
41
+ if [ -n "$ctx" ]; then
42
+ kubectl --kubeconfig="$conf" --context "$ctx" "$@"
43
+ else
44
+ kubectl --kubeconfig="$conf" "$@"
45
+ fi
46
+ }
47
+
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() {
52
+ local ctx="$1" conf
53
+ shift
54
+ if [ -z "$ctx" ]; then
55
+ ctx="$(kubectl config current-context 2>/dev/null || true)"
56
+ fi
57
+ conf="$(account_admin_config "$ctx")"
58
+ if [ -n "$ctx" ]; then
59
+ helm --kubeconfig "$conf" --kube-context "$ctx" "$@"
60
+ else
61
+ helm --kubeconfig "$conf" "$@"
62
+ fi
63
+ }
64
+
65
+ # Admin context of an installation: the chosen services cluster (cluster_saved
66
+ # of cluster.sh), otherwise the current kubectl context.
67
+ account_context() {
68
+ local ctx
69
+ ctx="$(cluster_saved 2>/dev/null || true)"
70
+ if [ -n "$ctx" ]; then
71
+ echo "$ctx"
72
+ return 0
73
+ fi
74
+ kubectl config current-context 2>/dev/null || true
75
+ }
76
+
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() {
81
+ local ctx="$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
86
+ }
87
+
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() {
94
+ local ctx="$1" ns="$2"
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
99
+ }
100
+
101
+ # Removes the account's permission in namespace ns (uninstall): RoleBinding
102
+ # deleted with the admin context.
103
+ account_remove() {
104
+ local ctx="$1" ns="$2"
105
+ account_admin "$ctx" -n "$ns" delete rolebinding "$ACCOUNT_SA" \
106
+ --ignore-not-found >/dev/null || return 1
107
+ }
108
+
109
+ # Creates and labels namespace ns as administrator, then allows the account.
110
+ account_namespace() {
111
+ local ctx="$1" ns="$2"
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
116
+ }
117
+
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}"
123
+ while IFS= read -r ns; do
124
+ [ -n "$ns" ] || continue
125
+ ns="${ns#namespace/}"
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)
130
+ }
131
+
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
144
+ return 1
145
+ fi
146
+ cluster="$(KUBECONFIG="$conf" kubectl config view \
147
+ -o jsonpath="{.contexts[?(@.name==\"$ctx\")].context.cluster}" 2>/dev/null || true)"
148
+ if [ -z "$cluster" ]; then
149
+ echo "devzone : cluster of context $ctx not found in $conf" >&2
150
+ return 1
151
+ fi
152
+ server="$(KUBECONFIG="$conf" kubectl config view \
153
+ -o jsonpath="{.clusters[?(@.name==\"$cluster\")].cluster.server}" 2>/dev/null || true)"
154
+ if [ -z "$server" ]; then
155
+ echo "devzone : server of cluster $cluster not found in $conf" >&2
156
+ return 1
157
+ fi
158
+ ca_data="$(KUBECONFIG="$conf" kubectl config view \
159
+ -o jsonpath="{.clusters[?(@.name==\"$cluster\")].cluster.certificate-authority-data}" 2>/dev/null || true)"
160
+ ca_file="$(KUBECONFIG="$conf" kubectl config view \
161
+ -o jsonpath="{.clusters[?(@.name==\"$cluster\")].cluster.certificate-authority}" 2>/dev/null || 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)
167
+ fi
168
+ tls="$(KUBECONFIG="$conf" kubectl config view \
169
+ -o jsonpath="{.clusters[?(@.name==\"$cluster\")].cluster.tls-server-name}" 2>/dev/null || true)"
170
+ if [ -n "$tls" ]; then
171
+ entry+=(--tls-server-name="$tls")
172
+ fi
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
179
+ }
180
+
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.
184
+ if [[ "${BASH_SOURCE[0]}" == "$0" ]]; then
185
+ if [ "${1:-}" != jeton ]; then
186
+ echo "devzone : kube-account : jeton" >&2
187
+ exit 1
188
+ fi
189
+ ICI="$(cd "$(dirname "$0")" && pwd)"
190
+ RACINE="${DEVZONE_ROOT:-$(dirname "$ICI")}"
191
+ ETAT="${DEVZONE_STATE:-$RACINE/.devzone.modules}"
192
+ ctx="$(grep -E '^cluster=' "$ETAT" 2>/dev/null | tail -1 | cut -d= -f2- || true)"
193
+ if [ -z "$ctx" ]; then
194
+ exit 0
195
+ fi
196
+ account_setup "$ctx" || exit 1
197
+ account_catch_up "$ctx" || exit 1
198
+ account_token "$ctx" || exit 1
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
@@ -1,8 +1,8 @@
1
1
  #!/usr/bin/env bash
2
- # Invite Kubernetes du shell (#337) : ⎈ ctx/ns.
2
+ # Kubernetes prompt of the shell (#337): ⎈ ctx/ns.
3
3
 
4
- # Rend l invite Kubernetes (⎈ ctx/ns) avec cache par mtime.
5
- devzone_invite_kube() {
4
+ # Renders the Kubernetes prompt (⎈ ctx/ns), with a cache keyed on the mtime.
5
+ devzone_kube_prompt() {
6
6
  local kubeconfig="${KUBECONFIG:-$HOME/.kube/config:$HOME/.kube/hote.config}"
7
7
  local files=() f sig="" cache mtime ctx ns result ici
8
8
  ici="$(cd -P "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
@@ -16,7 +16,7 @@ devzone_invite_kube() {
16
16
  fi
17
17
  sig+="${f}:${mtime};"
18
18
  done
19
- cache="${XDG_CACHE_HOME:-$HOME/.cache}/devzone-invite-kube"
19
+ cache="${XDG_CACHE_HOME:-$HOME/.cache}/devzone-kube-prompt"
20
20
  mkdir -p "$(dirname "$cache")"
21
21
  if [ -f "$cache" ]; then
22
22
  if [ "$(sed -n '1p' "$cache" 2>/dev/null)" = "$sig" ]; then
@@ -31,10 +31,10 @@ devzone_invite_kube() {
31
31
  ns="$(kubectl config view -o jsonpath="{.contexts[?(@.name==\"$ctx\")].context.namespace}" 2>/dev/null || true)"
32
32
  [ -n "$ns" ] || ns=default
33
33
  # shellcheck disable=SC1090,SC1091
34
- if ( . "$ici/cluster.sh"; cluster_est_local "$ctx" ) >/dev/null 2>&1; then
34
+ if ( . "$ici/cluster.sh"; cluster_is_local "$ctx" ) >/dev/null 2>&1; then
35
35
  result="$(printf '\001\033[36m\002⎈ %s/%s\001\033[0m\002' "$ctx" "$ns")"
36
36
  else
37
- result="$(printf '\001\033[1;31m\002⎈ %s/%s distant\001\033[0m\002' "$ctx" "$ns")"
37
+ result="$(printf '\001\033[1;31m\002⎈ %s/%s remote\001\033[0m\002' "$ctx" "$ns")"
38
38
  fi
39
39
  fi
40
40
  printf '%s\n%s\n' "$sig" "$result" >"$cache"
@@ -0,0 +1,64 @@
1
+ #!/usr/bin/env bash
2
+ # Clusters reachable from the container (#291). With the host's Docker, the API
3
+ # of a kind cluster listens on 127.0.0.1 OF THE WORKSTATION: inside the
4
+ # container, 127.0.0.1 is the container itself.
5
+ # 1. kind node found (container publishing this port): the devzone container
6
+ # joins the Docker network of the node and targets https://<node>:6443, the
7
+ # address kind provides for containers (kind get kubeconfig --internal);
8
+ # the node name is in the API certificate. Works under Linux as with Docker
9
+ # Desktop, without exposing anything on the workstation's network.
10
+ # 2. Otherwise: https://host.docker.internal:<port>, with the original name for
11
+ # the TLS check (--tls-server-name); enough with Docker Desktop, where
12
+ # host.docker.internal leads to the workstation's 127.0.0.1.
13
+ # Sourced library (cluster.sh, kind wrapper); run directly:
14
+ # kube-reachable.sh FILE
15
+ # kube_reachable_from_container FILE rewrites 127.0.0.1/localhost, idempotent
16
+
17
+ # kind control-plane node that publishes this port on the workstation (empty otherwise)
18
+ kube_kind_node() {
19
+ docker ps --filter "label=io.x-k8s.kind.role=control-plane" --filter "publish=$1" \
20
+ --format '{{.Names}}' 2>/dev/null | head -1
21
+ }
22
+
23
+ # The devzone container joins the node's network (idempotent: already a member = nothing)
24
+ kube_join_network() {
25
+ local node="$1" me network
26
+ me="$(hostname)"
27
+ for network in $(docker inspect "$node" \
28
+ --format '{{range $name, $v := .NetworkSettings.Networks}}{{$name}} {{end}}' 2>/dev/null); do
29
+ docker network connect "$network" "$me" >/dev/null 2>&1 || true
30
+ done
31
+ }
32
+
33
+ kube_reachable_from_container() {
34
+ local file="${1:-}" name server host port node
35
+ [ -n "$file" ] || return 0
36
+ # Kubernetes workspace (#517): the pod reaches the API through the cluster service, no docker call
37
+ if [ "${DEVZONE_WORKSPACE:-}" = kubernetes ]; then return 0; fi
38
+ KUBECONFIG="$file" kubectl config view \
39
+ -o jsonpath='{range .clusters[*]}{.name}{"\t"}{.cluster.server}{"\n"}{end}' 2>/dev/null |
40
+ while IFS=$'\t' read -r name server; do
41
+ case "$server" in
42
+ https://127.0.0.1:* | https://localhost:*) ;;
43
+ *) continue ;;
44
+ esac
45
+ host="${server#https://}"
46
+ host="${host%%:*}"
47
+ port="${server##*:}"
48
+ node="$(kube_kind_node "$port")"
49
+ if [ -n "$node" ]; then
50
+ kube_join_network "$node"
51
+ KUBECONFIG="$file" kubectl config set-cluster "$name" \
52
+ --server="https://${node}:6443" >/dev/null 2>&1 || true
53
+ else
54
+ KUBECONFIG="$file" kubectl config set-cluster "$name" \
55
+ --server="https://host.docker.internal:${port}" \
56
+ --tls-server-name="$host" >/dev/null 2>&1 || true
57
+ fi
58
+ done
59
+ return 0
60
+ }
61
+
62
+ if [ "${BASH_SOURCE[0]}" = "$0" ]; then
63
+ kube_reachable_from_container "${1:-}"
64
+ fi
@@ -55,7 +55,7 @@ memory_cluster_ki() {
55
55
  local output line providerID memory node total=0 max=0 n=0 all_kind=1
56
56
  MEMORY_KI=""
57
57
  MEMORY_RULE=""
58
- output="$(compte_admin "$(compte_ctx)" get nodes \
58
+ output="$(account_admin "$(account_context)" get nodes \
59
59
  -o jsonpath='{range .items[*]}{.spec.providerID}{"|"}{.status.allocatable.memory}{"\n"}{end}' 2>/dev/null)" || return 1
60
60
  [ -n "$output" ] || return 1
61
61
  while IFS= read -r line; do
@@ -27,7 +27,7 @@ if [ "${1:-}" = retirer ]; then
27
27
  # Local clusters only: removal on a remote cluster has nothing to remove
28
28
  # (devzone never installs there)
29
29
  mapfile -t contexts < <(printf '%s\n' ${known[@]+"${known[@]}"} |
30
- while IFS= read -r c; do cluster_est_local "$c" && echo "$c"; done || true)
30
+ while IFS= read -r c; do cluster_is_local "$c" && echo "$c"; done || true)
31
31
  set -- ${contexts[@]+"${contexts[@]}"}
32
32
  fi
33
33
  code=0
@@ -56,7 +56,7 @@ if [ "$requested" -eq 0 ]; then
56
56
  # Local clusters only: never an automatic installation on a remote cluster
57
57
  # of the host (prod, staging…); for another one, name it as an argument
58
58
  mapfile -t contexts < <(printf '%s\n' ${known[@]+"${known[@]}"} |
59
- while IFS= read -r c; do cluster_est_local "$c" && echo "$c"; done || true)
59
+ while IFS= read -r c; do cluster_is_local "$c" && echo "$c"; done || true)
60
60
  set -- ${contexts[@]+"${contexts[@]}"}
61
61
  fi
62
62
 
@@ -1,8 +1,8 @@
1
- // devzone : configuration opencode par défaut (devzone enable ia la tient à jour ; retirer cette ligne pour la personnaliser)
1
+ // devzone : default opencode configuration (devzone enable ia keeps it up to date; remove this line to customise it)
2
2
  {
3
3
  "$schema": "https://opencode.ai/config.json",
4
4
  // Modèles gratuits de la version d'opencode fixée par devzone.
5
- // Partage et mises à jour désactivés : les versions sont fixées par devzone.
5
+ // Sharing and updates disabled: versions are pinned by devzone.
6
6
  "model": "opencode/big-pickle",
7
7
  "small_model": "opencode/mimo-v2.6-flash-free",
8
8
  "share": "disabled",