devzone 7.4.0 → 7.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.devcontainer/devzone +18 -63
- package/.devcontainer/devzone-modules.sh +8 -3
- package/.devcontainer/devzone-repair.sh +7 -7
- package/.devcontainer/devzone-services.sh +21 -21
- package/.devcontainer/devzone-status.sh +12 -9
- package/.devcontainer/help.sh +5 -1
- package/.devcontainer/versions.env +8 -0
- package/.devcontainer/workspace-init.sh +8 -9
- package/.gitattributes +8 -0
- package/README.md +2 -2
- package/bin/SHA256SUMS +6 -6
- package/bin/devzone-darwin-amd64 +0 -0
- package/bin/devzone-darwin-arm64 +0 -0
- package/bin/devzone-linux-amd64 +0 -0
- package/bin/devzone-linux-arm64 +0 -0
- package/bin/devzone-windows-amd64.exe +0 -0
- package/bin/devzone-windows-arm64.exe +0 -0
- package/charts/devzone-mysql/values.yaml +1 -1
- package/charts/devzone-postgres/values.yaml +1 -1
- package/manage/devzone +6 -3
- package/manage/scripts/create-mode.sh +3 -3
- package/manage/scripts/uninstall.sh +4 -5
- package/manage/scripts/workspace/argocd-workspace.sh +2 -2
- package/manage/workspace.sh +1 -1
- package/package.json +1 -1
- package/.devcontainer/ai/host-check.sh +0 -173
- package/.devcontainer/ai/host-models.sh +0 -200
- package/.devcontainer/catalog/app.sh +0 -202
- package/.devcontainer/catalog/catalog-watcher.sh +0 -127
- package/.devcontainer/catalog.sh +0 -208
- package/.devcontainer/chart-direct.sh +0 -49
- package/.devcontainer/cluster.sh +0 -388
- package/.devcontainer/clusters.sh +0 -86
- package/.devcontainer/devzone-ai-guard.sh +0 -98
- package/.devcontainer/devzone-ai.sh +0 -201
- package/.devcontainer/devzone-cluster.sh +0 -209
- package/.devcontainer/devzone-skill.sh +0 -97
- package/.devcontainer/isolation.sh +0 -65
- package/.devcontainer/kube-account.sh +0 -107
- package/.devcontainer/kube-prompt.sh +0 -42
- package/.devcontainer/memory.sh +0 -113
- package/.devcontainer/metrics-server.sh +0 -100
- package/.devcontainer/packages.sh +0 -228
- package/.devcontainer/password.sh +0 -148
- package/.devcontainer/ports-json.sh +0 -31
- package/.devcontainer/ports.sh +0 -132
- package/manage/scripts/create-cluster.sh +0 -107
- package/manage/scripts/docker.sh +0 -43
package/.devcontainer/cluster.sh
DELETED
|
@@ -1,388 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env bash
|
|
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
|
-
# relay_start NAME CTX NS TARGET PORTS… port-forward kept alive
|
|
18
|
-
# relay_active NAME / relay_stop NAME
|
|
19
|
-
# account_* (kube-account.sh #430) limited account and admin context
|
|
20
|
-
|
|
21
|
-
# Kind and host clusters, as remoteEnv of devcontainer.json: a docker exec or a
|
|
22
|
-
# script run outside the container terminal does not have it, and the relay
|
|
23
|
-
# must see the host cluster
|
|
24
|
-
: "${KUBECONFIG:=$HOME/.kube/config:$HOME/.kube/hote.config}"
|
|
25
|
-
export KUBECONFIG
|
|
26
|
-
|
|
27
|
-
# Module state: defined by the caller; default value for the tests
|
|
28
|
-
: "${ETAT:=${DEVZONE_STATE:-$HOME/.devzone.modules}}"
|
|
29
|
-
|
|
30
|
-
# Safe state write (#417): lock, temporary file in the state folder, backup copy
|
|
31
|
-
# .prev — shared by devzone, ports
|
|
32
|
-
|
|
33
|
-
# Instance name: empty or « devzone » = default instance (no suffix)
|
|
34
|
-
: "${DEVZONE_INSTANCE:=}"
|
|
35
|
-
INSTANCE_SUFFIX=""
|
|
36
|
-
if [ -n "$DEVZONE_INSTANCE" ] && [ "$DEVZONE_INSTANCE" != "devzone" ]; then
|
|
37
|
-
INSTANCE_SUFFIX="-${DEVZONE_INSTANCE}"
|
|
38
|
-
fi
|
|
39
|
-
|
|
40
|
-
# Dedicated kind cluster, created on the host Docker; name suffixed per instance
|
|
41
|
-
CLUSTER_DEDICATED=kind-devzone${INSTANCE_SUFFIX}
|
|
42
|
-
# Label set on every namespace created by devzone : a dedicated kind without a
|
|
43
|
-
# labelled namespace has no use left and can be deleted
|
|
44
|
-
CLUSTER_LABEL=app.kubernetes.io/managed-by=devzone
|
|
45
|
-
|
|
46
|
-
# Limited Kubernetes account (#430): account_setup, account_allow,
|
|
47
|
-
# account_remove, account_token, account_admin (admin context); the installers
|
|
48
|
-
# use it, cluster_release too
|
|
49
|
-
# shellcheck source=SCRIPTDIR/kube-account.sh
|
|
50
|
-
. "$(dirname "${BASH_SOURCE[0]}")/kube-account.sh"
|
|
51
|
-
|
|
52
|
-
cluster_saved() {
|
|
53
|
-
grep -E '^cluster=' "$ETAT" 2>/dev/null | tail -1 | cut -d= -f2- || true
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
cluster_save() {
|
|
57
|
-
DEVZONE_STATE="$ETAT" bash "${ICI:-$(dirname "${BASH_SOURCE[0]}")}/devzone" state write cluster "$1"
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
cluster_is_dedicated() {
|
|
61
|
-
[ "$1" = "${CLUSTER_DEDICATED}" ]
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
# Local cluster: read from the KUBECONFIG configuration, without network call.
|
|
65
|
-
# The dedicated kind is always local; a host cluster is local when its server
|
|
66
|
-
# listens on a loopback address (127.0.0.1, localhost, ::1, host.docker.internal).
|
|
67
|
-
cluster_is_local() {
|
|
68
|
-
local ctx="$1" cluster server host
|
|
69
|
-
cluster_is_dedicated "$ctx" && return 0
|
|
70
|
-
cluster="$(kubectl config view -o jsonpath="{.contexts[?(@.name==\"$ctx\")].context.cluster}" 2>/dev/null || true)"
|
|
71
|
-
[ -n "$cluster" ] || return 1
|
|
72
|
-
server="$(kubectl config view -o jsonpath="{.clusters[?(@.name==\"$cluster\")].cluster.server}" 2>/dev/null || true)"
|
|
73
|
-
[ -n "$server" ] || return 1
|
|
74
|
-
# Rule by name (old rule of metrics-server.sh)
|
|
75
|
-
case "$ctx" in
|
|
76
|
-
kind-* | docker-desktop | rancher-desktop | orbstack | minikube) return 0 ;;
|
|
77
|
-
esac
|
|
78
|
-
# Host extraction (IPv6 addresses in brackets handled)
|
|
79
|
-
host="${server#*://}"
|
|
80
|
-
host="${host%%/*}"
|
|
81
|
-
if [[ "$host" == \[* ]]; then
|
|
82
|
-
host="${host#[}"
|
|
83
|
-
host="${host%%]*}"
|
|
84
|
-
else
|
|
85
|
-
host="${host%%:*}"
|
|
86
|
-
fi
|
|
87
|
-
case "$host" in
|
|
88
|
-
127.0.0.1 | localhost | ::1 | host.docker.internal) return 0 ;;
|
|
89
|
-
*-control-plane) return 0 ;;
|
|
90
|
-
esac
|
|
91
|
-
return 1
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
# Sets the « devzone » context (cluster + user) on the given context (default:
|
|
95
|
-
# the current one): after an installation on a new machine, --context devzone
|
|
96
|
-
# targets the chosen services cluster from the start (#396)
|
|
97
|
-
devzone_context_set() {
|
|
98
|
-
local ctx cluster user
|
|
99
|
-
ctx="${1:-$(kubectl config current-context 2>/dev/null || true)}"
|
|
100
|
-
if [ -z "$ctx" ]; then
|
|
101
|
-
return 1
|
|
102
|
-
fi
|
|
103
|
-
cluster="$(kubectl config view -o jsonpath="{.contexts[?(@.name==\"$ctx\")].context.cluster}" 2>/dev/null || true)"
|
|
104
|
-
user="$(kubectl config view -o jsonpath="{.contexts[?(@.name==\"$ctx\")].context.user}" 2>/dev/null || true)"
|
|
105
|
-
if [ -n "$cluster" ]; then
|
|
106
|
-
kubectl config set-context devzone --cluster="$cluster" --user="$user" >/dev/null 2>&1
|
|
107
|
-
else
|
|
108
|
-
return 1
|
|
109
|
-
fi
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
cluster_reachable() {
|
|
113
|
-
kubectl --context "$1" --request-timeout=3s get --raw /readyz >/dev/null 2>&1
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
# Host contexts: local ones first, then the dedicated kind, finally the remote ones
|
|
117
|
-
cluster_candidates() {
|
|
118
|
-
local host="${DEVZONE_KUBE_HOST:-$HOME/.kube/hote.config}" c
|
|
119
|
-
if [ -f "$host" ]; then
|
|
120
|
-
# 1. Local clusters of the host (server on a loopback address)
|
|
121
|
-
for c in $(KUBECONFIG="$host" kubectl config get-contexts -o name 2>/dev/null); do
|
|
122
|
-
cluster_is_dedicated "$c" && continue
|
|
123
|
-
if cluster_is_local "$c" && cluster_reachable "$c"; then
|
|
124
|
-
echo "$c"
|
|
125
|
-
fi
|
|
126
|
-
done
|
|
127
|
-
fi
|
|
128
|
-
# 2. Dedicated kind cluster
|
|
129
|
-
echo "$CLUSTER_DEDICATED"
|
|
130
|
-
if [ -f "$host" ]; then
|
|
131
|
-
# 3. Remote clusters of the host
|
|
132
|
-
for c in $(KUBECONFIG="$host" kubectl config get-contexts -o name 2>/dev/null); do
|
|
133
|
-
cluster_is_dedicated "$c" && continue
|
|
134
|
-
if ! cluster_is_local "$c" && cluster_reachable "$c"; then
|
|
135
|
-
echo "$c"
|
|
136
|
-
fi
|
|
137
|
-
done
|
|
138
|
-
fi
|
|
139
|
-
return 0
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
# Menu on stderr (stdout carries the answer); Enter = first candidate
|
|
143
|
-
cluster_menu() {
|
|
144
|
-
local candidates=() c i=1 answer
|
|
145
|
-
while IFS= read -r c; do candidates+=("$c"); done < <(cluster_candidates)
|
|
146
|
-
{
|
|
147
|
-
echo "devzone : on which cluster should the devzone services be installed?"
|
|
148
|
-
for c in "${candidates[@]}"; do
|
|
149
|
-
if cluster_is_dedicated "$c"; then
|
|
150
|
-
echo " $i) $c dedicated kind cluster, in the container (default)"
|
|
151
|
-
elif cluster_is_local "$c"; then
|
|
152
|
-
echo " $i) $c local cluster"
|
|
153
|
-
else
|
|
154
|
-
echo " $i) $c remote cluster"
|
|
155
|
-
fi
|
|
156
|
-
i=$((i + 1))
|
|
157
|
-
done
|
|
158
|
-
[ -f "${DEVZONE_KUBE_HOST:-$HOME/.kube/hote.config}" ] ||
|
|
159
|
-
echo " (host clusters not visible: devzone enable kubernetes)"
|
|
160
|
-
} >&2
|
|
161
|
-
printf 'Number [1]: ' >&2
|
|
162
|
-
read -r answer || answer=""
|
|
163
|
-
answer="${answer:-1}"
|
|
164
|
-
case "$answer" in
|
|
165
|
-
*[!0-9]* | 0) echo "devzone : invalid choice: $answer" >&2; return 2 ;;
|
|
166
|
-
esac
|
|
167
|
-
if [ "$answer" -gt "${#candidates[@]}" ]; then
|
|
168
|
-
echo "devzone : invalid choice: $answer" >&2
|
|
169
|
-
return 2
|
|
170
|
-
fi
|
|
171
|
-
echo "${candidates[$((answer - 1))]}"
|
|
172
|
-
}
|
|
173
|
-
|
|
174
|
-
# Interactive terminal; DEVZONE_INTERACTIVE=1 for the tests (stdin redirected)
|
|
175
|
-
cluster_interactive() {
|
|
176
|
-
[ "${DEVZONE_INTERACTIVE:-}" = 1 ] || [ -t 0 ]
|
|
177
|
-
}
|
|
178
|
-
|
|
179
|
-
cluster_choose() {
|
|
180
|
-
local wanted="" confirm="" c answer arg
|
|
181
|
-
while [ "$#" -gt 0 ]; do
|
|
182
|
-
arg="$1"
|
|
183
|
-
shift
|
|
184
|
-
case "$arg" in
|
|
185
|
-
--confirm)
|
|
186
|
-
if [ "$#" -eq 0 ]; then
|
|
187
|
-
echo "devzone : --confirm needs a context" >&2
|
|
188
|
-
return 2
|
|
189
|
-
fi
|
|
190
|
-
confirm="$1"
|
|
191
|
-
shift
|
|
192
|
-
;;
|
|
193
|
-
--confirm=*) confirm="${arg#*=}" ;;
|
|
194
|
-
-*)
|
|
195
|
-
echo "devzone : unknown argument: $arg (cluster_choose [CTX] [--confirm CTX])" >&2
|
|
196
|
-
return 2
|
|
197
|
-
;;
|
|
198
|
-
*)
|
|
199
|
-
if [ -n "$wanted" ]; then
|
|
200
|
-
echo "devzone : unknown argument: $arg (cluster_choose [CTX] [--confirm CTX])" >&2
|
|
201
|
-
return 2
|
|
202
|
-
fi
|
|
203
|
-
wanted="$arg"
|
|
204
|
-
;;
|
|
205
|
-
esac
|
|
206
|
-
done
|
|
207
|
-
if [ -n "$wanted" ]; then
|
|
208
|
-
while IFS= read -r c; do
|
|
209
|
-
[ "$c" = "$wanted" ] && break
|
|
210
|
-
done < <(cluster_candidates)
|
|
211
|
-
if [ "$c" != "$wanted" ]; then
|
|
212
|
-
echo "devzone : unknown or unreachable cluster: $wanted; candidates: $(cluster_candidates | tr '\n' ' ')" >&2
|
|
213
|
-
return 2
|
|
214
|
-
fi
|
|
215
|
-
# Remote: confirmation required. --confirm counts only if it is exactly
|
|
216
|
-
# the requested context; DEVZONE_CLUSTER_REMOTE is still accepted for
|
|
217
|
-
# the tests and CI
|
|
218
|
-
if ! cluster_is_local "$wanted"; then
|
|
219
|
-
if [ -n "$confirm" ]; then
|
|
220
|
-
if [ "$confirm" != "$wanted" ]; then
|
|
221
|
-
echo "devzone : remote cluster refused: $wanted (--confirm $wanted)" >&2
|
|
222
|
-
return 2
|
|
223
|
-
fi
|
|
224
|
-
elif [ -n "${DEVZONE_CLUSTER_REMOTE:-}" ]; then
|
|
225
|
-
if [ "${DEVZONE_CLUSTER_REMOTE}" != "$wanted" ]; then
|
|
226
|
-
echo "devzone : remote cluster refused: $wanted (DEVZONE_CLUSTER_REMOTE must be exactly $wanted)" >&2
|
|
227
|
-
return 2
|
|
228
|
-
fi
|
|
229
|
-
elif cluster_interactive; then
|
|
230
|
-
printf 'remote cluster: %s ; type its name to confirm: ' "$wanted" >&2
|
|
231
|
-
read -r answer || answer=""
|
|
232
|
-
if [ "$answer" != "$wanted" ]; then
|
|
233
|
-
echo "devzone : remote cluster refused: $wanted (--confirm $wanted)" >&2
|
|
234
|
-
return 2
|
|
235
|
-
fi
|
|
236
|
-
else
|
|
237
|
-
echo "devzone : remote cluster refused: $wanted (--confirm $wanted)" >&2
|
|
238
|
-
return 2
|
|
239
|
-
fi
|
|
240
|
-
fi
|
|
241
|
-
echo "$wanted"
|
|
242
|
-
return 0
|
|
243
|
-
fi
|
|
244
|
-
c="$(cluster_saved)"
|
|
245
|
-
if [ -n "$c" ]; then
|
|
246
|
-
echo "$c"
|
|
247
|
-
elif cluster_interactive; then
|
|
248
|
-
cluster_menu
|
|
249
|
-
else
|
|
250
|
-
# Default: local only (never remote by default)
|
|
251
|
-
local host_choice=""
|
|
252
|
-
if [ -f "${DEVZONE_KUBE_HOST:-$HOME/.kube/hote.config}" ]; then
|
|
253
|
-
host_choice="$(KUBECONFIG="${DEVZONE_KUBE_HOST:-$HOME/.kube/hote.config}" kubectl config current-context 2>/dev/null || true)"
|
|
254
|
-
fi
|
|
255
|
-
if [ -n "$host_choice" ] && cluster_is_local "$host_choice" && cluster_reachable "$host_choice"; then
|
|
256
|
-
echo "$host_choice"
|
|
257
|
-
else
|
|
258
|
-
echo "$CLUSTER_DEDICATED"
|
|
259
|
-
fi
|
|
260
|
-
fi
|
|
261
|
-
}
|
|
262
|
-
|
|
263
|
-
# Runs kind without switching kubectl's current context (#366): the previous
|
|
264
|
-
# one is restored, or removed if there was none. The kind exit code is returned
|
|
265
|
-
# even under set -e: the restore happens first.
|
|
266
|
-
kind_keep_context() {
|
|
267
|
-
local previous code=0
|
|
268
|
-
previous="$(kubectl config current-context 2>/dev/null || true)"
|
|
269
|
-
kind "$@" || code=$?
|
|
270
|
-
if [ -n "$previous" ]; then
|
|
271
|
-
kubectl config use-context "$previous" >/dev/null 2>&1 || true
|
|
272
|
-
else
|
|
273
|
-
KUBECONFIG="$HOME/.kube/config" kubectl config unset current-context >/dev/null 2>&1 || true
|
|
274
|
-
fi
|
|
275
|
-
return "$code"
|
|
276
|
-
}
|
|
277
|
-
|
|
278
|
-
# Creates a kind cluster without switching kubectl's current context.
|
|
279
|
-
kind_create_keep_context() {
|
|
280
|
-
kind_keep_context create cluster "$@"
|
|
281
|
-
}
|
|
282
|
-
|
|
283
|
-
cluster_prepare() {
|
|
284
|
-
local ctx="$1"
|
|
285
|
-
if [ "$ctx" = "$CLUSTER_DEDICATED" ]; then
|
|
286
|
-
if ! kind get clusters 2>/dev/null | grep -qx "devzone${INSTANCE_SUFFIX}"; then
|
|
287
|
-
echo "▶ Creating the kind devzone cluster (about 1 min)…"
|
|
288
|
-
# Busy host Docker (its Kubernetes, other clusters): the node API can
|
|
289
|
-
# restart during initialization and kind gives up within seconds. A
|
|
290
|
-
# second attempt, on a fresh cluster.
|
|
291
|
-
if ! kind_create_keep_context --name "devzone${INSTANCE_SUFFIX}" --wait 120s; then
|
|
292
|
-
echo "▶ Retrying the kind cluster creation…"
|
|
293
|
-
kind delete cluster --name "devzone${INSTANCE_SUFFIX}" >/dev/null 2>&1 || true
|
|
294
|
-
kind_create_keep_context --name "devzone${INSTANCE_SUFFIX}" --wait 120s || return 1
|
|
295
|
-
fi
|
|
296
|
-
fi
|
|
297
|
-
elif ! cluster_reachable "$ctx"; then
|
|
298
|
-
echo "devzone : cluster $ctx unreachable (kubernetes module enabled? cluster started?)" >&2
|
|
299
|
-
return 1
|
|
300
|
-
fi
|
|
301
|
-
# If it has just been created, the services cluster must carry the devzone
|
|
302
|
-
# context at once, otherwise the installation targets the old cluster (#396)
|
|
303
|
-
devzone_context_set "$ctx" || echo "devzone : devzone context not set on $ctx" >&2
|
|
304
|
-
}
|
|
305
|
-
|
|
306
|
-
# Dedicated kind with no devzone namespace left: deleted (it only uses memory).
|
|
307
|
-
# Never a host cluster.
|
|
308
|
-
cluster_release() {
|
|
309
|
-
local ctx="$1" left
|
|
310
|
-
cluster_is_dedicated "$ctx" || return 0
|
|
311
|
-
kind get clusters 2>/dev/null | grep -qx "devzone${INSTANCE_SUFFIX}" || return 0
|
|
312
|
-
# Reading the namespaces labelled by the administrator (#430): the namespace
|
|
313
|
-
# list is refused to the limited account
|
|
314
|
-
left="$(account_admin "$ctx" get namespaces -l "$CLUSTER_LABEL" -o name 2>/dev/null || true)"
|
|
315
|
-
if [ -z "$left" ]; then
|
|
316
|
-
kind delete cluster --name "devzone${INSTANCE_SUFFIX}" >/dev/null 2>&1 || true
|
|
317
|
-
echo "▶ kind devzone cluster removed (no service left)."
|
|
318
|
-
fi
|
|
319
|
-
}
|
|
320
|
-
|
|
321
|
-
# ---- Relay: port of a cluster service on the container's 127.0.0.1 ----
|
|
322
|
-
# kubectl port-forward works on every cluster whose API answers (dedicated kind
|
|
323
|
-
# or host cluster), without exposing a port on the nodes. It stops when the pod
|
|
324
|
-
# restarts: the loop restarts it. PID and log in workspace/.<name>/ (module
|
|
325
|
-
# folder, ignored by git).
|
|
326
|
-
relay_dir() {
|
|
327
|
-
echo "$RACINE/workspace/.$1"
|
|
328
|
-
}
|
|
329
|
-
|
|
330
|
-
relay_active() {
|
|
331
|
-
local pid
|
|
332
|
-
pid="$(cat "$(relay_dir "$1")/relais.pid" 2>/dev/null || true)"
|
|
333
|
-
[ -n "$pid" ] && kill -0 "$pid" 2>/dev/null
|
|
334
|
-
}
|
|
335
|
-
|
|
336
|
-
relay_start() {
|
|
337
|
-
local name="$1" ctx="$2" ns="$3" target="$4" dir
|
|
338
|
-
shift 4
|
|
339
|
-
dir="$(relay_dir "$name")"
|
|
340
|
-
mkdir -p "$dir"
|
|
341
|
-
relay_active "$name" && return 0
|
|
342
|
-
# setsid: separate session, the relay survives the end of the script that
|
|
343
|
-
# started it (postStartCommand, devzone workspace shell); absent on macOS (bash 3.2 tests)
|
|
344
|
-
local detached=()
|
|
345
|
-
command -v setsid >/dev/null 2>&1 && detached=(setsid)
|
|
346
|
-
# port-forward targets one precise pod and sees its disappearance only at the
|
|
347
|
-
# next connection, which fails. For a service, the loop therefore follows the
|
|
348
|
-
# ready pod behind it (UID in its endpoints): waits until there is one, then
|
|
349
|
-
# restarts port-forward as soon as it changes (pod restarted).
|
|
350
|
-
# shellcheck disable=SC2016 # variables expanded by the relay's bash
|
|
351
|
-
${detached[@]+"${detached[@]}"} nohup bash -c '
|
|
352
|
-
pod() {
|
|
353
|
-
case "$2" in
|
|
354
|
-
svc/*) kubectl --context "$0" -n "$1" get endpoints "${2#svc/}" -o jsonpath="{.subsets[*].addresses[*].targetRef.uid}" 2>/dev/null ;;
|
|
355
|
-
*) echo fixe ;;
|
|
356
|
-
esac
|
|
357
|
-
}
|
|
358
|
-
while :; do
|
|
359
|
-
until [ -n "$(pod "$@")" ]; do sleep 2; done
|
|
360
|
-
actuel="$(pod "$@")"
|
|
361
|
-
kubectl --context "$0" -n "$1" port-forward --address 127.0.0.1 "$2" "${@:3}" &
|
|
362
|
-
pf=$!
|
|
363
|
-
while kill -0 "$pf" 2>/dev/null; do
|
|
364
|
-
sleep 5
|
|
365
|
-
[ "$(pod "$@")" = "$actuel" ] || { kill "$pf" 2>/dev/null; break; }
|
|
366
|
-
done
|
|
367
|
-
wait "$pf" 2>/dev/null
|
|
368
|
-
sleep 1
|
|
369
|
-
done' \
|
|
370
|
-
"$ctx" "$ns" "$target" "$@" >"$dir/relais.log" 2>&1 &
|
|
371
|
-
echo "$!" >"$dir/relais.pid"
|
|
372
|
-
}
|
|
373
|
-
|
|
374
|
-
relay_stop() {
|
|
375
|
-
local file pid children
|
|
376
|
-
file="$(relay_dir "$1")/relais.pid"
|
|
377
|
-
pid="$(cat "$file" 2>/dev/null || true)"
|
|
378
|
-
if [ -n "$pid" ]; then
|
|
379
|
-
# Children (port-forward) listed before: once the loop is killed, they
|
|
380
|
-
# are reattached to init and pgrep -P no longer sees them. The loop first,
|
|
381
|
-
# otherwise it would restart the port-forward.
|
|
382
|
-
children="$(pgrep -P "$pid" 2>/dev/null || true)"
|
|
383
|
-
kill "$pid" 2>/dev/null || true
|
|
384
|
-
# shellcheck disable=SC2086 # list of PIDs
|
|
385
|
-
[ -z "$children" ] || kill $children 2>/dev/null || true
|
|
386
|
-
fi
|
|
387
|
-
rm -f "$file"
|
|
388
|
-
}
|
|
@@ -1,86 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env bash
|
|
2
|
-
# View of the connected clusters (#337): visible contexts, type, state, namespace.
|
|
3
|
-
ICI="$(cd -P "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
|
4
|
-
if ! declare -F cluster_is_local >/dev/null 2>&1; then
|
|
5
|
-
# shellcheck source=SCRIPTDIR/cluster.sh
|
|
6
|
-
# shellcheck disable=SC1091
|
|
7
|
-
. "$ICI/cluster.sh"
|
|
8
|
-
fi
|
|
9
|
-
|
|
10
|
-
# Shows the view of the connected clusters.
|
|
11
|
-
clusters_show() {
|
|
12
|
-
local contexts=() ctx ctx_work ctx_services tmp i ns type state mark marks
|
|
13
|
-
ctx_work="$(kubectl config current-context 2>/dev/null || true)"
|
|
14
|
-
ctx_services="$(cluster_saved 2>/dev/null || true)"
|
|
15
|
-
while IFS= read -r ctx; do
|
|
16
|
-
[ -n "$ctx" ] || continue
|
|
17
|
-
contexts+=("$ctx")
|
|
18
|
-
done < <(kubectl config get-contexts -o name 2>/dev/null || true)
|
|
19
|
-
|
|
20
|
-
if [ "${#contexts[@]}" -eq 0 ]; then
|
|
21
|
-
echo "no cluster: kind create cluster, or devzone enable kubernetes"
|
|
22
|
-
return 0
|
|
23
|
-
fi
|
|
24
|
-
|
|
25
|
-
printf '%s %-14s %-8s %-12s %s\n' " " "CONTEXT" "TYPE" "STATE" "NAMESPACE"
|
|
26
|
-
tmp="$(mktemp -d)"
|
|
27
|
-
for i in "${!contexts[@]}"; do
|
|
28
|
-
ctx="${contexts[$i]}"
|
|
29
|
-
(
|
|
30
|
-
if kubectl --context "$ctx" --request-timeout=3s get --raw /readyz >/dev/null 2>&1; then
|
|
31
|
-
echo reachable
|
|
32
|
-
else
|
|
33
|
-
echo unreachable
|
|
34
|
-
fi
|
|
35
|
-
) >"$tmp/$i" &
|
|
36
|
-
done
|
|
37
|
-
wait
|
|
38
|
-
for i in "${!contexts[@]}"; do
|
|
39
|
-
ctx="${contexts[$i]}"
|
|
40
|
-
state="$(cat "$tmp/$i" 2>/dev/null || echo unreachable)"
|
|
41
|
-
if cluster_is_local "$ctx" >/dev/null 2>&1; then
|
|
42
|
-
type=local
|
|
43
|
-
else
|
|
44
|
-
type=remote
|
|
45
|
-
fi
|
|
46
|
-
ns="$(kubectl config view -o jsonpath="{.contexts[?(@.name==\"$ctx\")].context.namespace}" 2>/dev/null || true)"
|
|
47
|
-
[ -n "$ns" ] || ns=default
|
|
48
|
-
mark=""
|
|
49
|
-
marks=0
|
|
50
|
-
if [ "$ctx" = "$ctx_work" ]; then
|
|
51
|
-
mark+="★"
|
|
52
|
-
marks=$((marks + 1))
|
|
53
|
-
fi
|
|
54
|
-
if [ "$ctx" = "$ctx_services" ]; then
|
|
55
|
-
mark+="●"
|
|
56
|
-
marks=$((marks + 1))
|
|
57
|
-
fi
|
|
58
|
-
while [ "$marks" -lt 2 ]; do
|
|
59
|
-
mark+=" "
|
|
60
|
-
marks=$((marks + 1))
|
|
61
|
-
done
|
|
62
|
-
printf '%s %-14s %-8s %-12s %s\n' "$mark" "$ctx" "$type" "$state" "$ns"
|
|
63
|
-
done
|
|
64
|
-
rm -rf "$tmp"
|
|
65
|
-
echo
|
|
66
|
-
echo "★ working cluster (kubectl, k9s, helm) · ● devzone services cluster (devzone cluster)"
|
|
67
|
-
# Display of the NetworkPolicy isolation state for the services cluster
|
|
68
|
-
if [ -n "$ctx_services" ] && cluster_is_local "$ctx_services"; then
|
|
69
|
-
if kubectl --context "$ctx_services" get networkpolicy devzone-meme-namespace -n devzone-postgres >/dev/null 2>&1; then
|
|
70
|
-
printf ' ✔ isolated (NetworkPolicy) → %s\n' "$ctx_services"
|
|
71
|
-
else
|
|
72
|
-
printf ' ⚠ isolated (NetworkPolicy missing) → %s\n' "$ctx_services"
|
|
73
|
-
fi
|
|
74
|
-
printf ' devzone → %s\n' "$ctx_services"
|
|
75
|
-
fi
|
|
76
|
-
return 0
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
# Aliases of the devzone clusters command.
|
|
80
|
-
clusters() { clusters_show "$@"; }
|
|
81
|
-
# Alias for the tests and direct calls.
|
|
82
|
-
devzone_clusters() { clusters_show "$@"; }
|
|
83
|
-
|
|
84
|
-
if [ "${BASH_SOURCE[0]}" = "$0" ]; then
|
|
85
|
-
clusters_show "$@"
|
|
86
|
-
fi
|
|
@@ -1,98 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env bash
|
|
2
|
-
# shellcheck shell=bash
|
|
3
|
-
# devzone, ai module: guard of the host container tools.
|
|
4
|
-
# Sourced by .devcontainer/devzone (split of the 1 600 lines file, #722):
|
|
5
|
-
# functions only, shared variables are defined in devzone.
|
|
6
|
-
|
|
7
|
-
# Docker guard for the folders that are not this repository: a Claude Code
|
|
8
|
-
# PreToolUse hook in the global settings and the two opencode plugins in the
|
|
9
|
-
# global plugins folder. Idempotent, other user settings and hooks preserved.
|
|
10
|
-
# Claude Code also receives the limited Kubernetes context via env.KUBECONFIG.
|
|
11
|
-
install_docker_guard() {
|
|
12
|
-
local script="$ICI/ai/docker-guard.sh" config="$HOME/.claude/settings.json"
|
|
13
|
-
local src="$ICI/ai/plugins" dst="$HOME/.config/opencode/plugins"
|
|
14
|
-
local tmp f
|
|
15
|
-
if ! command -v jq >/dev/null 2>&1; then
|
|
16
|
-
echo "devzone : jq missing: docker guard not installed for Claude Code" >&2
|
|
17
|
-
elif [ ! -f "$config" ]; then
|
|
18
|
-
echo "devzone : $config missing: docker guard not installed for Claude Code" >&2
|
|
19
|
-
elif ! jq -e . "$config" >/dev/null 2>&1; then
|
|
20
|
-
echo "devzone : $config unreadable (invalid JSON): docker guard not installed for Claude Code" >&2
|
|
21
|
-
else
|
|
22
|
-
tmp="$(mktemp)"
|
|
23
|
-
if jq --arg cmd "bash \"$script\" --format claude" \
|
|
24
|
-
--arg kube "$HOME/.kube/agent.config" '
|
|
25
|
-
.hooks = (.hooks // {}) |
|
|
26
|
-
.hooks.PreToolUse = (.hooks.PreToolUse // []) |
|
|
27
|
-
if ([.hooks.PreToolUse[]? | .hooks[]? | (.command // "")] | any(contains("docker-guard.sh")))
|
|
28
|
-
then .
|
|
29
|
-
else .hooks.PreToolUse += [{"matcher": "Bash", "hooks": [{"type": "command", "command": $cmd}]}]
|
|
30
|
-
end |
|
|
31
|
-
if (.env | type) == "object" then .env = (.env + {"KUBECONFIG": $kube})
|
|
32
|
-
elif (.env | type) == "null" then .env = {"KUBECONFIG": $kube}
|
|
33
|
-
else . end
|
|
34
|
-
' "$config" >"$tmp" 2>/dev/null; then
|
|
35
|
-
mv "$tmp" "$config"
|
|
36
|
-
else
|
|
37
|
-
rm -f "$tmp"
|
|
38
|
-
echo "devzone : $config unchanged: docker guard not installed for Claude Code" >&2
|
|
39
|
-
fi
|
|
40
|
-
fi
|
|
41
|
-
mkdir -p "$dst"
|
|
42
|
-
for f in devzone-guard.js devzone-guard-v2.js; do
|
|
43
|
-
[ -f "$src/$f" ] || continue
|
|
44
|
-
sed "s|__DEVZONE_DOCKER_GUARD__|$script|g" "$src/$f" >"$dst/$f"
|
|
45
|
-
done
|
|
46
|
-
echo "devzone : docker guard active for Claude Code and opencode"
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
# Removes only the Docker guard entries (commands containing docker-guard.sh)
|
|
50
|
-
# and the two plugins; the rest of settings.json and of the plugins is kept.
|
|
51
|
-
# The Kubernetes context key is removed too, and an empty env object is dropped.
|
|
52
|
-
remove_docker_guard() {
|
|
53
|
-
local config="$HOME/.claude/settings.json" tmp tmp2
|
|
54
|
-
if [ -f "$config" ] && jq -e . "$config" >/dev/null 2>&1; then
|
|
55
|
-
tmp="$(mktemp)"
|
|
56
|
-
if jq '
|
|
57
|
-
if (.hooks.PreToolUse // null) != null then
|
|
58
|
-
.hooks.PreToolUse = [
|
|
59
|
-
.hooks.PreToolUse[] |
|
|
60
|
-
if (.hooks // null) != null then
|
|
61
|
-
.hooks = [ .hooks[] | select(((.command // "") | contains("docker-guard.sh")) | not) ] |
|
|
62
|
-
select((.hooks | length) > 0)
|
|
63
|
-
else
|
|
64
|
-
select(((.command // "") | contains("docker-guard.sh")) | not)
|
|
65
|
-
end
|
|
66
|
-
] |
|
|
67
|
-
if (.hooks.PreToolUse | length) == 0 then del(.hooks.PreToolUse) else . end |
|
|
68
|
-
if ((.hooks // {}) | keys | length) == 0 then del(.hooks) else . end
|
|
69
|
-
else . end
|
|
70
|
-
' "$config" >"$tmp" 2>/dev/null; then
|
|
71
|
-
if [ "$(cat "$tmp")" = "{}" ]; then
|
|
72
|
-
rm -f "$tmp" "$config"
|
|
73
|
-
else
|
|
74
|
-
tmp2="$(mktemp)"
|
|
75
|
-
if jq '
|
|
76
|
-
if (.env | type) == "object" then
|
|
77
|
-
.env = (.env | del(.KUBECONFIG)) |
|
|
78
|
-
if (.env | length) == 0 then del(.env) else . end
|
|
79
|
-
else . end
|
|
80
|
-
' "$tmp" >"$tmp2" 2>/dev/null; then
|
|
81
|
-
if [ "$(cat "$tmp2")" = "{}" ]; then
|
|
82
|
-
rm -f "$tmp2" "$config"
|
|
83
|
-
else
|
|
84
|
-
mv "$tmp2" "$config"
|
|
85
|
-
fi
|
|
86
|
-
else
|
|
87
|
-
rm -f "$tmp2"
|
|
88
|
-
mv "$tmp" "$config"
|
|
89
|
-
fi
|
|
90
|
-
rm -f "$tmp"
|
|
91
|
-
fi
|
|
92
|
-
else
|
|
93
|
-
rm -f "$tmp"
|
|
94
|
-
fi
|
|
95
|
-
fi
|
|
96
|
-
rm -f "$HOME/.config/opencode/plugins/devzone-guard.js" \
|
|
97
|
-
"$HOME/.config/opencode/plugins/devzone-guard-v2.js"
|
|
98
|
-
}
|