devzone 2.0.0 → 4.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.
- package/.devcontainer/agent-errors.sh +6 -6
- package/.devcontainer/agent-pod-manifest.sh +4 -4
- package/.devcontainer/agent-session.sh +2 -2
- package/.devcontainer/agent-state-json.sh +2 -2
- package/.devcontainer/agent-workspace.sh +1 -1
- package/.devcontainer/agent.sh +7 -7
- package/.devcontainer/ai/host-models.sh +2 -2
- package/.devcontainer/ai/plugins/devzone-guard-v2.js +3 -3
- package/.devcontainer/ai/plugins/devzone-guard.js +3 -3
- package/.devcontainer/argocd/argocd.sh +90 -89
- package/.devcontainer/argocd/catalog-argocd.sh +2 -2
- package/.devcontainer/argocd/services-hook.sh +3 -3
- package/.devcontainer/argocd/services.sh +1 -1
- package/.devcontainer/catalog/app.sh +114 -116
- package/.devcontainer/catalog/catalog-watcher.sh +62 -62
- package/.devcontainer/catalog/mysql/app.conf +1 -1
- package/.devcontainer/catalog/mysql/install.sh +40 -40
- package/.devcontainer/catalog/mysql/mysql.sh +141 -141
- package/.devcontainer/catalog/mysql/volume.sh +39 -39
- package/.devcontainer/catalog.sh +112 -112
- package/.devcontainer/chart-direct.sh +1 -1
- package/.devcontainer/cluster.sh +216 -218
- package/.devcontainer/clusters.sh +41 -41
- package/.devcontainer/command-aliases.sh +17 -8
- package/.devcontainer/devzone +93 -1496
- package/.devcontainer/devzone-ai-guard.sh +76 -0
- package/.devcontainer/devzone-ai.sh +201 -0
- package/.devcontainer/devzone-cluster.sh +210 -0
- package/.devcontainer/devzone-modules.sh +126 -0
- package/.devcontainer/devzone-platform.sh +189 -0
- package/.devcontainer/devzone-repair.sh +94 -0
- package/.devcontainer/devzone-services.sh +241 -0
- package/.devcontainer/devzone-skill.sh +97 -0
- package/.devcontainer/devzone-status.sh +140 -0
- package/.devcontainer/devzone-version.sh +78 -0
- package/.devcontainer/git-identity.sh +28 -0
- package/.devcontainer/gitlab/chart.sh +2 -2
- package/.devcontainer/gitlab/gitlab.sh +81 -82
- package/.devcontainer/gitlab/installation.sh +109 -109
- package/.devcontainer/gitlab/secrets.sh +47 -47
- package/.devcontainer/gitlab/seed.sh +77 -77
- package/.devcontainer/gitlab/test-gitlab.sh +242 -243
- package/.devcontainer/help.sh +1 -1
- package/.devcontainer/isolation.sh +30 -30
- package/.devcontainer/kind-wrapper.sh +17 -17
- package/.devcontainer/kube-account.sh +112 -113
- package/.devcontainer/kube-config.sh +45 -46
- package/.devcontainer/{invite-kube.sh → kube-prompt.sh} +6 -6
- package/.devcontainer/kube-reachable.sh +40 -40
- package/.devcontainer/memory.sh +1 -1
- package/.devcontainer/metrics-server.sh +2 -2
- package/.devcontainer/opencode.jsonc +2 -2
- package/.devcontainer/packages.sh +136 -135
- package/.devcontainer/password.sh +1 -1
- package/.devcontainer/ports-auto.sh +152 -153
- package/.devcontainer/ports-json.sh +16 -15
- package/.devcontainer/ports.sh +126 -122
- package/.devcontainer/post-create.sh +52 -52
- package/.devcontainer/postgres/postgres.sh +174 -174
- package/.devcontainer/rename-legacy-files.sh +103 -0
- package/.devcontainer/services-admin.sh +3 -3
- package/.devcontainer/skills/devzone/SKILL.md +40 -41
- package/.devcontainer/startup.sh +48 -49
- package/.devcontainer/state-gitops.sh +1 -1
- package/.devcontainer/state-json.sh +36 -62
- package/.devcontainer/state.sh +2 -2
- package/.devcontainer/workspace-init.sh +16 -2
- package/Makefile +1 -1
- package/README.md +191 -195
- package/charts/devzone-workspace/templates/statefulset.yaml +1 -1
- package/manage/devzone +7 -11
- package/manage/scripts/argocd-workspace.sh +1 -1
- package/manage/scripts/{check-charts.sh → ci/check-charts.sh} +1 -1
- package/manage/scripts/{check-english.sh → ci/check-english.sh} +1 -1
- package/manage/scripts/{check-go-layout.sh → ci/check-go-layout.sh} +1 -1
- package/manage/scripts/{check-names.sh → ci/check-names.sh} +7 -6
- package/manage/scripts/{check-utf8-vars.sh → ci/check-utf8-vars.sh} +1 -1
- package/manage/scripts/{versions.sh → ci/versions.sh} +8 -8
- package/manage/scripts/create-cluster.sh +1 -1
- package/manage/scripts/create-mode.sh +11 -18
- package/manage/scripts/devzone-create.sh +7 -35
- package/manage/scripts/devzone-manifest.sh +1 -1
- package/manage/scripts/devzone-update.sh +12 -8
- package/manage/scripts/launch.sh +7 -48
- package/manage/scripts/ports-apps.sh +1 -1
- package/manage/scripts/ports-workspace.sh +7 -7
- package/manage/scripts/poste.sh +6 -7
- package/manage/scripts/uninstall.sh +8 -8
- package/manage/scripts/workspace-egress.sh +2 -2
- package/manage/scripts/workspace-update.sh +5 -2
- package/manage/scripts/workspace-wait.sh +2 -2
- package/manage/workspace.sh +2 -12
- package/package.json +1 -1
- package/.devcontainer/docker-relay.sh +0 -149
- package/.devcontainer/docker-without-host.sh +0 -12
- package/.devcontainer/git-identite.sh +0 -28
- package/manage/scripts/docker-workstation.sh +0 -73
- package/manage/scripts/migrate-revert.sh +0 -60
- package/manage/scripts/migrate.sh +0 -243
- /package/manage/scripts/{ci-dns.sh → ci/ci-dns.sh} +0 -0
package/.devcontainer/cluster.sh
CHANGED
|
@@ -1,111 +1,109 @@
|
|
|
1
1
|
#!/usr/bin/env bash
|
|
2
|
-
#
|
|
3
|
-
#
|
|
4
|
-
#
|
|
5
|
-
#
|
|
6
|
-
#
|
|
7
|
-
#
|
|
8
|
-
#
|
|
9
|
-
#
|
|
10
|
-
#
|
|
11
|
-
#
|
|
12
|
-
#
|
|
13
|
-
#
|
|
14
|
-
#
|
|
15
|
-
#
|
|
16
|
-
#
|
|
17
|
-
#
|
|
18
|
-
#
|
|
19
|
-
#
|
|
20
|
-
#
|
|
21
|
-
# compte_* (kube-account.sh #430) compte limité et contexte administrateur
|
|
2
|
+
# devzone cluster (#280): the cluster where the modules that provide a service
|
|
3
|
+
# are deployed (postgres; gitlab with #279). A single choice per instance, kept
|
|
4
|
+
# in the state (line « cluster=<kubectl context> »): the services of an instance
|
|
5
|
+
# live in the same place and move together (devzone cluster CTX).
|
|
6
|
+
# Sourced library: the caller defines RACINE and ETAT.
|
|
7
|
+
# cluster_saved chosen context, nothing if there is none
|
|
8
|
+
# cluster_save CTX keeps the choice in the state
|
|
9
|
+
# cluster_is_local CTX 0 if local cluster (config, no network)
|
|
10
|
+
# cluster_candidates local, then dedicated kind, then remote
|
|
11
|
+
# cluster_choose [CTX] [--confirm CTX]
|
|
12
|
+
# CTX validated (remote: confirmation),
|
|
13
|
+
# otherwise kept choice, otherwise menu
|
|
14
|
+
# (terminal only), otherwise local default
|
|
15
|
+
# cluster_prepare CTX creates the dedicated kind cluster if missing
|
|
16
|
+
# cluster_release CTX deletes the dedicated kind cluster once empty
|
|
17
|
+
# kube_reachable_from_container FILE rewrites 127.0.0.1/localhost
|
|
18
|
+
# relay_start NAME CTX NS TARGET PORTS… port-forward kept alive
|
|
19
|
+
# relay_active NAME / relay_stop NAME
|
|
20
|
+
# account_* (kube-account.sh #430) limited account and admin context
|
|
22
21
|
|
|
23
|
-
#
|
|
24
|
-
#
|
|
25
|
-
#
|
|
22
|
+
# Kind and host clusters, as remoteEnv of devcontainer.json: a docker exec or a
|
|
23
|
+
# script run outside the container terminal does not have it, and the relay
|
|
24
|
+
# must see the host cluster
|
|
26
25
|
: "${KUBECONFIG:=$HOME/.kube/config:$HOME/.kube/hote.config}"
|
|
27
26
|
export KUBECONFIG
|
|
28
27
|
|
|
29
|
-
#
|
|
30
|
-
: "${ETAT:=${
|
|
28
|
+
# Module state: defined by the caller; default value for the tests
|
|
29
|
+
: "${ETAT:=${DEVZONE_STATE:-$HOME/.devzone.modules}}"
|
|
31
30
|
|
|
32
|
-
#
|
|
33
|
-
#
|
|
31
|
+
# Safe state write (#417): lock, temporary file in the state folder, backup copy
|
|
32
|
+
# .prec — shared by devzone, ports and ports-auto
|
|
34
33
|
# shellcheck source=SCRIPTDIR/state.sh
|
|
35
34
|
# shellcheck disable=SC1091
|
|
36
35
|
. "$(dirname "${BASH_SOURCE[0]}")/state.sh"
|
|
37
36
|
|
|
38
|
-
#
|
|
37
|
+
# Instance name: empty or « devzone » = default instance (no suffix)
|
|
39
38
|
: "${DEVZONE_INSTANCE:=}"
|
|
40
39
|
INSTANCE_SUFFIX=""
|
|
41
40
|
if [ -n "$DEVZONE_INSTANCE" ] && [ "$DEVZONE_INSTANCE" != "devzone" ]; then
|
|
42
41
|
INSTANCE_SUFFIX="-${DEVZONE_INSTANCE}"
|
|
43
42
|
fi
|
|
44
43
|
|
|
45
|
-
#
|
|
46
|
-
|
|
47
|
-
#
|
|
48
|
-
# namespace
|
|
49
|
-
|
|
44
|
+
# Dedicated kind cluster, created on the host Docker; name suffixed per instance
|
|
45
|
+
CLUSTER_DEDICATED=kind-devzone${INSTANCE_SUFFIX}
|
|
46
|
+
# Label set on every namespace created by devzone : a dedicated kind without a
|
|
47
|
+
# labelled namespace has no use left and can be deleted
|
|
48
|
+
CLUSTER_LABEL=app.kubernetes.io/managed-by=devzone
|
|
50
49
|
|
|
51
|
-
#
|
|
52
|
-
#
|
|
50
|
+
# Rewrite 127.0.0.1 → host.docker.internal (#291): shared with the kind wrapper,
|
|
51
|
+
# which applies it too to clusters created by hand
|
|
53
52
|
# shellcheck source=SCRIPTDIR/kube-reachable.sh
|
|
54
53
|
. "$(dirname "${BASH_SOURCE[0]}")/kube-reachable.sh"
|
|
55
54
|
|
|
56
|
-
#
|
|
57
|
-
#
|
|
58
|
-
#
|
|
55
|
+
# Limited Kubernetes account (#430): account_setup, account_allow,
|
|
56
|
+
# account_remove, account_token, account_admin (admin context); the installers
|
|
57
|
+
# use it, cluster_release too
|
|
59
58
|
# shellcheck source=SCRIPTDIR/kube-account.sh
|
|
60
59
|
. "$(dirname "${BASH_SOURCE[0]}")/kube-account.sh"
|
|
61
60
|
|
|
62
|
-
|
|
61
|
+
cluster_saved() {
|
|
63
62
|
grep -E '^cluster=' "$ETAT" 2>/dev/null | tail -1 | cut -d= -f2- || true
|
|
64
63
|
}
|
|
65
64
|
|
|
66
|
-
|
|
65
|
+
cluster_save() {
|
|
67
66
|
state_write cluster "$1"
|
|
68
67
|
}
|
|
69
68
|
|
|
70
|
-
|
|
71
|
-
[ "$1" = "${
|
|
69
|
+
cluster_is_dedicated() {
|
|
70
|
+
[ "$1" = "${CLUSTER_DEDICATED}" ]
|
|
72
71
|
}
|
|
73
72
|
|
|
74
|
-
#
|
|
75
|
-
#
|
|
76
|
-
#
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
cluster_est_dedie "$ctx" && return 0
|
|
73
|
+
# Local cluster: read from the KUBECONFIG configuration, without network call.
|
|
74
|
+
# The dedicated kind is always local; a host cluster is local when its server
|
|
75
|
+
# listens on a loopback address (127.0.0.1, localhost, ::1, host.docker.internal).
|
|
76
|
+
cluster_is_local() {
|
|
77
|
+
local ctx="$1" cluster server host
|
|
78
|
+
cluster_is_dedicated "$ctx" && return 0
|
|
81
79
|
cluster="$(kubectl config view -o jsonpath="{.contexts[?(@.name==\"$ctx\")].context.cluster}" 2>/dev/null || true)"
|
|
82
80
|
[ -n "$cluster" ] || return 1
|
|
83
|
-
|
|
84
|
-
[ -n "$
|
|
85
|
-
#
|
|
81
|
+
server="$(kubectl config view -o jsonpath="{.clusters[?(@.name==\"$cluster\")].cluster.server}" 2>/dev/null || true)"
|
|
82
|
+
[ -n "$server" ] || return 1
|
|
83
|
+
# Rule by name (old rule of metrics-server.sh)
|
|
86
84
|
case "$ctx" in
|
|
87
85
|
kind-* | docker-desktop | rancher-desktop | orbstack | minikube) return 0 ;;
|
|
88
86
|
esac
|
|
89
|
-
#
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
if [[ "$
|
|
93
|
-
|
|
94
|
-
|
|
87
|
+
# Host extraction (IPv6 addresses in brackets handled)
|
|
88
|
+
host="${server#*://}"
|
|
89
|
+
host="${host%%/*}"
|
|
90
|
+
if [[ "$host" == \[* ]]; then
|
|
91
|
+
host="${host#[}"
|
|
92
|
+
host="${host%%]*}"
|
|
95
93
|
else
|
|
96
|
-
|
|
94
|
+
host="${host%%:*}"
|
|
97
95
|
fi
|
|
98
|
-
case "$
|
|
96
|
+
case "$host" in
|
|
99
97
|
127.0.0.1 | localhost | ::1 | host.docker.internal) return 0 ;;
|
|
100
98
|
*-control-plane) return 0 ;;
|
|
101
99
|
esac
|
|
102
100
|
return 1
|
|
103
101
|
}
|
|
104
102
|
|
|
105
|
-
#
|
|
106
|
-
#
|
|
107
|
-
#
|
|
108
|
-
|
|
103
|
+
# Sets the « devzone » context (cluster + user) on the given context (default:
|
|
104
|
+
# the current one): after an installation on a new machine, --context devzone
|
|
105
|
+
# targets the chosen services cluster from the start (#396)
|
|
106
|
+
devzone_context_set() {
|
|
109
107
|
local ctx cluster user
|
|
110
108
|
ctx="${1:-$(kubectl config current-context 2>/dev/null || true)}"
|
|
111
109
|
if [ -z "$ctx" ]; then
|
|
@@ -120,29 +118,29 @@ contexte_devzone_poser() {
|
|
|
120
118
|
fi
|
|
121
119
|
}
|
|
122
120
|
|
|
123
|
-
|
|
121
|
+
cluster_reachable() {
|
|
124
122
|
kubectl --context "$1" --request-timeout=3s get --raw /readyz >/dev/null 2>&1
|
|
125
123
|
}
|
|
126
124
|
|
|
127
|
-
#
|
|
128
|
-
|
|
129
|
-
local
|
|
130
|
-
if [ -f "$
|
|
131
|
-
# 1.
|
|
132
|
-
for c in $(KUBECONFIG="$
|
|
133
|
-
|
|
134
|
-
if
|
|
125
|
+
# Host contexts: local ones first, then the dedicated kind, finally the remote ones
|
|
126
|
+
cluster_candidates() {
|
|
127
|
+
local host="${DEVZONE_KUBE_HOST:-$HOME/.kube/hote.config}" c
|
|
128
|
+
if [ -f "$host" ]; then
|
|
129
|
+
# 1. Local clusters of the host (server on a loopback address)
|
|
130
|
+
for c in $(KUBECONFIG="$host" kubectl config get-contexts -o name 2>/dev/null); do
|
|
131
|
+
cluster_is_dedicated "$c" && continue
|
|
132
|
+
if cluster_is_local "$c" && cluster_reachable "$c"; then
|
|
135
133
|
echo "$c"
|
|
136
134
|
fi
|
|
137
135
|
done
|
|
138
136
|
fi
|
|
139
|
-
# 2.
|
|
140
|
-
echo "$
|
|
141
|
-
if [ -f "$
|
|
142
|
-
# 3.
|
|
143
|
-
for c in $(KUBECONFIG="$
|
|
144
|
-
|
|
145
|
-
if !
|
|
137
|
+
# 2. Dedicated kind cluster
|
|
138
|
+
echo "$CLUSTER_DEDICATED"
|
|
139
|
+
if [ -f "$host" ]; then
|
|
140
|
+
# 3. Remote clusters of the host
|
|
141
|
+
for c in $(KUBECONFIG="$host" kubectl config get-contexts -o name 2>/dev/null); do
|
|
142
|
+
cluster_is_dedicated "$c" && continue
|
|
143
|
+
if ! cluster_is_local "$c" && cluster_reachable "$c"; then
|
|
146
144
|
echo "$c"
|
|
147
145
|
fi
|
|
148
146
|
done
|
|
@@ -150,220 +148,220 @@ cluster_candidats() {
|
|
|
150
148
|
return 0
|
|
151
149
|
}
|
|
152
150
|
|
|
153
|
-
# Menu
|
|
151
|
+
# Menu on stderr (stdout carries the answer); Enter = first candidate
|
|
154
152
|
cluster_menu() {
|
|
155
|
-
local
|
|
156
|
-
while IFS= read -r c; do
|
|
153
|
+
local candidates=() c i=1 answer
|
|
154
|
+
while IFS= read -r c; do candidates+=("$c"); done < <(cluster_candidates)
|
|
157
155
|
{
|
|
158
|
-
echo "devzone :
|
|
159
|
-
for c in "${
|
|
160
|
-
if
|
|
161
|
-
echo " $i) $c
|
|
162
|
-
elif
|
|
163
|
-
echo " $i) $c cluster
|
|
156
|
+
echo "devzone : on which cluster should the devzone services be installed?"
|
|
157
|
+
for c in "${candidates[@]}"; do
|
|
158
|
+
if cluster_is_dedicated "$c"; then
|
|
159
|
+
echo " $i) $c dedicated kind cluster, in the container (default)"
|
|
160
|
+
elif cluster_is_local "$c"; then
|
|
161
|
+
echo " $i) $c local cluster"
|
|
164
162
|
else
|
|
165
|
-
echo " $i) $c cluster
|
|
163
|
+
echo " $i) $c remote cluster"
|
|
166
164
|
fi
|
|
167
165
|
i=$((i + 1))
|
|
168
166
|
done
|
|
169
|
-
[ -f "${
|
|
170
|
-
echo " (clusters
|
|
167
|
+
[ -f "${DEVZONE_KUBE_HOST:-$HOME/.kube/hote.config}" ] ||
|
|
168
|
+
echo " (host clusters not visible: devzone enable kubernetes)"
|
|
171
169
|
} >&2
|
|
172
|
-
printf '
|
|
173
|
-
read -r
|
|
174
|
-
|
|
175
|
-
case "$
|
|
176
|
-
*[!0-9]* | 0) echo "devzone :
|
|
170
|
+
printf 'Number [1]: ' >&2
|
|
171
|
+
read -r answer || answer=""
|
|
172
|
+
answer="${answer:-1}"
|
|
173
|
+
case "$answer" in
|
|
174
|
+
*[!0-9]* | 0) echo "devzone : invalid choice: $answer" >&2; return 2 ;;
|
|
177
175
|
esac
|
|
178
|
-
if [ "$
|
|
179
|
-
echo "devzone :
|
|
176
|
+
if [ "$answer" -gt "${#candidates[@]}" ]; then
|
|
177
|
+
echo "devzone : invalid choice: $answer" >&2
|
|
180
178
|
return 2
|
|
181
179
|
fi
|
|
182
|
-
echo "${
|
|
180
|
+
echo "${candidates[$((answer - 1))]}"
|
|
183
181
|
}
|
|
184
182
|
|
|
185
|
-
#
|
|
186
|
-
|
|
187
|
-
[ "${
|
|
183
|
+
# Interactive terminal; DEVZONE_INTERACTIVE=1 for the tests (stdin redirected)
|
|
184
|
+
cluster_interactive() {
|
|
185
|
+
[ "${DEVZONE_INTERACTIVE:-}" = 1 ] || [ -t 0 ]
|
|
188
186
|
}
|
|
189
187
|
|
|
190
|
-
|
|
191
|
-
local
|
|
188
|
+
cluster_choose() {
|
|
189
|
+
local wanted="" confirm="" c answer arg
|
|
192
190
|
while [ "$#" -gt 0 ]; do
|
|
193
191
|
arg="$1"
|
|
194
192
|
shift
|
|
195
193
|
case "$arg" in
|
|
196
194
|
--confirm)
|
|
197
195
|
if [ "$#" -eq 0 ]; then
|
|
198
|
-
echo "devzone : --confirm
|
|
196
|
+
echo "devzone : --confirm needs a context" >&2
|
|
199
197
|
return 2
|
|
200
198
|
fi
|
|
201
|
-
|
|
199
|
+
confirm="$1"
|
|
202
200
|
shift
|
|
203
201
|
;;
|
|
204
|
-
--confirm=*)
|
|
202
|
+
--confirm=*) confirm="${arg#*=}" ;;
|
|
205
203
|
-*)
|
|
206
|
-
echo "devzone : argument
|
|
204
|
+
echo "devzone : unknown argument: $arg (cluster_choose [CTX] [--confirm CTX])" >&2
|
|
207
205
|
return 2
|
|
208
206
|
;;
|
|
209
207
|
*)
|
|
210
|
-
if [ -n "$
|
|
211
|
-
echo "devzone : argument
|
|
208
|
+
if [ -n "$wanted" ]; then
|
|
209
|
+
echo "devzone : unknown argument: $arg (cluster_choose [CTX] [--confirm CTX])" >&2
|
|
212
210
|
return 2
|
|
213
211
|
fi
|
|
214
|
-
|
|
212
|
+
wanted="$arg"
|
|
215
213
|
;;
|
|
216
214
|
esac
|
|
217
215
|
done
|
|
218
|
-
if [ -n "$
|
|
216
|
+
if [ -n "$wanted" ]; then
|
|
219
217
|
while IFS= read -r c; do
|
|
220
|
-
[ "$c" = "$
|
|
221
|
-
done < <(
|
|
222
|
-
if [ "$c" != "$
|
|
223
|
-
echo "devzone :
|
|
218
|
+
[ "$c" = "$wanted" ] && break
|
|
219
|
+
done < <(cluster_candidates)
|
|
220
|
+
if [ "$c" != "$wanted" ]; then
|
|
221
|
+
echo "devzone : unknown or unreachable cluster: $wanted; candidates: $(cluster_candidates | tr '\n' ' ')" >&2
|
|
224
222
|
return 2
|
|
225
223
|
fi
|
|
226
|
-
#
|
|
227
|
-
#
|
|
228
|
-
#
|
|
229
|
-
if !
|
|
230
|
-
if [ -n "$
|
|
231
|
-
if [ "$
|
|
232
|
-
echo "devzone : cluster
|
|
224
|
+
# Remote: confirmation required. --confirm counts only if it is exactly
|
|
225
|
+
# the requested context; DEVZONE_CLUSTER_REMOTE is still accepted for
|
|
226
|
+
# the tests and CI
|
|
227
|
+
if ! cluster_is_local "$wanted"; then
|
|
228
|
+
if [ -n "$confirm" ]; then
|
|
229
|
+
if [ "$confirm" != "$wanted" ]; then
|
|
230
|
+
echo "devzone : remote cluster refused: $wanted (--confirm $wanted)" >&2
|
|
233
231
|
return 2
|
|
234
232
|
fi
|
|
235
|
-
elif [ -n "${
|
|
236
|
-
if [ "${
|
|
237
|
-
echo "devzone : cluster
|
|
233
|
+
elif [ -n "${DEVZONE_CLUSTER_REMOTE:-}" ]; then
|
|
234
|
+
if [ "${DEVZONE_CLUSTER_REMOTE}" != "$wanted" ]; then
|
|
235
|
+
echo "devzone : remote cluster refused: $wanted (DEVZONE_CLUSTER_REMOTE must be exactly $wanted)" >&2
|
|
238
236
|
return 2
|
|
239
237
|
fi
|
|
240
|
-
elif
|
|
241
|
-
printf 'cluster
|
|
242
|
-
read -r
|
|
243
|
-
if [ "$
|
|
244
|
-
echo "devzone : cluster
|
|
238
|
+
elif cluster_interactive; then
|
|
239
|
+
printf 'remote cluster: %s ; type its name to confirm: ' "$wanted" >&2
|
|
240
|
+
read -r answer || answer=""
|
|
241
|
+
if [ "$answer" != "$wanted" ]; then
|
|
242
|
+
echo "devzone : remote cluster refused: $wanted (--confirm $wanted)" >&2
|
|
245
243
|
return 2
|
|
246
244
|
fi
|
|
247
245
|
else
|
|
248
|
-
echo "devzone : cluster
|
|
246
|
+
echo "devzone : remote cluster refused: $wanted (--confirm $wanted)" >&2
|
|
249
247
|
return 2
|
|
250
248
|
fi
|
|
251
249
|
fi
|
|
252
|
-
echo "$
|
|
250
|
+
echo "$wanted"
|
|
253
251
|
return 0
|
|
254
252
|
fi
|
|
255
|
-
c="$(
|
|
253
|
+
c="$(cluster_saved)"
|
|
256
254
|
if [ -n "$c" ]; then
|
|
257
255
|
echo "$c"
|
|
258
|
-
elif
|
|
256
|
+
elif cluster_interactive; then
|
|
259
257
|
cluster_menu
|
|
260
258
|
else
|
|
261
|
-
#
|
|
262
|
-
local
|
|
263
|
-
if [ -f "${
|
|
264
|
-
|
|
259
|
+
# Default: local only (never remote by default)
|
|
260
|
+
local host_choice=""
|
|
261
|
+
if [ -f "${DEVZONE_KUBE_HOST:-$HOME/.kube/hote.config}" ]; then
|
|
262
|
+
host_choice="$(KUBECONFIG="${DEVZONE_KUBE_HOST:-$HOME/.kube/hote.config}" kubectl config current-context 2>/dev/null || true)"
|
|
265
263
|
fi
|
|
266
|
-
if [ -n "$
|
|
267
|
-
echo "$
|
|
264
|
+
if [ -n "$host_choice" ] && cluster_is_local "$host_choice" && cluster_reachable "$host_choice"; then
|
|
265
|
+
echo "$host_choice"
|
|
268
266
|
else
|
|
269
|
-
echo "$
|
|
267
|
+
echo "$CLUSTER_DEDICATED"
|
|
270
268
|
fi
|
|
271
269
|
fi
|
|
272
270
|
}
|
|
273
271
|
|
|
274
|
-
#
|
|
275
|
-
#
|
|
276
|
-
#
|
|
277
|
-
|
|
278
|
-
local
|
|
279
|
-
|
|
272
|
+
# Runs kind without switching kubectl's current context (#366): the previous
|
|
273
|
+
# one is restored, or removed if there was none. The kind exit code is returned
|
|
274
|
+
# even under set -e: the restore happens first.
|
|
275
|
+
kind_keep_context() {
|
|
276
|
+
local previous code=0
|
|
277
|
+
previous="$(kubectl config current-context 2>/dev/null || true)"
|
|
280
278
|
kind "$@" || code=$?
|
|
281
|
-
if [ -n "$
|
|
282
|
-
kubectl config use-context "$
|
|
279
|
+
if [ -n "$previous" ]; then
|
|
280
|
+
kubectl config use-context "$previous" >/dev/null 2>&1 || true
|
|
283
281
|
else
|
|
284
282
|
KUBECONFIG="$HOME/.kube/config" kubectl config unset current-context >/dev/null 2>&1 || true
|
|
285
283
|
fi
|
|
286
284
|
return "$code"
|
|
287
285
|
}
|
|
288
286
|
|
|
289
|
-
#
|
|
290
|
-
|
|
291
|
-
|
|
287
|
+
# Creates a kind cluster without switching kubectl's current context.
|
|
288
|
+
kind_create_keep_context() {
|
|
289
|
+
kind_keep_context create cluster "$@"
|
|
292
290
|
}
|
|
293
291
|
|
|
294
|
-
|
|
292
|
+
cluster_prepare() {
|
|
295
293
|
local ctx="$1"
|
|
296
|
-
if [ "$ctx" = "$
|
|
294
|
+
if [ "$ctx" = "$CLUSTER_DEDICATED" ]; then
|
|
297
295
|
if ! kind get clusters 2>/dev/null | grep -qx "devzone${INSTANCE_SUFFIX}"; then
|
|
298
|
-
echo "▶
|
|
299
|
-
#
|
|
300
|
-
#
|
|
301
|
-
# (host.docker.internal),
|
|
302
|
-
#
|
|
303
|
-
#
|
|
304
|
-
#
|
|
305
|
-
if !
|
|
306
|
-
echo "▶
|
|
296
|
+
echo "▶ Creating the kind devzone cluster (about 1 min)…"
|
|
297
|
+
# On the host Docker, the API listens on the workstation's 127.0.0.1:
|
|
298
|
+
# kube_reachable_from_container makes it reachable from the container
|
|
299
|
+
# (host.docker.internal), without exposing it on the local network.
|
|
300
|
+
# Busy host Docker (its Kubernetes, other clusters): the node API can
|
|
301
|
+
# restart during initialization and kind gives up within seconds. A
|
|
302
|
+
# second attempt, on a fresh cluster.
|
|
303
|
+
if ! kind_create_keep_context --name "devzone${INSTANCE_SUFFIX}" --wait 120s; then
|
|
304
|
+
echo "▶ Retrying the kind cluster creation…"
|
|
307
305
|
kind delete cluster --name "devzone${INSTANCE_SUFFIX}" >/dev/null 2>&1 || true
|
|
308
|
-
|
|
306
|
+
kind_create_keep_context --name "devzone${INSTANCE_SUFFIX}" --wait 120s || return 1
|
|
309
307
|
fi
|
|
310
|
-
|
|
308
|
+
kube_reachable_from_container "$HOME/.kube/config"
|
|
311
309
|
fi
|
|
312
|
-
elif !
|
|
313
|
-
echo "devzone : cluster $ctx
|
|
310
|
+
elif ! cluster_reachable "$ctx"; then
|
|
311
|
+
echo "devzone : cluster $ctx unreachable (kubernetes module enabled? cluster started?)" >&2
|
|
314
312
|
return 1
|
|
315
313
|
fi
|
|
316
|
-
#
|
|
317
|
-
#
|
|
318
|
-
|
|
314
|
+
# If it has just been created, the services cluster must carry the devzone
|
|
315
|
+
# context at once, otherwise the installation targets the old cluster (#396)
|
|
316
|
+
devzone_context_set "$ctx" || echo "devzone : devzone context not set on $ctx" >&2
|
|
319
317
|
}
|
|
320
318
|
|
|
321
|
-
#
|
|
322
|
-
#
|
|
323
|
-
|
|
324
|
-
local ctx="$1"
|
|
325
|
-
|
|
319
|
+
# Dedicated kind with no devzone namespace left: deleted (it only uses memory).
|
|
320
|
+
# Never a host cluster.
|
|
321
|
+
cluster_release() {
|
|
322
|
+
local ctx="$1" left
|
|
323
|
+
cluster_is_dedicated "$ctx" || return 0
|
|
326
324
|
kind get clusters 2>/dev/null | grep -qx "devzone${INSTANCE_SUFFIX}" || return 0
|
|
327
|
-
#
|
|
328
|
-
#
|
|
329
|
-
|
|
330
|
-
if [ -z "$
|
|
325
|
+
# Reading the namespaces labelled by the administrator (#430): the namespace
|
|
326
|
+
# list is refused to the limited account
|
|
327
|
+
left="$(account_admin "$ctx" get namespaces -l "$CLUSTER_LABEL" -o name 2>/dev/null || true)"
|
|
328
|
+
if [ -z "$left" ]; then
|
|
331
329
|
kind delete cluster --name "devzone${INSTANCE_SUFFIX}" >/dev/null 2>&1 || true
|
|
332
|
-
echo "▶
|
|
330
|
+
echo "▶ kind devzone cluster removed (no service left)."
|
|
333
331
|
fi
|
|
334
332
|
}
|
|
335
333
|
|
|
336
|
-
# ----
|
|
337
|
-
# kubectl port-forward
|
|
338
|
-
#
|
|
339
|
-
#
|
|
340
|
-
#
|
|
341
|
-
|
|
334
|
+
# ---- Relay: port of a cluster service on the container's 127.0.0.1 ----
|
|
335
|
+
# kubectl port-forward works on every cluster whose API answers (dedicated kind
|
|
336
|
+
# or host cluster), without exposing a port on the nodes. It stops when the pod
|
|
337
|
+
# restarts: the loop restarts it. PID and log in workspace/.<name>/ (module
|
|
338
|
+
# folder, ignored by git).
|
|
339
|
+
relay_dir() {
|
|
342
340
|
echo "$RACINE/workspace/.$1"
|
|
343
341
|
}
|
|
344
342
|
|
|
345
|
-
|
|
343
|
+
relay_active() {
|
|
346
344
|
local pid
|
|
347
|
-
pid="$(cat "$(
|
|
345
|
+
pid="$(cat "$(relay_dir "$1")/relais.pid" 2>/dev/null || true)"
|
|
348
346
|
[ -n "$pid" ] && kill -0 "$pid" 2>/dev/null
|
|
349
347
|
}
|
|
350
348
|
|
|
351
|
-
|
|
352
|
-
local
|
|
349
|
+
relay_start() {
|
|
350
|
+
local name="$1" ctx="$2" ns="$3" target="$4" dir
|
|
353
351
|
shift 4
|
|
354
|
-
|
|
355
|
-
mkdir -p "$
|
|
356
|
-
|
|
357
|
-
# setsid
|
|
358
|
-
#
|
|
359
|
-
local
|
|
360
|
-
command -v setsid >/dev/null 2>&1 &&
|
|
361
|
-
# port-forward
|
|
362
|
-
#
|
|
363
|
-
# pod
|
|
364
|
-
#
|
|
365
|
-
# shellcheck disable=SC2016 # variables
|
|
366
|
-
${
|
|
352
|
+
dir="$(relay_dir "$name")"
|
|
353
|
+
mkdir -p "$dir"
|
|
354
|
+
relay_active "$name" && return 0
|
|
355
|
+
# setsid: separate session, the relay survives the end of the script that
|
|
356
|
+
# started it (postStartCommand, make shell); absent on macOS (bash 3.2 tests)
|
|
357
|
+
local detached=()
|
|
358
|
+
command -v setsid >/dev/null 2>&1 && detached=(setsid)
|
|
359
|
+
# port-forward targets one precise pod and sees its disappearance only at the
|
|
360
|
+
# next connection, which fails. For a service, the loop therefore follows the
|
|
361
|
+
# ready pod behind it (UID in its endpoints): waits until there is one, then
|
|
362
|
+
# restarts port-forward as soon as it changes (pod restarted).
|
|
363
|
+
# shellcheck disable=SC2016 # variables expanded by the relay's bash
|
|
364
|
+
${detached[@]+"${detached[@]}"} nohup bash -c '
|
|
367
365
|
pod() {
|
|
368
366
|
case "$2" in
|
|
369
367
|
svc/*) kubectl --context "$0" -n "$1" get endpoints "${2#svc/}" -o jsonpath="{.subsets[*].addresses[*].targetRef.uid}" 2>/dev/null ;;
|
|
@@ -382,22 +380,22 @@ relais_lancer() {
|
|
|
382
380
|
wait "$pf" 2>/dev/null
|
|
383
381
|
sleep 1
|
|
384
382
|
done' \
|
|
385
|
-
"$ctx" "$ns" "$
|
|
386
|
-
echo "$!" >"$
|
|
383
|
+
"$ctx" "$ns" "$target" "$@" >"$dir/relais.log" 2>&1 &
|
|
384
|
+
echo "$!" >"$dir/relais.pid"
|
|
387
385
|
}
|
|
388
386
|
|
|
389
|
-
|
|
390
|
-
local
|
|
391
|
-
|
|
392
|
-
pid="$(cat "$
|
|
387
|
+
relay_stop() {
|
|
388
|
+
local file pid children
|
|
389
|
+
file="$(relay_dir "$1")/relais.pid"
|
|
390
|
+
pid="$(cat "$file" 2>/dev/null || true)"
|
|
393
391
|
if [ -n "$pid" ]; then
|
|
394
|
-
#
|
|
395
|
-
#
|
|
396
|
-
#
|
|
397
|
-
|
|
392
|
+
# Children (port-forward) listed before: once the loop is killed, they
|
|
393
|
+
# are reattached to init and pgrep -P no longer sees them. The loop first,
|
|
394
|
+
# otherwise it would restart the port-forward.
|
|
395
|
+
children="$(pgrep -P "$pid" 2>/dev/null || true)"
|
|
398
396
|
kill "$pid" 2>/dev/null || true
|
|
399
|
-
# shellcheck disable=SC2086 #
|
|
400
|
-
[ -z "$
|
|
397
|
+
# shellcheck disable=SC2086 # list of PIDs
|
|
398
|
+
[ -z "$children" ] || kill $children 2>/dev/null || true
|
|
401
399
|
fi
|
|
402
|
-
rm -f "$
|
|
400
|
+
rm -f "$file"
|
|
403
401
|
}
|