devzone 7.5.0 → 7.5.2
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 +15 -16
- package/.devcontainer/devzone-status.sh +3 -3
- package/.devcontainer/services-admin.sh +1 -1
- 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/manage/devzone +33 -13
- package/manage/scripts/workspace/argocd-services.sh +1 -1
- package/manage/scripts/workspace/argocd-workspace.sh +1 -1
- package/manage/workspace.sh +11 -27
- package/package.json +1 -1
- package/.devcontainer/devzone-repair.sh +0 -85
- package/.devcontainer/devzone-version.sh +0 -78
- package/.devcontainer/help.sh +0 -46
- package/manage/scripts/create-mode.sh +0 -103
- package/manage/scripts/devzone-create.sh +0 -110
- package/manage/scripts/devzone-update.sh +0 -237
- package/manage/scripts/kube-ready.sh +0 -75
- package/manage/scripts/workspace/ports-apps.sh +0 -156
- package/manage/scripts/workspace/ports-workspace.sh +0 -235
- package/manage/scripts/workspace/services-workspace.sh +0 -193
- package/manage/scripts/workspace/workspace-clone.sh +0 -12
- package/manage/scripts/workspace/workspace-copies.sh +0 -44
- package/manage/scripts/workspace/workspace-egress.sh +0 -184
- package/manage/scripts/workspace/workspace-update.sh +0 -106
- package/manage/scripts/workspace/workspace-wait.sh +0 -56
|
@@ -1,156 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env bash
|
|
2
|
-
# Applications of the Kubernetes workspace relayed on workstation localhost (#611).
|
|
3
|
-
# Sourced by ports-workspace.sh, never run alone. One kubectl get svc -A per
|
|
4
|
-
# round: each TCP port of each Service gets a local port, kept stable in
|
|
5
|
-
# .devzone.workspace-ports/apps/<namespace>.<service>.<port> while the Service
|
|
6
|
-
# exists. Only Services with a ready endpoint are relayed (#638): the others keep
|
|
7
|
-
# their local port and show as "no ready pod" in status. Output lines:
|
|
8
|
-
# "portlocal|namespace|svc/name|remoteport", as pw_services.
|
|
9
|
-
|
|
10
|
-
PA_MAX=30
|
|
11
|
-
# Namespaces never relayed: system ones, and those of the devzone modules
|
|
12
|
-
# (relayed by pw_services, or without any interface).
|
|
13
|
-
PA_NS_SKIP=" kube-system kube-public kube-node-lease local-path-storage devzone-system devzone-workspace devzone-postgres devzone-mysql devzone-argocd devzone-gitlab devzone-llm "
|
|
14
|
-
|
|
15
|
-
# Services of the cluster, one "namespace|name|clusterIP|type|relay annotation|port/proto," line each.
|
|
16
|
-
pa_discover() {
|
|
17
|
-
pw_kubectl get svc -A -o 'jsonpath={range .items[*]}{.metadata.namespace}|{.metadata.name}|{.spec.clusterIP}|{.spec.type}|{.metadata.annotations.devzone\.io/relay}|{range .spec.ports[*]}{.port}/{.protocol},{end}{"\n"}{end}' 2>/dev/null
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
# Services with a ready endpoint, as " namespace/name " items, from one kubectl get
|
|
21
|
-
# endpointslices call. A Service with several slices is ready if one of its slices has
|
|
22
|
-
# a ready endpoint. Exit 1 if the call fails: the caller then relays every Service.
|
|
23
|
-
pa_ready() {
|
|
24
|
-
local out ns name conds set=" "
|
|
25
|
-
out="$(pw_kubectl get endpointslices -A -o 'jsonpath={range .items[*]}{.metadata.namespace}|{.metadata.labels.kubernetes\.io/service-name}|{range .endpoints[*]}{.conditions.ready},{end}{"\n"}{end}' 2>/dev/null)" || return 1
|
|
26
|
-
while IFS='|' read -r ns name conds; do
|
|
27
|
-
[ -n "$ns" ] || continue
|
|
28
|
-
[ -n "$name" ] || continue
|
|
29
|
-
case "$conds" in *true*) set="$set$ns/$name " ;; esac
|
|
30
|
-
done <<<"$out"
|
|
31
|
-
echo "$set"
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
# Is the Service excluded? $1 namespace, $2 name, $3 clusterIP, $4 type, $5 relay annotation.
|
|
35
|
-
pa_excluded() {
|
|
36
|
-
case "$PA_NS_SKIP" in *" $1 "*) return 0 ;; esac
|
|
37
|
-
[ "$1/$2" != default/kubernetes ] || return 0
|
|
38
|
-
[ "$5" != false ] || return 0
|
|
39
|
-
case "$4" in ExternalName) return 0 ;; esac
|
|
40
|
-
case "$3" in '' | None) return 0 ;; esac
|
|
41
|
-
return 1
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
# Is local port $1 free for an application? Not in the list "$2" (" p p "), not taken on the workstation.
|
|
45
|
-
pa_free() {
|
|
46
|
-
case "$2" in *" $1 "*) return 1 ;; esac
|
|
47
|
-
! pw_taken "$1"
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
# First free local port for Service port $1, given the ports in use "$2": the port itself
|
|
51
|
-
# when >= 1024, else $1 + 8000 (80 -> 8080), then incrementing; past 65000, from 20000.
|
|
52
|
-
pa_new() {
|
|
53
|
-
local c=$(($1 + 8000)) i=0
|
|
54
|
-
if [ "$1" -ge 1024 ] && pa_free "$1" "$2"; then
|
|
55
|
-
echo "$1"
|
|
56
|
-
return 0
|
|
57
|
-
fi
|
|
58
|
-
[ "$c" -le 65000 ] || c=20000
|
|
59
|
-
while [ "$i" -lt 60000 ]; do
|
|
60
|
-
if pa_free "$c" "$2"; then
|
|
61
|
-
echo "$c"
|
|
62
|
-
return 0
|
|
63
|
-
fi
|
|
64
|
-
c=$((c + 1))
|
|
65
|
-
i=$((i + 1))
|
|
66
|
-
[ "$c" -le 65000 ] || c=20000
|
|
67
|
-
done
|
|
68
|
-
return 1
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
# One round of applications, from the ports already wanted "$1" (services, pod).
|
|
72
|
-
# Prints the relay lines; writes apps/ (stable local port), cap/ (cap marker) and
|
|
73
|
-
# no-ready-pod/ (Service without ready endpoint, not relayed nor counted), removes the
|
|
74
|
-
# state of Services gone, warns once per port over the cap of PA_MAX.
|
|
75
|
-
pa_round() {
|
|
76
|
-
local d used excl ns name ip type annot ports pp port key stored loc n=0 seen="" f
|
|
77
|
-
local ready="" ready_ok=1 unready
|
|
78
|
-
d="$(pw_dir)"
|
|
79
|
-
mkdir -p "$d/apps" "$d/cap"
|
|
80
|
-
excl="$(grep -E '^excluded_ports=' .devzone.modules 2>/dev/null | tail -1 | cut -d= -f2- | tr ',' ' ')"
|
|
81
|
-
used=" $1 $excl "
|
|
82
|
-
# One kubectl call per round. If it fails, every Service is relayed, warned once.
|
|
83
|
-
if ready="$(pa_ready)"; then
|
|
84
|
-
rm -f "$d/endpoints-unreadable"
|
|
85
|
-
else
|
|
86
|
-
ready_ok=0
|
|
87
|
-
if [ ! -e "$d/endpoints-unreadable" ]; then
|
|
88
|
-
: >"$d/endpoints-unreadable"
|
|
89
|
-
echo "⚠ endpointslices unreadable, ready pods not checked" >&2
|
|
90
|
-
fi
|
|
91
|
-
fi
|
|
92
|
-
while IFS='|' read -r ns name ip type annot ports; do
|
|
93
|
-
[ -n "$ns" ] || continue
|
|
94
|
-
pa_excluded "$ns" "$name" "$ip" "$type" "$annot" && continue
|
|
95
|
-
for pp in ${ports//,/ }; do
|
|
96
|
-
case "$pp" in */TCP) ;; *) continue ;; esac
|
|
97
|
-
port="${pp%/*}"
|
|
98
|
-
case "$port" in '' | *[!0-9]*) continue ;; esac
|
|
99
|
-
key="$ns.$name.$port"
|
|
100
|
-
seen="$seen $key "
|
|
101
|
-
stored="$(cat "$d/apps/$key" 2>/dev/null || true)"
|
|
102
|
-
loc=""
|
|
103
|
-
case "$stored" in '' | *[!0-9]*) ;; *) case "$used" in *" $stored "*) ;; *) loc="$stored" ;; esac ;; esac
|
|
104
|
-
if [ -z "$loc" ]; then
|
|
105
|
-
loc="$(pa_new "$port" "$used")" || { echo "⚠ no free local port for $ns/$name:$port" >&2; continue; }
|
|
106
|
-
fi
|
|
107
|
-
used="$used $loc "
|
|
108
|
-
[ "$loc" = "$stored" ] || printf '%s' "$loc" >"$d/apps/$key"
|
|
109
|
-
unready=0
|
|
110
|
-
if [ "$ready_ok" -eq 1 ]; then
|
|
111
|
-
case "$ready" in *" $ns/$name "*) ;; *) unready=1 ;; esac
|
|
112
|
-
fi
|
|
113
|
-
if [ "$unready" -eq 1 ]; then
|
|
114
|
-
mkdir -p "$d/no-ready-pod"
|
|
115
|
-
: >"$d/no-ready-pod/$key"
|
|
116
|
-
continue
|
|
117
|
-
fi
|
|
118
|
-
rm -f "$d/no-ready-pod/$key"
|
|
119
|
-
if [ "$n" -lt "$PA_MAX" ]; then
|
|
120
|
-
n=$((n + 1))
|
|
121
|
-
rm -f "$d/cap/$key"
|
|
122
|
-
echo "$loc|$ns|svc/$name|$port"
|
|
123
|
-
elif [ ! -e "$d/cap/$key" ]; then
|
|
124
|
-
: >"$d/cap/$key"
|
|
125
|
-
echo "⚠ cap of $PA_MAX application relays reached, $ns/$name:$port not relayed" >&2
|
|
126
|
-
fi
|
|
127
|
-
done
|
|
128
|
-
done <<<"$(pa_discover)"
|
|
129
|
-
for f in "$d"/apps/* "$d"/cap/* "$d"/no-ready-pod/*; do
|
|
130
|
-
[ -e "$f" ] || continue
|
|
131
|
-
case "$seen" in *" $(basename "$f") "*) ;; *) rm -f "$f" ;; esac
|
|
132
|
-
done
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
# Status lines of relayed applications: local URL, then namespace/service:port.
|
|
136
|
-
# Then the Services without ready pod, with the local URL they would get.
|
|
137
|
-
pa_status() {
|
|
138
|
-
local d f key rest loc
|
|
139
|
-
d="$(pw_dir)"
|
|
140
|
-
for f in "$d"/apps/*; do
|
|
141
|
-
[ -e "$f" ] || continue
|
|
142
|
-
loc="$(cat "$f")"
|
|
143
|
-
pw_alive "$(cat "$d/relays/$loc" 2>/dev/null)" || continue
|
|
144
|
-
key="$(basename "$f")"
|
|
145
|
-
rest="${key#*.}"
|
|
146
|
-
echo " http://127.0.0.1:$loc ${key%%.*}/${rest%%.*}:${rest#*.}"
|
|
147
|
-
done
|
|
148
|
-
for f in "$d"/no-ready-pod/*; do
|
|
149
|
-
[ -e "$f" ] || continue
|
|
150
|
-
key="$(basename "$f")"
|
|
151
|
-
loc="$(cat "$d/apps/$key" 2>/dev/null || true)"
|
|
152
|
-
[ -n "$loc" ] || continue
|
|
153
|
-
rest="${key#*.}"
|
|
154
|
-
echo " http://127.0.0.1:$loc ${key%%.*}/${rest%%.*}:${rest#*.} no ready pod"
|
|
155
|
-
done
|
|
156
|
-
}
|
|
@@ -1,235 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env bash
|
|
2
|
-
# Applications and services of the Kubernetes workspace on workstation localhost (#401).
|
|
3
|
-
# Sourced by manage/workspace.sh (ports_* functions); run directly with "loop" or
|
|
4
|
-
# "round", it is the workstation watcher: only one, mkdir lock and pid in
|
|
5
|
-
# .devzone.workspace-ports/. It relays with kubectl port-forward, on 127.0.0.1
|
|
6
|
-
# only, TCP ports >= 1024 listening in the pod, and devzone services of active
|
|
7
|
-
# modules in .devzone.modules. Guard: never under bats without
|
|
8
|
-
# DEVZONE_PORTS_WORKSPACE_REAL=yes.
|
|
9
|
-
|
|
10
|
-
PW_POD="devzone-workspace-0"
|
|
11
|
-
PW_NS="devzone-workspace"
|
|
12
|
-
# Internal pod ports, never relayed: kubedock and buildkit.
|
|
13
|
-
PW_INTERNAL=" 2475 1234 "
|
|
14
|
-
# pgAdmin service port: read from the service, without it nothing is relayed.
|
|
15
|
-
PW_JSONPATH='jsonpath={.spec.ports[0].port}'
|
|
16
|
-
# Cluster Services relayed as applications (#611).
|
|
17
|
-
# shellcheck source=manage/scripts/workspace/ports-apps.sh
|
|
18
|
-
. "$(dirname "${BASH_SOURCE[0]}")/ports-apps.sh"
|
|
19
|
-
|
|
20
|
-
# Watcher state folder: lock, pid, relays, reported ports, log.
|
|
21
|
-
pw_dir() { printf '%s' "${DEVZONE_PORTS_WORKSPACE_DIR:-$PWD/.devzone.workspace-ports}"; }
|
|
22
|
-
|
|
23
|
-
# kubectl context flag: devzone if it exists, otherwise current context.
|
|
24
|
-
pw_ctx() {
|
|
25
|
-
if kubectl config get-contexts -o name 2>/dev/null | grep -qx 'devzone'; then
|
|
26
|
-
printf -- '--context devzone'
|
|
27
|
-
fi
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
# Watcher kubectl: devzone context if it exists, then given arguments.
|
|
31
|
-
pw_kubectl() {
|
|
32
|
-
# shellcheck disable=SC2046
|
|
33
|
-
kubectl $(pw_ctx) "$@"
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
# Guard: refuse under bats without DEVZONE_PORTS_WORKSPACE_REAL=yes (message if $1 empty).
|
|
37
|
-
pw_guard() {
|
|
38
|
-
if [ -n "${BATS_TEST_TMPDIR:-}" ] && [ "${DEVZONE_PORTS_WORKSPACE_REAL:-}" != yes ]; then
|
|
39
|
-
[ -n "${1:-}" ] || echo "✖ port watcher refused under bats (DEVZONE_PORTS_WORKSPACE_REAL=yes required)" >&2
|
|
40
|
-
return 2
|
|
41
|
-
fi
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
# Is process $1 alive?
|
|
45
|
-
pw_alive() { [ -n "${1:-}" ] && kill -0 "$1" 2>/dev/null; }
|
|
46
|
-
|
|
47
|
-
# TCP ports >= 1024 listening in the pod (ss -ltnH), excluding internal ports, one per line.
|
|
48
|
-
pw_pod_ports() {
|
|
49
|
-
local p
|
|
50
|
-
pw_kubectl --namespace "$PW_NS" exec "$PW_POD" -c workspace -- ss -ltnH 2>/dev/null |
|
|
51
|
-
awk '{n=split($4,a,":"); print a[n]}' | sort -un | while read -r p; do
|
|
52
|
-
case "$p" in '' | *[!0-9]*) continue ;; esac
|
|
53
|
-
[ "$p" -ge 1024 ] || continue
|
|
54
|
-
case "$PW_INTERNAL" in *" $p "*) continue ;; esac
|
|
55
|
-
echo "$p"
|
|
56
|
-
done
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
# devzone services to relay, one "port|namespace|target[|remote port]" line per
|
|
60
|
-
# active module service: postgres (5432) and pgAdmin if present in namespace,
|
|
61
|
-
# mysql (3306), and the Argo CD UI (8443 → 443) when present (#516).
|
|
62
|
-
pw_services() {
|
|
63
|
-
local port
|
|
64
|
-
if grep -qxE 'postgres=(on|true|oui)' .devzone.modules 2>/dev/null; then
|
|
65
|
-
echo "5432|devzone-postgres|svc/postgres"
|
|
66
|
-
port="$(pw_kubectl --namespace devzone-postgres get svc pgadmin -o "$PW_JSONPATH" 2>/dev/null || true)"
|
|
67
|
-
case "$port" in '' | *[!0-9]*) ;; *) echo "$port|devzone-postgres|svc/pgadmin" ;; esac
|
|
68
|
-
fi
|
|
69
|
-
if grep -qxE 'mysql=(on|true|oui)' .devzone.modules 2>/dev/null; then
|
|
70
|
-
echo "3306|devzone-mysql|svc/mysql"
|
|
71
|
-
fi
|
|
72
|
-
# Argo CD UI: https port of svc/argocd-server on 127.0.0.1:8443, unless argocd=off
|
|
73
|
-
if ! grep -qx 'argocd=off' .devzone.modules 2>/dev/null; then
|
|
74
|
-
port="$(pw_kubectl --namespace devzone-argocd get svc argocd-server \
|
|
75
|
-
-o 'jsonpath={.spec.ports[?(@.name=="https")].port}' 2>/dev/null || true)"
|
|
76
|
-
case "$port" in '' | *[!0-9]*) ;; *) echo "${DEVZONE_ARGOCD_PORT:-8443}|devzone-argocd|svc/argocd-server|$port" ;; esac
|
|
77
|
-
fi
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
# Is port $1 already in use on the workstation? (lsof, otherwise nc -z)
|
|
81
|
-
pw_taken() {
|
|
82
|
-
if command -v lsof >/dev/null 2>&1; then
|
|
83
|
-
lsof -nP -iTCP:"$1" -sTCP:LISTEN >/dev/null 2>&1
|
|
84
|
-
else
|
|
85
|
-
nc -z 127.0.0.1 "$1" >/dev/null 2>&1
|
|
86
|
-
fi
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
# Starts relay of port $1 to port $4 (default: $1) of target $3 in namespace $2,
|
|
90
|
-
# unless already alive; port taken on workstation: only one warning line per port.
|
|
91
|
-
pw_relay() {
|
|
92
|
-
local port="$1" ns="$2" target="$3" remote="${4:-$1}" d pid
|
|
93
|
-
d="$(pw_dir)"
|
|
94
|
-
pid="$(cat "$d/relays/$port" 2>/dev/null || true)"
|
|
95
|
-
pw_alive "$pid" && return 0
|
|
96
|
-
if pw_taken "$port"; then
|
|
97
|
-
[ -e "$d/taken/$port" ] || { : >"$d/taken/$port"; echo "⚠ port $port already in use on the workstation, not relayed"; }
|
|
98
|
-
return 0
|
|
99
|
-
fi
|
|
100
|
-
# shellcheck disable=SC2046
|
|
101
|
-
kubectl $(pw_ctx) --namespace "$ns" port-forward --address 127.0.0.1 "$target" "$port:$remote" </dev/null >/dev/null 2>&1 &
|
|
102
|
-
echo $! >"$d/relays/$port"
|
|
103
|
-
rm -f "$d/taken/$port"
|
|
104
|
-
echo "→ port $port relayed on 127.0.0.1"
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
# Stops relay of port $1 and forgets its warning.
|
|
108
|
-
pw_remove() {
|
|
109
|
-
local d pid
|
|
110
|
-
d="$(pw_dir)"
|
|
111
|
-
pid="$(cat "$d/relays/$1" 2>/dev/null || true)"
|
|
112
|
-
if pw_alive "$pid"; then kill "$pid" 2>/dev/null || true; fi
|
|
113
|
-
rm -f "$d/relays/$1" "$d/taken/$1"
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
# One watcher round: relay new ports, remove those that disappeared.
|
|
117
|
-
pw_round() {
|
|
118
|
-
local d wanted="" p ns target remote l f
|
|
119
|
-
d="$(pw_dir)"
|
|
120
|
-
mkdir -p "$d/relays" "$d/taken"
|
|
121
|
-
while IFS='|' read -r p ns target remote; do
|
|
122
|
-
[ -n "$p" ] || continue
|
|
123
|
-
wanted="$wanted $p "
|
|
124
|
-
pw_relay "$p" "$ns" "$target" "${remote:-$p}"
|
|
125
|
-
done <<<"$(pw_services)"
|
|
126
|
-
for p in $(pw_pod_ports); do
|
|
127
|
-
case "$wanted" in *" $p "*) continue ;; esac
|
|
128
|
-
wanted="$wanted $p "
|
|
129
|
-
pw_relay "$p" "$PW_NS" "pod/$PW_POD"
|
|
130
|
-
done
|
|
131
|
-
while IFS='|' read -r p ns target remote; do
|
|
132
|
-
[ -n "$p" ] || continue
|
|
133
|
-
wanted="$wanted $p "
|
|
134
|
-
pw_relay "$p" "$ns" "$target" "$remote"
|
|
135
|
-
done <<<"$(pa_round "$wanted")"
|
|
136
|
-
for f in "$d"/relays/* "$d"/taken/*; do
|
|
137
|
-
[ -e "$f" ] || continue
|
|
138
|
-
l="$(basename "$f")"
|
|
139
|
-
case "$wanted" in *" $l "*) ;; *) pw_remove "$l" ;; esac
|
|
140
|
-
done
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
# Removes all relays from the state folder.
|
|
144
|
-
pw_remove_all() {
|
|
145
|
-
local f
|
|
146
|
-
for f in "$(pw_dir)"/relays/*; do
|
|
147
|
-
if [ -e "$f" ]; then pw_remove "$(basename "$f")"; fi
|
|
148
|
-
done
|
|
149
|
-
}
|
|
150
|
-
|
|
151
|
-
# Watcher loop: one round every 3 s; on stop, removes its relays and lock.
|
|
152
|
-
pw_loop() {
|
|
153
|
-
local d
|
|
154
|
-
d="$(pw_dir)"
|
|
155
|
-
trap 'pw_remove_all; rm -rf "$d/lock" "$d/pid"; exit 0' TERM INT
|
|
156
|
-
while :; do
|
|
157
|
-
pw_round || true
|
|
158
|
-
sleep "${DEVZONE_PORTS_WORKSPACE_STEP:-3}" &
|
|
159
|
-
wait $!
|
|
160
|
-
done
|
|
161
|
-
}
|
|
162
|
-
|
|
163
|
-
# Starts the watcher, only one: mkdir lock, pid recorded; $1=silence: no guard message.
|
|
164
|
-
# shellcheck disable=SC2120
|
|
165
|
-
ports_start() {
|
|
166
|
-
pw_guard "${1:-}" || return 0
|
|
167
|
-
local d pid
|
|
168
|
-
d="$(pw_dir)"
|
|
169
|
-
mkdir -p "$d"
|
|
170
|
-
rm -f "$d/restart"
|
|
171
|
-
pid="$(cat "$d/pid" 2>/dev/null || true)"
|
|
172
|
-
if pw_alive "$pid"; then
|
|
173
|
-
echo "Workspace ports: watcher already running (pid $pid)"
|
|
174
|
-
return 0
|
|
175
|
-
fi
|
|
176
|
-
rm -rf "$d/lock"
|
|
177
|
-
mkdir "$d/lock" 2>/dev/null || return 0
|
|
178
|
-
nohup bash "${BASH_SOURCE[0]}" loop >>"$d/journal.log" 2>&1 &
|
|
179
|
-
echo $! >"$d/pid"
|
|
180
|
-
disown 2>/dev/null || true
|
|
181
|
-
echo "Workspace ports: watcher started, log $d/journal.log"
|
|
182
|
-
}
|
|
183
|
-
|
|
184
|
-
# Stops the watcher and all its port-forwards; without watcher, removes leftovers.
|
|
185
|
-
ports_stop() {
|
|
186
|
-
local d pid
|
|
187
|
-
d="$(pw_dir)"
|
|
188
|
-
pid="$(cat "$d/pid" 2>/dev/null || true)"
|
|
189
|
-
if pw_alive "$pid"; then
|
|
190
|
-
kill "$pid" 2>/dev/null || true
|
|
191
|
-
for _ in 1 2 3 4 5 6 7 8 9 10; do pw_alive "$pid" || break; sleep 0.2; done
|
|
192
|
-
fi
|
|
193
|
-
pw_remove_all
|
|
194
|
-
rm -rf "$d/lock" "$d/pid" "$d/restart"
|
|
195
|
-
}
|
|
196
|
-
|
|
197
|
-
# Shows status: watcher, relayed ports, reported taken ports.
|
|
198
|
-
ports_status() {
|
|
199
|
-
local d pid f
|
|
200
|
-
d="$(pw_dir)"
|
|
201
|
-
pid="$(cat "$d/pid" 2>/dev/null || true)"
|
|
202
|
-
if pw_alive "$pid"; then echo "Port watcher: running (pid $pid)"; else echo "Port watcher: stopped"; fi
|
|
203
|
-
for f in "$d"/relays/*; do
|
|
204
|
-
if [ -e "$f" ] && pw_alive "$(cat "$f")"; then echo " 127.0.0.1:$(basename "$f") relayed"; fi
|
|
205
|
-
done
|
|
206
|
-
for f in "$d"/taken/*; do
|
|
207
|
-
if [ -e "$f" ]; then echo " ⚠ port $(basename "$f") already in use on the workstation, not relayed"; fi
|
|
208
|
-
done
|
|
209
|
-
pa_status
|
|
210
|
-
return 0
|
|
211
|
-
}
|
|
212
|
-
|
|
213
|
-
# Subcommand "devzone workspace ports [start|stop|status]" (default: status).
|
|
214
|
-
ports() {
|
|
215
|
-
case "${1:-status}" in
|
|
216
|
-
start) ports_start ;;
|
|
217
|
-
stop) ports_stop ;;
|
|
218
|
-
status) ports_status ;;
|
|
219
|
-
*) echo "✖ devzone workspace ports start|stop|status" >&2; return 1 ;;
|
|
220
|
-
esac
|
|
221
|
-
}
|
|
222
|
-
|
|
223
|
-
# compatibility aliases, removed with lot 4 (#509)
|
|
224
|
-
ports_demarrer() { ports_start "$@"; }
|
|
225
|
-
ports_arreter() { ports_stop "$@"; }
|
|
226
|
-
ports_etat() { ports_status "$@"; }
|
|
227
|
-
|
|
228
|
-
# Run directly: watcher loop, or a single round (tests).
|
|
229
|
-
if [ "${BASH_SOURCE[0]}" = "$0" ]; then
|
|
230
|
-
pw_guard quiet || exit 2
|
|
231
|
-
case "${1:-}" in
|
|
232
|
-
loop) pw_loop ;;
|
|
233
|
-
round) pw_round ;;
|
|
234
|
-
esac
|
|
235
|
-
fi
|
|
@@ -1,193 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env bash
|
|
2
|
-
# devzone workspace services (#528): installs or removes the devzone services
|
|
3
|
-
# (gitlab, postgres, mysql, argocd) of a Kubernetes workspace from the workstation.
|
|
4
|
-
# Sourced by manage/workspace.sh (kubectl_flag, POD, NAMESPACE).
|
|
5
|
-
# devzone workspace services enable <service> [options]
|
|
6
|
-
# devzone workspace services disable <service> [--yes]
|
|
7
|
-
# devzone workspace services status
|
|
8
|
-
# Why: the pod has no administrator access to the cluster (#430), while the
|
|
9
|
-
# installers need one. The workstation creates a ServiceAccount bound to
|
|
10
|
-
# cluster-admin for the time of the operation, asks a one-hour token for it
|
|
11
|
-
# and runs the installer inside the pod (kubectl exec, token on stdin, see
|
|
12
|
-
# .devcontainer/services-admin.sh). The account and its binding are removed
|
|
13
|
-
# at the end, even on failure; the token is never printed.
|
|
14
|
-
|
|
15
|
-
SERVICES_ADMIN_SA="devzone-services-admin"
|
|
16
|
-
# Script run in the pod; DEVZONE_SERVICES_ADMIN_SCRIPT: another copy (trial of
|
|
17
|
-
# a version the image of the pod does not hold yet)
|
|
18
|
-
SERVICES_ADMIN_SCRIPT="${DEVZONE_SERVICES_ADMIN_SCRIPT:-/usr/local/share/devzone/.devcontainer/services-admin.sh}"
|
|
19
|
-
SERVICES_TOKEN_DURATION="${DEVZONE_SERVICES_TOKEN_DURATION:-1h}"
|
|
20
|
-
|
|
21
|
-
services_usage() {
|
|
22
|
-
echo "devzone workspace services enable|disable <gitlab|postgres|mysql|argocd> [options] | seed gitlab | status"
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
services_known() {
|
|
26
|
-
case "${1:-}" in
|
|
27
|
-
gitlab | postgres | mysql | argocd) return 0 ;;
|
|
28
|
-
esac
|
|
29
|
-
return 1
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
# A successful enable/disable is kept in .devzone.modules of the workstation so
|
|
33
|
-
# that a new devcontainer does not reinstall what was removed (#605). state_note
|
|
34
|
-
# (argocd-workspace.sh) updates the line and keeps the other ones intact.
|
|
35
|
-
services_state_note() {
|
|
36
|
-
case "$1" in
|
|
37
|
-
enable) state_note "$2" on ;;
|
|
38
|
-
disable) state_note "$2" off ;;
|
|
39
|
-
esac
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
# Namespace of a service in the cluster (gitlab: default instance)
|
|
43
|
-
services_namespace() {
|
|
44
|
-
case "$1" in
|
|
45
|
-
gitlab) echo devzone-gitlab ;;
|
|
46
|
-
postgres) echo devzone-postgres ;;
|
|
47
|
-
mysql) echo devzone-mysql ;;
|
|
48
|
-
argocd) echo devzone-argocd ;;
|
|
49
|
-
esac
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
# The workspace pod must be running: the installer runs inside it
|
|
53
|
-
services_pod_running() {
|
|
54
|
-
local phase
|
|
55
|
-
# shellcheck disable=SC2046
|
|
56
|
-
phase="$(kubectl $(kubectl_flag) get pod "$POD" --namespace "$NAMESPACE" \
|
|
57
|
-
-o jsonpath='{.status.phase}' 2>/dev/null)" || phase=""
|
|
58
|
-
[ "$phase" = Running ]
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
# Temporary administrator: ServiceAccount of the workspace namespace bound to
|
|
62
|
-
# cluster-admin (idempotent apply)
|
|
63
|
-
services_admin_create() {
|
|
64
|
-
# shellcheck disable=SC2046
|
|
65
|
-
kubectl $(kubectl_flag) apply -f - >/dev/null <<EOF
|
|
66
|
-
apiVersion: v1
|
|
67
|
-
kind: ServiceAccount
|
|
68
|
-
metadata:
|
|
69
|
-
name: $SERVICES_ADMIN_SA
|
|
70
|
-
namespace: $NAMESPACE
|
|
71
|
-
---
|
|
72
|
-
apiVersion: rbac.authorization.k8s.io/v1
|
|
73
|
-
kind: ClusterRoleBinding
|
|
74
|
-
metadata:
|
|
75
|
-
name: $SERVICES_ADMIN_SA
|
|
76
|
-
roleRef:
|
|
77
|
-
apiGroup: rbac.authorization.k8s.io
|
|
78
|
-
kind: ClusterRole
|
|
79
|
-
name: cluster-admin
|
|
80
|
-
subjects:
|
|
81
|
-
- kind: ServiceAccount
|
|
82
|
-
name: $SERVICES_ADMIN_SA
|
|
83
|
-
namespace: $NAMESPACE
|
|
84
|
-
EOF
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
services_admin_delete() {
|
|
88
|
-
# shellcheck disable=SC2046
|
|
89
|
-
kubectl $(kubectl_flag) delete clusterrolebinding "$SERVICES_ADMIN_SA" \
|
|
90
|
-
--ignore-not-found >/dev/null 2>&1 || true
|
|
91
|
-
# shellcheck disable=SC2046
|
|
92
|
-
kubectl $(kubectl_flag) delete serviceaccount "$SERVICES_ADMIN_SA" \
|
|
93
|
-
--namespace "$NAMESPACE" --ignore-not-found >/dev/null 2>&1 || true
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
# Runs the installer in the pod: temporary administrator created, token on
|
|
97
|
-
# stdin of kubectl exec, administrator removed whatever the outcome
|
|
98
|
-
services_run() {
|
|
99
|
-
local action="$1" service="$2" token code=0
|
|
100
|
-
shift 2
|
|
101
|
-
if ! services_known "$service"; then
|
|
102
|
-
echo "✖ unknown service: ${service:-(none)} ($(services_usage))" >&2
|
|
103
|
-
return 1
|
|
104
|
-
fi
|
|
105
|
-
# Argo CD itself, and postgres and mysql when Argo CD holds the devzone
|
|
106
|
-
# charts: done by the workstation, no installer in the pod (#516, #538)
|
|
107
|
-
if [ "$service" = argocd ]; then
|
|
108
|
-
argocd_toggle "$action" "$@"
|
|
109
|
-
code=$?
|
|
110
|
-
[ "$code" -eq 0 ] || return "$code"
|
|
111
|
-
services_state_note "$action" "$service"
|
|
112
|
-
return 0
|
|
113
|
-
fi
|
|
114
|
-
# postgres and mysql are held by Argo CD when it holds the charts
|
|
115
|
-
case "$service" in
|
|
116
|
-
postgres | mysql)
|
|
117
|
-
if argocd_holds_charts; then
|
|
118
|
-
services_argocd_toggle "$service" "$action" "$@"
|
|
119
|
-
code=$?
|
|
120
|
-
[ "$code" -eq 0 ] || return "$code"
|
|
121
|
-
services_state_note "$action" "$service"
|
|
122
|
-
return 0
|
|
123
|
-
fi
|
|
124
|
-
;;
|
|
125
|
-
esac
|
|
126
|
-
if ! services_pod_running; then
|
|
127
|
-
echo "✖ workspace pod $POD not running: devzone workspace start" >&2
|
|
128
|
-
return 1
|
|
129
|
-
fi
|
|
130
|
-
echo "▶ temporary administrator $SERVICES_ADMIN_SA (removed at the end)…"
|
|
131
|
-
if ! services_admin_create; then
|
|
132
|
-
echo "✖ cannot create the temporary administrator: cluster-admin rights needed on the workstation" >&2
|
|
133
|
-
return 1
|
|
134
|
-
fi
|
|
135
|
-
trap services_admin_delete EXIT
|
|
136
|
-
# shellcheck disable=SC2046
|
|
137
|
-
if ! token="$(kubectl $(kubectl_flag) create token "$SERVICES_ADMIN_SA" \
|
|
138
|
-
--namespace "$NAMESPACE" --duration "$SERVICES_TOKEN_DURATION")" || [ -z "$token" ]; then
|
|
139
|
-
echo "✖ cannot get a token of the temporary administrator (kubectl 1.24 or more)" >&2
|
|
140
|
-
services_admin_delete
|
|
141
|
-
trap - EXIT
|
|
142
|
-
return 1
|
|
143
|
-
fi
|
|
144
|
-
echo "▶ $action $service in the pod ${POD}…"
|
|
145
|
-
# The installer of the pod takes --yes (#557) : no translation, no warning
|
|
146
|
-
# shellcheck disable=SC2046
|
|
147
|
-
printf '%s\n' "$token" | kubectl $(kubectl_flag) exec -i "$POD" --namespace "$NAMESPACE" \
|
|
148
|
-
-c workspace -- bash "$SERVICES_ADMIN_SCRIPT" "$action" "$service" "$@" || code=$?
|
|
149
|
-
services_admin_delete
|
|
150
|
-
trap - EXIT
|
|
151
|
-
if [ "$code" -ne 0 ]; then
|
|
152
|
-
echo "✖ $action $service failed (code $code); in the pod: devzone status" >&2
|
|
153
|
-
return "$code"
|
|
154
|
-
fi
|
|
155
|
-
services_state_note "$action" "$service"
|
|
156
|
-
echo "✔ $action $service done; in the pod: devzone status; local access: devzone workspace ports"
|
|
157
|
-
}
|
|
158
|
-
|
|
159
|
-
# One line per service: installed (namespace present) or not
|
|
160
|
-
services_status() {
|
|
161
|
-
local s ns
|
|
162
|
-
for s in gitlab postgres mysql argocd; do
|
|
163
|
-
ns="$(services_namespace "$s")"
|
|
164
|
-
# shellcheck disable=SC2046
|
|
165
|
-
if kubectl $(kubectl_flag) get namespace "$ns" >/dev/null 2>&1; then
|
|
166
|
-
echo " ✔ $s installed (namespace $ns): devzone workspace services disable $s"
|
|
167
|
-
else
|
|
168
|
-
echo " ○ $s not installed: devzone workspace services enable $s"
|
|
169
|
-
fi
|
|
170
|
-
done
|
|
171
|
-
}
|
|
172
|
-
|
|
173
|
-
services() {
|
|
174
|
-
local sub="${1:-}"
|
|
175
|
-
case "$sub" in
|
|
176
|
-
enable) services_run enable "${2:-}" "${@:3}" ;;
|
|
177
|
-
disable) services_run disable "${2:-}" "${@:3}" ;;
|
|
178
|
-
# The data of gitlab (group, demo project, dev user, runner) seeded
|
|
179
|
-
# again, in the pod (#538): the only seed of the services
|
|
180
|
-
seed)
|
|
181
|
-
if [ "${2:-}" != gitlab ]; then
|
|
182
|
-
echo "✖ seed: only gitlab ($(services_usage))" >&2
|
|
183
|
-
return 1
|
|
184
|
-
fi
|
|
185
|
-
services_run seed gitlab
|
|
186
|
-
;;
|
|
187
|
-
status | '') services_status ;;
|
|
188
|
-
*)
|
|
189
|
-
echo "✖ unknown subcommand: $sub ($(services_usage))" >&2
|
|
190
|
-
return 1
|
|
191
|
-
;;
|
|
192
|
-
esac
|
|
193
|
-
}
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env bash
|
|
2
|
-
|
|
3
|
-
# Guard of the agents in the pod (#558): when the ai module is on there,
|
|
4
|
-
# "repowarden agents init --global" is run (idempotent), so that an agent
|
|
5
|
-
# launched in the pod cannot edit develop. Never fails the workspace start.
|
|
6
|
-
workspace_agents_guard() {
|
|
7
|
-
# shellcheck disable=SC2046
|
|
8
|
-
if kubectl $(kubectl_flag) exec "$POD" --namespace "$NAMESPACE" -c workspace -- \
|
|
9
|
-
bash -lc 'devzone is-enabled ai && repowarden agents init --global' >/dev/null 2>&1; then
|
|
10
|
-
echo "✔ repowarden guard active for the agents of the pod"
|
|
11
|
-
fi
|
|
12
|
-
}
|
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env bash
|
|
2
|
-
# Stale copies in the pod (#558), sourced by manage/workspace.sh:
|
|
3
|
-
# status_workspace pod status, then the legacy copies still in the pod
|
|
4
|
-
# Uses kubectl_flag, POD, NAMESPACE and PROJECTS_DIR from workspace.sh.
|
|
5
|
-
|
|
6
|
-
# Shows workspace pod status, then the legacy copies still in the pod.
|
|
7
|
-
status_workspace() {
|
|
8
|
-
# shellcheck disable=SC2046
|
|
9
|
-
kubectl $(kubectl_flag) get pods --namespace devzone-workspace
|
|
10
|
-
workspace_legacy_copies || true
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
# Script run in the pod: prints the legacy copies, one folder per line
|
|
14
|
-
# (repogarde, wt): their .git file points to a git folder missing from the pod.
|
|
15
|
-
workspace_legacy_pod_script() {
|
|
16
|
-
cat <<'POD'
|
|
17
|
-
broken() {
|
|
18
|
-
local g
|
|
19
|
-
[ -f "$1/.git" ] || return 1
|
|
20
|
-
g="$(sed -n 's/^gitdir: *//p' "$1/.git" | head -1)"
|
|
21
|
-
[ -n "$g" ] && [ ! -e "$g" ]
|
|
22
|
-
}
|
|
23
|
-
cd "$1" || exit 0
|
|
24
|
-
if broken repogarde; then echo repogarde; fi
|
|
25
|
-
for d in wt/*; do
|
|
26
|
-
if broken "$d"; then echo wt; break; fi
|
|
27
|
-
done
|
|
28
|
-
POD
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
# Legacy copies (repogarde/, wt/) are reported with the command to remove them;
|
|
32
|
-
# the removal itself is manual, after a backup.
|
|
33
|
-
workspace_legacy_copies() {
|
|
34
|
-
local found d dirs=""
|
|
35
|
-
# shellcheck disable=SC2046
|
|
36
|
-
found="$(workspace_legacy_pod_script | kubectl $(kubectl_flag) exec -i "$POD" \
|
|
37
|
-
--namespace "$NAMESPACE" -c workspace -- bash -s -- "$PROJECTS_DIR" 2>/dev/null)" || return 0
|
|
38
|
-
[ -n "$found" ] || return 0
|
|
39
|
-
for d in $found; do dirs="$dirs $PROJECTS_DIR/$d"; done
|
|
40
|
-
echo "⚠ legacy copies in the pod (their .git points outside the pod):$dirs"
|
|
41
|
-
echo " 1. save what you need: devzone workspace copy-from <folder>"
|
|
42
|
-
echo " 2. remove them from the pod shell (devzone workspace shell), one folder at a time:"
|
|
43
|
-
for d in $found; do echo " rm -rf $PROJECTS_DIR/$d"; done
|
|
44
|
-
}
|