devzone 7.3.0 → 7.4.1
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/devcontainer.json +1 -1
- package/.devcontainer/devzone +13 -20
- package/.devcontainer/devzone-modules.sh +1 -1
- package/.devcontainer/devzone-repair.sh +2 -2
- package/.devcontainer/devzone-services.sh +7 -7
- package/.devcontainer/devzone-status.sh +5 -5
- package/.devcontainer/help.sh +3 -1
- package/.devcontainer/versions.env +3 -0
- package/.devcontainer/workspace-init.sh +8 -9
- package/.gitattributes +8 -0
- package/README.md +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/charts/devzone-mysql/values.yaml +1 -1
- package/charts/devzone-postgres/values.yaml +1 -1
- package/manage/devzone +2 -2
- package/manage/scripts/uninstall.sh +1 -1
- package/manage/scripts/workspace/argocd-workspace.sh +2 -2
- package/package.json +1 -1
- package/.devcontainer/agent-errors.sh +0 -156
- package/.devcontainer/agent-local.sh +0 -63
- package/.devcontainer/agent-model.sh +0 -113
- package/.devcontainer/agent-pod-egress.sh +0 -36
- package/.devcontainer/agent-pod-manifest.sh +0 -250
- package/.devcontainer/agent-pod.sh +0 -243
- package/.devcontainer/agent-session.sh +0 -242
- package/.devcontainer/agent-state-json.sh +0 -117
- package/.devcontainer/agent-workspace.sh +0 -97
- package/.devcontainer/agent.sh +0 -247
- 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-cluster.sh +0 -209
- 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
|
@@ -1,113 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env bash
|
|
2
|
-
# Models asked with devzone agent --model (#420): list check, attempt order
|
|
3
|
-
# (requested models first, then the usual rotation) and the shared rank rule.
|
|
4
|
-
# Library sourced by agent.sh: no command is launched here.
|
|
5
|
-
|
|
6
|
-
# Journal and refusal texts, printf formats.
|
|
7
|
-
# shellcheck source=SCRIPTDIR/agent-model.messages disable=SC1091
|
|
8
|
-
. "$ICI/agent-model.messages"
|
|
9
|
-
|
|
10
|
-
# Option --model as typed (comma-separated list), empty when absent.
|
|
11
|
-
MODEL_LIST=""
|
|
12
|
-
# Requested models, in order, checked by models_load.
|
|
13
|
-
MODELS_REQUESTED=()
|
|
14
|
-
# Attempt order of the session (internal names), set by model_order.
|
|
15
|
-
ORDER=()
|
|
16
|
-
|
|
17
|
-
# Refuses a name missing from the free models: nothing is launched (code 2).
|
|
18
|
-
refuse_model() {
|
|
19
|
-
# shellcheck disable=SC2059 # the format comes from agent-model.messages
|
|
20
|
-
printf "$MSG_UNKNOWN\n" "$1" >&2
|
|
21
|
-
printf ' %s\n' "${FREE_MODELS[@]}" >&2
|
|
22
|
-
exit 2
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
# Loads the free models, checks the --model list and writes its header to the
|
|
26
|
-
# journal $1: the last header tells devzone agent state what was asked.
|
|
27
|
-
models_load() {
|
|
28
|
-
local journal="$1" m nom
|
|
29
|
-
FREE_MODELS=()
|
|
30
|
-
while IFS= read -r m; do
|
|
31
|
-
if [ -n "$m" ]; then FREE_MODELS+=("$m"); fi
|
|
32
|
-
done < <(list_models)
|
|
33
|
-
[ "${#FREE_MODELS[@]}" -gt 0 ] || refuse "$MSG_NO_MODEL"
|
|
34
|
-
MODELS_REQUESTED=()
|
|
35
|
-
if [ -n "$MODEL_LIST" ]; then
|
|
36
|
-
while IFS= read -r nom; do
|
|
37
|
-
case " ${FREE_MODELS[*]} " in
|
|
38
|
-
*" $nom "*) MODELS_REQUESTED+=("$nom") ;;
|
|
39
|
-
*) refuse_model "$nom" ;;
|
|
40
|
-
esac
|
|
41
|
-
done < <(printf '%s\n' "$MODEL_LIST" | tr ',' '\n')
|
|
42
|
-
fi
|
|
43
|
-
echo "=== --model : ${MODEL_LIST:-none}" >>"$journal"
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
# True when model $1 was asked with --model.
|
|
47
|
-
model_requested_p() {
|
|
48
|
-
case " ${MODELS_REQUESTED[*]:-} " in
|
|
49
|
-
*" $1 "*) return 0 ;;
|
|
50
|
-
esac
|
|
51
|
-
return 1
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
# Journal line when requested model $1 starts; other models get no line.
|
|
55
|
-
model_requested_chosen() {
|
|
56
|
-
if model_requested_p "$1"; then
|
|
57
|
-
# shellcheck disable=SC2059 # the format comes from agent-model.messages
|
|
58
|
-
printf "$MSG_CHOSEN\n" "$1" >>"$2"
|
|
59
|
-
fi
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
# Journal line when requested model $1 is excluded for cause $2, written to the
|
|
63
|
-
# journal $3. Other models keep their own lines.
|
|
64
|
-
model_requested_excluded() {
|
|
65
|
-
if model_requested_p "$1"; then
|
|
66
|
-
# shellcheck disable=SC2059 # the format comes from agent-model.messages
|
|
67
|
-
printf "$MSG_EXCLUDED\n" "$1" "$2" >>"$3"
|
|
68
|
-
fi
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
# Cause of the current exclusion of model $1: ecart-<model> gives it, muet-<model>
|
|
72
|
-
# has none and counts as muet.
|
|
73
|
-
model_exclusion_cause() {
|
|
74
|
-
local f cause=""
|
|
75
|
-
f="$AGENT_STATE/ecart-$1"
|
|
76
|
-
if [ ! -f "$f" ]; then f="$AGENT_STATE/muet-$1"; fi
|
|
77
|
-
if [ -f "$f" ]; then read -r _ cause _ <"$f" || true; fi
|
|
78
|
-
echo "${cause:-muet}"
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
# Adds model $1 to ORDER unless it is already there.
|
|
82
|
-
order_add() {
|
|
83
|
-
case " ${ORDER[*]:-} " in
|
|
84
|
-
*" $1 "*) ;;
|
|
85
|
-
*) ORDER+=("$1") ;;
|
|
86
|
-
esac
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
# Attempt order of the session from rank $1: requested models in their order,
|
|
90
|
-
# then the usual rotation (online models, then the local one). Each model
|
|
91
|
-
# appears once, so the rotation never tries again a requested model.
|
|
92
|
-
model_order() {
|
|
93
|
-
local start="$1" total i k
|
|
94
|
-
ORDER=()
|
|
95
|
-
for ((k = 0; k < ${#MODELS_REQUESTED[@]}; k++)); do
|
|
96
|
-
order_add "${MODELS_REQUESTED[$k]}"
|
|
97
|
-
done
|
|
98
|
-
total="$(models_total)"
|
|
99
|
-
for ((i = 0; i < total; i++)); do
|
|
100
|
-
order_add "$(model_at_rank "$i" "$start")"
|
|
101
|
-
done
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
# True when the shared rank may advance: no requested model is available.
|
|
105
|
-
# A requested model that starts leaves the rank alone, so the rotation of the
|
|
106
|
-
# other sessions does not move.
|
|
107
|
-
model_rank_advance() {
|
|
108
|
-
local k
|
|
109
|
-
for ((k = 0; k < ${#MODELS_REQUESTED[@]}; k++)); do
|
|
110
|
-
if ! model_excluded "${MODELS_REQUESTED[$k]}"; then return 1; fi
|
|
111
|
-
done
|
|
112
|
-
return 0
|
|
113
|
-
}
|
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env bash
|
|
2
|
-
# Egress proxy helpers for the ephemeral session pod (#220).
|
|
3
|
-
# Sourced by agent-pod-manifest.sh. bash 3.2 compatible ; shellcheck -x clean.
|
|
4
|
-
|
|
5
|
-
agent_pod_egress_mode() {
|
|
6
|
-
kubectl get service -l app.kubernetes.io/component=egress-proxy \
|
|
7
|
-
-o jsonpath='{.items[0].metadata.labels.devzone\.io/egress-mode}' 2>/dev/null || true
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
agent_pod_egress_manifest_lines() {
|
|
11
|
-
local mode="$1"
|
|
12
|
-
[ -n "$mode" ] || return 0
|
|
13
|
-
printf '%s\n' " - name: HTTP_PROXY"
|
|
14
|
-
printf '%s\n' " value: \"http://egress-proxy:3128\""
|
|
15
|
-
printf '%s\n' " - name: HTTPS_PROXY"
|
|
16
|
-
printf '%s\n' " value: \"http://egress-proxy:3128\""
|
|
17
|
-
printf '%s\n' " - name: NO_PROXY"
|
|
18
|
-
printf '%s\n' " value: \"localhost,127.0.0.1,.svc,.cluster.local\""
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
agent_pod_egress_init_lines() {
|
|
22
|
-
local mode="$1" ws_image="$2"
|
|
23
|
-
[ "$mode" = "strict" ] || return 0
|
|
24
|
-
printf '%s\n' " initContainers:"
|
|
25
|
-
printf '%s\n' " - name: wait-egress-restriction"
|
|
26
|
-
printf '%s\n' " image: ${ws_image}"
|
|
27
|
-
printf '%s\n' " command: [\"/bin/bash\", \"-lc\"]"
|
|
28
|
-
printf '%s\n' " args:"
|
|
29
|
-
printf '%s\n' " - 'i=0; while [ \$i -lt 20 ]; do if ! curl --noproxy \"*\" -m 3 -sS https://opencode.ai >/dev/null 2>&1; then exit 0; fi; i=\$((i+1)); sleep 1; done; echo \"egress restriction never became effective: session refused\" >&2; exit 1'"
|
|
30
|
-
printf '%s\n' " securityContext:"
|
|
31
|
-
printf '%s\n' " runAsUser: 1000"
|
|
32
|
-
printf '%s\n' " runAsGroup: 1000"
|
|
33
|
-
printf '%s\n' " allowPrivilegeEscalation: false"
|
|
34
|
-
printf '%s\n' " capabilities:"
|
|
35
|
-
printf '%s\n' " drop: [\"ALL\"]"
|
|
36
|
-
}
|
|
@@ -1,250 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env bash
|
|
2
|
-
# Manifest and validation helpers for the ephemeral session pod (#222).
|
|
3
|
-
# Sourced by agent-pod.sh.
|
|
4
|
-
# bash 3.2 compatible ; shellcheck -x clean.
|
|
5
|
-
# shellcheck disable=SC1091
|
|
6
|
-
. "$(dirname "${BASH_SOURCE[0]}")/agent-pod-egress.sh"
|
|
7
|
-
|
|
8
|
-
# --- Defaults ---
|
|
9
|
-
|
|
10
|
-
DEVZONE_AGENT_POD_ACTIVE_DEADLINE_SECONDS="${DEVZONE_AGENT_POD_ACTIVE_DEADLINE_SECONDS:-1800}"
|
|
11
|
-
DEVZONE_AGENT_POD_CPU_LIMIT="${DEVZONE_AGENT_POD_CPU_LIMIT:-2}"
|
|
12
|
-
DEVZONE_AGENT_POD_MEM_LIMIT="${DEVZONE_AGENT_POD_MEM_LIMIT:-4Gi}"
|
|
13
|
-
DEVZONE_AGENT_POD_TIMEOUT="${DEVZONE_AGENT_POD_TIMEOUT:-$((DEVZONE_AGENT_POD_ACTIVE_DEADLINE_SECONDS + 120))}"
|
|
14
|
-
# Projects root, read by the launcher only (no trailing slash). The pod keeps
|
|
15
|
-
# /workspaces/projets in its own environment (DEVZONE_ROOT in the manifest).
|
|
16
|
-
AGENT_POD_ROOT="${DEVZONE_ROOT:-/workspaces/projets}"
|
|
17
|
-
# Module state file on the workspace volume (subPath .devzone.modules, read-only in the pod).
|
|
18
|
-
# shellcheck disable=SC2034 # read by agent-pod.sh
|
|
19
|
-
AGENT_POD_MODULES_FILE="${DEVZONE_AGENT_POD_MODULES_FILE:-${AGENT_POD_ROOT}/.devzone.modules}"
|
|
20
|
-
|
|
21
|
-
# --- Path check : under AGENT_POD_ROOT, only [A-Za-z0-9._/-], no . or .. part ---
|
|
22
|
-
|
|
23
|
-
agent_pod_path_ok() {
|
|
24
|
-
printf '%s' "$AGENT_POD_ROOT" | grep -Eq '^/[A-Za-z0-9._/-]*[A-Za-z0-9._-]$' || return 1
|
|
25
|
-
case "$1" in "$AGENT_POD_ROOT"/*) ;; *) return 1 ;; esac
|
|
26
|
-
printf '%s' "$1" | grep -Eq '^[A-Za-z0-9._/-]+$' || return 1
|
|
27
|
-
case "$1/" in */./* | */../* | *//*) return 1 ;; esac
|
|
28
|
-
return 0
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
# --- State filled by agent_pod_validate_folder ---
|
|
32
|
-
|
|
33
|
-
AGENT_POD_WORKTREE_SUBPATH=""
|
|
34
|
-
AGENT_POD_WORKTREE_MOUNTPATH=""
|
|
35
|
-
AGENT_POD_GIT_SUBPATH=""
|
|
36
|
-
AGENT_POD_GIT_MOUNTPATH=""
|
|
37
|
-
AGENT_POD_SESSION_LABEL=""
|
|
38
|
-
AGENT_POD_TICKET=""
|
|
39
|
-
|
|
40
|
-
# --- Helpers : read the workspace pod (devzone-workspace-0, container workspace) ---
|
|
41
|
-
|
|
42
|
-
agent_pod_image_workspace() {
|
|
43
|
-
local result
|
|
44
|
-
result="$(kubectl get pod devzone-workspace-0 -o jsonpath='{.spec.containers[?(@.name=="workspace")].image}' 2>/dev/null)" || true
|
|
45
|
-
echo "${result:-ghcr.io/simbienvenuehoulboumi/devzone-workspace:latest}"
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
agent_pod_path_workspace() {
|
|
49
|
-
local result
|
|
50
|
-
result="$(kubectl get pod devzone-workspace-0 -o jsonpath='{.spec.containers[?(@.name=="workspace")].env[?(@.name=="PATH")].value}' 2>/dev/null)" || true
|
|
51
|
-
echo "${result:-/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin}"
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
agent_pod_pvc_workspace() {
|
|
55
|
-
local result
|
|
56
|
-
result="$(kubectl get pod devzone-workspace-0 -o jsonpath='{.spec.volumes[?(@.name=="workspace")].persistentVolumeClaim.claimName}' 2>/dev/null)" || true
|
|
57
|
-
echo "${result:-workspace-devzone-workspace-0}"
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
agent_pod_pvc_etat() {
|
|
61
|
-
local result
|
|
62
|
-
result="$(kubectl get pod devzone-workspace-0 -o jsonpath='{.spec.volumes[?(@.name=="etat")].persistentVolumeClaim.claimName}' 2>/dev/null)" || true
|
|
63
|
-
echo "${result:-etat-devzone-workspace-0}"
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
# --- Validation of the folder to session ---
|
|
67
|
-
|
|
68
|
-
agent_pod_validate_folder() {
|
|
69
|
-
local folder="$1" gitfile gitdir common base
|
|
70
|
-
if [ -z "$folder" ]; then
|
|
71
|
-
echo "devzone agent --pod : folder missing" >&2
|
|
72
|
-
return 1
|
|
73
|
-
fi
|
|
74
|
-
case "$folder" in
|
|
75
|
-
"$AGENT_POD_ROOT"/*) ;;
|
|
76
|
-
*)
|
|
77
|
-
echo "devzone agent --pod : folder outside the projects root $AGENT_POD_ROOT : $folder" >&2
|
|
78
|
-
return 1
|
|
79
|
-
;;
|
|
80
|
-
esac
|
|
81
|
-
if ! agent_pod_path_ok "$folder"; then
|
|
82
|
-
echo "devzone agent --pod : invalid folder path : $folder" >&2
|
|
83
|
-
return 1
|
|
84
|
-
fi
|
|
85
|
-
gitfile="$folder/.git"
|
|
86
|
-
if [ ! -f "$gitfile" ]; then
|
|
87
|
-
echo "devzone agent --pod : no .git file (not a git worktree) : $folder" >&2
|
|
88
|
-
return 1
|
|
89
|
-
fi
|
|
90
|
-
gitdir="$(grep '^gitdir:' "$gitfile" 2>/dev/null | head -1 | sed 's/^gitdir:[[:space:]]*//;s/[[:space:]]*$//')"
|
|
91
|
-
if [ -z "$gitdir" ]; then
|
|
92
|
-
echo "devzone agent --pod : .git without gitdir line : $folder" >&2
|
|
93
|
-
return 1
|
|
94
|
-
fi
|
|
95
|
-
case "$gitdir" in
|
|
96
|
-
*/worktrees/*) common="${gitdir%/worktrees/*}" ;;
|
|
97
|
-
*)
|
|
98
|
-
echo "devzone agent --pod : gitdir is not a worktree : $gitdir" >&2
|
|
99
|
-
return 1
|
|
100
|
-
;;
|
|
101
|
-
esac
|
|
102
|
-
case "$common" in
|
|
103
|
-
"$AGENT_POD_ROOT"/*) ;;
|
|
104
|
-
*)
|
|
105
|
-
echo "devzone agent --pod : worktree depot outside the projects root $AGENT_POD_ROOT : $common" >&2
|
|
106
|
-
return 1
|
|
107
|
-
;;
|
|
108
|
-
esac
|
|
109
|
-
if ! agent_pod_path_ok "$common"; then
|
|
110
|
-
echo "devzone agent --pod : invalid depot path : $common" >&2
|
|
111
|
-
return 1
|
|
112
|
-
fi
|
|
113
|
-
base="$(basename "$folder")"
|
|
114
|
-
if ! printf '%s' "$base" | grep -Eq '^[A-Za-z0-9]([A-Za-z0-9._-]*[A-Za-z0-9])?$'; then
|
|
115
|
-
echo "devzone agent --pod : invalid label value : $base" >&2
|
|
116
|
-
return 1
|
|
117
|
-
fi
|
|
118
|
-
if [ "${#base}" -gt 63 ]; then
|
|
119
|
-
echo "devzone agent --pod : label value too long : $base" >&2
|
|
120
|
-
return 1
|
|
121
|
-
fi
|
|
122
|
-
AGENT_POD_WORKTREE_MOUNTPATH="$folder"
|
|
123
|
-
AGENT_POD_WORKTREE_SUBPATH="${folder#"$AGENT_POD_ROOT"/}"
|
|
124
|
-
AGENT_POD_GIT_MOUNTPATH="$common"
|
|
125
|
-
AGENT_POD_GIT_SUBPATH="${common#"$AGENT_POD_ROOT"/}"
|
|
126
|
-
AGENT_POD_SESSION_LABEL="$base"
|
|
127
|
-
# Keep the ticket only for an exact dz-<number> name.
|
|
128
|
-
if ! printf '%s' "$base" | grep -Eq '^dz-[0-9]+$'; then
|
|
129
|
-
AGENT_POD_TICKET=""
|
|
130
|
-
else
|
|
131
|
-
AGENT_POD_TICKET="${base#dz-}"
|
|
132
|
-
fi
|
|
133
|
-
return 0
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
# --- Build the session pod manifest ---
|
|
137
|
-
|
|
138
|
-
agent_pod_build_manifest() {
|
|
139
|
-
# $2 (the brief) is never written here: it only goes to the ConfigMap.
|
|
140
|
-
local folder="$1" pod_name="$3"
|
|
141
|
-
local ws_image ws_path pvc_workspace pvc_etat manifest_file ticket_block=""
|
|
142
|
-
|
|
143
|
-
ws_image="$(agent_pod_image_workspace)"
|
|
144
|
-
ws_path="$(agent_pod_path_workspace)"
|
|
145
|
-
pvc_workspace="$(agent_pod_pvc_workspace)"
|
|
146
|
-
pvc_etat="$(agent_pod_pvc_etat)"
|
|
147
|
-
|
|
148
|
-
if [ -n "$AGENT_POD_TICKET" ]; then
|
|
149
|
-
ticket_block=" devzone.io/agent-ticket: \"${AGENT_POD_TICKET}\""
|
|
150
|
-
fi
|
|
151
|
-
|
|
152
|
-
manifest_file="$(mktemp "${TMPDIR:-/tmp}/devzone-agent-pod-manifest.XXXXXX.yaml")"; egress_mode="$(agent_pod_egress_mode)"
|
|
153
|
-
|
|
154
|
-
{
|
|
155
|
-
printf '%s\n' "apiVersion: v1"
|
|
156
|
-
printf '%s\n' "kind: Pod"
|
|
157
|
-
printf '%s\n' "metadata:"
|
|
158
|
-
printf '%s\n' " name: ${pod_name}"
|
|
159
|
-
printf '%s\n' " labels:"
|
|
160
|
-
printf '%s\n' " devzone.io/agent-session: ${AGENT_POD_SESSION_LABEL}"
|
|
161
|
-
if [ -n "$ticket_block" ]; then
|
|
162
|
-
printf '%s\n' "$ticket_block"
|
|
163
|
-
fi
|
|
164
|
-
printf '%s\n' "spec:"
|
|
165
|
-
agent_pod_egress_init_lines "$egress_mode" "$ws_image"
|
|
166
|
-
printf '%s\n' " restartPolicy: Never"
|
|
167
|
-
printf '%s\n' " activeDeadlineSeconds: ${DEVZONE_AGENT_POD_ACTIVE_DEADLINE_SECONDS}"
|
|
168
|
-
printf '%s\n' " automountServiceAccountToken: false"
|
|
169
|
-
printf '%s\n' " securityContext:"
|
|
170
|
-
printf '%s\n' " runAsUser: 1000"
|
|
171
|
-
printf '%s\n' " runAsGroup: 1000"
|
|
172
|
-
printf '%s\n' " runAsNonRoot: true"
|
|
173
|
-
printf '%s\n' " fsGroup: 1000"
|
|
174
|
-
printf '%s\n' " affinity:"
|
|
175
|
-
printf '%s\n' " podAffinity:"
|
|
176
|
-
printf '%s\n' " requiredDuringSchedulingIgnoredDuringExecution:"
|
|
177
|
-
printf '%s\n' " - labelSelector:"
|
|
178
|
-
printf '%s\n' " matchExpressions:"
|
|
179
|
-
printf '%s\n' " - key: statefulset.kubernetes.io/pod-name"
|
|
180
|
-
printf '%s\n' " operator: In"
|
|
181
|
-
printf '%s\n' " values:"
|
|
182
|
-
printf '%s\n' " - devzone-workspace-0"
|
|
183
|
-
printf '%s\n' " topologyKey: kubernetes.io/hostname"
|
|
184
|
-
printf '%s\n' " containers:"
|
|
185
|
-
printf '%s\n' " - name: agent"
|
|
186
|
-
printf '%s\n' " image: ${ws_image}"
|
|
187
|
-
printf '%s\n' " env:"
|
|
188
|
-
printf '%s\n' " - name: HOME"
|
|
189
|
-
printf '%s\n' " value: \"/home/vscode\""
|
|
190
|
-
printf '%s\n' " - name: NPM_CONFIG_PREFIX"
|
|
191
|
-
printf '%s\n' " value: \"/home/vscode/.local/npm\""
|
|
192
|
-
printf '%s\n' " - name: PATH"
|
|
193
|
-
printf '%s\n' " value: \"${ws_path}\""
|
|
194
|
-
printf '%s\n' " - name: DEVZONE_WORKSPACE"
|
|
195
|
-
printf '%s\n' " value: \"kubernetes\""
|
|
196
|
-
printf '%s\n' " - name: DEVZONE_ROOT"
|
|
197
|
-
printf '%s\n' " value: \"/workspaces/projets\""; agent_pod_egress_manifest_lines "$egress_mode"
|
|
198
|
-
printf '%s\n' " resources:"
|
|
199
|
-
printf '%s\n' " limits:"
|
|
200
|
-
printf '%s\n' " cpu: ${DEVZONE_AGENT_POD_CPU_LIMIT}"
|
|
201
|
-
printf '%s\n' " memory: ${DEVZONE_AGENT_POD_MEM_LIMIT}"
|
|
202
|
-
printf '%s\n' " volumeMounts:"
|
|
203
|
-
printf '%s\n' " - name: workspace"
|
|
204
|
-
printf '%s\n' " mountPath: ${AGENT_POD_WORKTREE_MOUNTPATH}"
|
|
205
|
-
printf '%s\n' " subPath: ${AGENT_POD_WORKTREE_SUBPATH}"
|
|
206
|
-
printf '%s\n' " - name: workspace"
|
|
207
|
-
printf '%s\n' " mountPath: ${AGENT_POD_GIT_MOUNTPATH}"
|
|
208
|
-
printf '%s\n' " subPath: ${AGENT_POD_GIT_SUBPATH}"
|
|
209
|
-
printf '%s\n' " - name: workspace"
|
|
210
|
-
printf '%s\n' " mountPath: /workspaces/projets/.devzone.modules"
|
|
211
|
-
printf '%s\n' " subPath: .devzone.modules"
|
|
212
|
-
printf '%s\n' " readOnly: true"
|
|
213
|
-
printf '%s\n' " - name: etat"
|
|
214
|
-
printf '%s\n' " mountPath: /home/vscode/.config/opencode"
|
|
215
|
-
printf '%s\n' " subPath: .config/opencode"
|
|
216
|
-
printf '%s\n' " - name: etat"
|
|
217
|
-
printf '%s\n' " mountPath: /home/vscode/.local/share/opencode"
|
|
218
|
-
printf '%s\n' " subPath: .local/share/opencode"
|
|
219
|
-
printf '%s\n' " - name: etat"
|
|
220
|
-
printf '%s\n' " mountPath: /home/vscode/.local/state/oc-lancer"
|
|
221
|
-
printf '%s\n' " subPath: .local/state/oc-lancer"
|
|
222
|
-
printf '%s\n' " - name: etat"
|
|
223
|
-
printf '%s\n' " mountPath: /home/vscode/.local/npm"
|
|
224
|
-
printf '%s\n' " subPath: .local/npm"
|
|
225
|
-
printf '%s\n' " readOnly: true"
|
|
226
|
-
printf '%s\n' " - name: consigne"
|
|
227
|
-
printf '%s\n' " mountPath: /agent-consigne"
|
|
228
|
-
printf '%s\n' " readOnly: true"
|
|
229
|
-
printf '%s\n' " - name: session-workspace"
|
|
230
|
-
printf '%s\n' " mountPath: /workspaces/projets/workspace"
|
|
231
|
-
printf '%s\n' " command: [\"/bin/bash\", \"-lc\"]"
|
|
232
|
-
printf '%s\n' " args:"
|
|
233
|
-
printf '%s\n' " - 'devzone agent --local ${folder} /agent-consigne/consigne.md; code=\$?; cat \"\$DEVZONE_ROOT/workspace/.agents/${AGENT_POD_SESSION_LABEL}.log\" 2>/dev/null; exit \$code'"
|
|
234
|
-
printf '%s\n' " volumes:"
|
|
235
|
-
printf '%s\n' " - name: workspace"
|
|
236
|
-
printf '%s\n' " persistentVolumeClaim:"
|
|
237
|
-
printf '%s\n' " claimName: ${pvc_workspace}"
|
|
238
|
-
printf '%s\n' " - name: etat"
|
|
239
|
-
printf '%s\n' " persistentVolumeClaim:"
|
|
240
|
-
printf '%s\n' " claimName: ${pvc_etat}"
|
|
241
|
-
printf '%s\n' " - name: consigne"
|
|
242
|
-
printf '%s\n' " configMap:"
|
|
243
|
-
printf '%s\n' " name: ${pod_name}-consigne"
|
|
244
|
-
printf '%s\n' " - name: session-workspace"
|
|
245
|
-
printf '%s\n' " emptyDir:"
|
|
246
|
-
printf '%s\n' " sizeLimit: 256Mi"
|
|
247
|
-
} >"$manifest_file"
|
|
248
|
-
|
|
249
|
-
echo "$manifest_file"
|
|
250
|
-
}
|
|
@@ -1,243 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env bash
|
|
2
|
-
# Ephemeral session pod for devzone agent (#222).
|
|
3
|
-
# Sourced by agent.sh: launches the session pod (devzone agent --pod), waits for
|
|
4
|
-
# its end, keeps its log, deletes the pod and its ConfigMap, lists session pods (status).
|
|
5
|
-
#
|
|
6
|
-
# Constraints:
|
|
7
|
-
# - bash 3.2 compatible
|
|
8
|
-
# - shellcheck -x clean
|
|
9
|
-
# - no real cluster: kubectl is faked in tests
|
|
10
|
-
# - the pod and its ConfigMap are always deleted (EXIT, INT, TERM trap)
|
|
11
|
-
|
|
12
|
-
ICI="${ICI:-$(cd -P "$(dirname "${BASH_SOURCE[0]}")" && pwd)}"
|
|
13
|
-
# shellcheck source=agent-pod-manifest.sh disable=SC1091
|
|
14
|
-
. "${ICI}/agent-pod-manifest.sh"
|
|
15
|
-
|
|
16
|
-
# Resources of the current launch, read by the cleanup trap.
|
|
17
|
-
AGENT_POD_ACTIVE_NAME=""
|
|
18
|
-
AGENT_POD_ACTIVE_MANIFEST=""
|
|
19
|
-
AGENT_POD_CLEANED=0
|
|
20
|
-
|
|
21
|
-
# --- Pod and ConfigMap names ---
|
|
22
|
-
|
|
23
|
-
agent_pod_name() {
|
|
24
|
-
local base="${1:-}"
|
|
25
|
-
if [ -z "$base" ]; then
|
|
26
|
-
base="${AGENT_POD_SESSION_LABEL:-session}"
|
|
27
|
-
else
|
|
28
|
-
base="$(basename "$base")"
|
|
29
|
-
fi
|
|
30
|
-
# Kubernetes object names must be lowercase.
|
|
31
|
-
base="$(printf '%s' "$base" | tr '[:upper:]' '[:lower:]')"
|
|
32
|
-
echo "agent-${base}-$RANDOM"
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
agent_pod_configmap_name() {
|
|
36
|
-
echo "$1-consigne"
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
agent_pod_create_configmap() {
|
|
40
|
-
local pod_name="$1" consigne_file="$2"
|
|
41
|
-
kubectl create configmap "$(agent_pod_configmap_name "$pod_name")" \
|
|
42
|
-
--from-file=consigne.md="$consigne_file" >/dev/null 2>&1
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
agent_pod_delete_configmap() {
|
|
46
|
-
local pod_name="$1"
|
|
47
|
-
kubectl delete configmap "$(agent_pod_configmap_name "$pod_name")" >/dev/null 2>&1 || true
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
# --- Create the pod ---
|
|
51
|
-
|
|
52
|
-
agent_pod_create() {
|
|
53
|
-
local manifest_file="$1"
|
|
54
|
-
kubectl create -f "$manifest_file" >/dev/null 2>&1
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
# --- Wait for the pod to finish ---
|
|
58
|
-
|
|
59
|
-
agent_pod_wait() {
|
|
60
|
-
local pod_name="$1"
|
|
61
|
-
local elapsed=0
|
|
62
|
-
local max_wait="$DEVZONE_AGENT_POD_TIMEOUT"
|
|
63
|
-
local phase=""
|
|
64
|
-
|
|
65
|
-
while [ "$elapsed" -lt "$max_wait" ]; do
|
|
66
|
-
phase="$(kubectl get pod "$pod_name" -o jsonpath='{.status.phase}' 2>/dev/null)" || true
|
|
67
|
-
if [ "$phase" = "Succeeded" ] || [ "$phase" = "Failed" ]; then
|
|
68
|
-
echo "$phase"
|
|
69
|
-
return 0
|
|
70
|
-
fi
|
|
71
|
-
sleep 1
|
|
72
|
-
elapsed=$((elapsed + 1))
|
|
73
|
-
done
|
|
74
|
-
|
|
75
|
-
phase="$(kubectl get pod "$pod_name" -o jsonpath='{.status.phase}' 2>/dev/null)" || true
|
|
76
|
-
echo "${phase:-Unknown}"
|
|
77
|
-
return 1
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
# --- Keep the log of the session ---
|
|
81
|
-
|
|
82
|
-
# Init containers run before the agent: their log goes first, so a refused
|
|
83
|
-
# session shows the guard message. A failing `kubectl logs -c` is not fatal.
|
|
84
|
-
agent_pod_fetch_logs() {
|
|
85
|
-
local pod_name="$1" journal_file="$2"
|
|
86
|
-
local init_name
|
|
87
|
-
while IFS= read -r init_name; do
|
|
88
|
-
[ -n "$init_name" ] || continue
|
|
89
|
-
echo "=== init container ${init_name} ===" >>"$journal_file"
|
|
90
|
-
kubectl logs "$pod_name" -c "$init_name" >>"$journal_file" 2>/dev/null || true
|
|
91
|
-
done <<EOF
|
|
92
|
-
$(kubectl get pod "$pod_name" -o jsonpath='{.spec.initContainers[*].name}' 2>/dev/null || true)
|
|
93
|
-
EOF
|
|
94
|
-
kubectl logs "$pod_name" >>"$journal_file" 2>/dev/null || true
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
# Names the init container that stopped the pod on stderr: the launcher already
|
|
98
|
-
# shows the end of the log, which contains the message of the guard. Only the
|
|
99
|
-
# init containers that actually failed (exit code different from 0) are named.
|
|
100
|
-
agent_pod_init_failure() {
|
|
101
|
-
local pod_name="$1"
|
|
102
|
-
local cause name code
|
|
103
|
-
cause="$(kubectl get pod "$pod_name" -o jsonpath='{range .status.initContainerStatuses[?(@.state.terminated.exitCode)]}{.name}{" "}{.state.terminated.exitCode}{"\n"}{end}' 2>/dev/null)" || true
|
|
104
|
-
[ -n "$cause" ] || return 0
|
|
105
|
-
while IFS=' ' read -r name code; do
|
|
106
|
-
[ -n "$name" ] || continue
|
|
107
|
-
[ "${code:-0}" != 0 ] || continue
|
|
108
|
-
echo "devzone agent --pod : init container ${name} failed (exit ${code})" >&2
|
|
109
|
-
done <<EOF
|
|
110
|
-
${cause}
|
|
111
|
-
EOF
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
# Last lines of the log on stderr: the cause of a failure is there.
|
|
115
|
-
agent_pod_show_tail() {
|
|
116
|
-
local journal_file="$1"
|
|
117
|
-
tail -n 15 "$journal_file" >&2 || true
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
# --- Delete the pod ---
|
|
121
|
-
|
|
122
|
-
agent_pod_delete() {
|
|
123
|
-
local pod_name="$1"
|
|
124
|
-
kubectl delete pod "$pod_name" >/dev/null 2>&1 || true
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
# --- Status : list session pods with their limits ---
|
|
128
|
-
|
|
129
|
-
agent_pod_status() {
|
|
130
|
-
kubectl get pods -l "devzone.io/agent-session" \
|
|
131
|
-
-o jsonpath='{range .items[*]}{.metadata.name}{"\t"}{.spec.containers[0].resources.limits.cpu}{"\t"}{.spec.containers[0].resources.limits.memory}{"\n"}{end}' 2>/dev/null || true
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
# --- Cleanup trap: pod, ConfigMap, temporary manifest (not the log) ---
|
|
135
|
-
|
|
136
|
-
agent_pod_cleanup() {
|
|
137
|
-
if [ "$AGENT_POD_CLEANED" = 1 ]; then
|
|
138
|
-
return 0
|
|
139
|
-
fi
|
|
140
|
-
AGENT_POD_CLEANED=1
|
|
141
|
-
if [ -n "$AGENT_POD_ACTIVE_NAME" ]; then
|
|
142
|
-
agent_pod_delete "$AGENT_POD_ACTIVE_NAME"
|
|
143
|
-
agent_pod_delete_configmap "$AGENT_POD_ACTIVE_NAME"
|
|
144
|
-
fi
|
|
145
|
-
if [ -n "$AGENT_POD_ACTIVE_MANIFEST" ]; then
|
|
146
|
-
rm -f "$AGENT_POD_ACTIVE_MANIFEST"
|
|
147
|
-
fi
|
|
148
|
-
return 0
|
|
149
|
-
}
|
|
150
|
-
|
|
151
|
-
# Set before any object is created. INT and TERM leave with 130 / 143;
|
|
152
|
-
# EXIT keeps the exit code of the script.
|
|
153
|
-
agent_pod_set_trap() {
|
|
154
|
-
trap 'agent_pod_cleanup' EXIT
|
|
155
|
-
trap 'agent_pod_cleanup; exit 130' INT
|
|
156
|
-
trap 'agent_pod_cleanup; exit 143' TERM
|
|
157
|
-
}
|
|
158
|
-
|
|
159
|
-
# --- Launch a session agent in an ephemeral pod (devzone agent --pod) ---
|
|
160
|
-
|
|
161
|
-
agent_pod_launch() {
|
|
162
|
-
local folder_raw="${1:-}" consigne_raw="${2:-}"
|
|
163
|
-
local folder consigne pod_name journal_file phase manifest_file state
|
|
164
|
-
local rc=0
|
|
165
|
-
|
|
166
|
-
if [ "${DEVZONE_WORKSPACE:-}" != "kubernetes" ]; then
|
|
167
|
-
echo "devzone agent --pod : must be called from the workspace pod (DEVZONE_WORKSPACE=kubernetes)" >&2
|
|
168
|
-
exit 1
|
|
169
|
-
fi
|
|
170
|
-
|
|
171
|
-
if ! agent_pod_path_ok "$folder_raw"; then
|
|
172
|
-
echo "devzone agent --pod : invalid folder path : ${folder_raw:-}" >&2
|
|
173
|
-
exit 1
|
|
174
|
-
fi
|
|
175
|
-
if [ ! -d "$folder_raw" ]; then
|
|
176
|
-
echo "devzone agent --pod : folder not found : $folder_raw" >&2
|
|
177
|
-
exit 1
|
|
178
|
-
fi
|
|
179
|
-
folder="$(cd "$folder_raw" && pwd -P)" || {
|
|
180
|
-
echo "devzone agent --pod : folder not found : $folder_raw" >&2
|
|
181
|
-
exit 1
|
|
182
|
-
}
|
|
183
|
-
if [ ! -r "${consigne_raw:-}" ]; then
|
|
184
|
-
echo "devzone agent --pod : brief not found : ${consigne_raw:-}" >&2
|
|
185
|
-
exit 1
|
|
186
|
-
fi
|
|
187
|
-
consigne="$(cd "$(dirname "$consigne_raw")" && pwd -P)/$(basename "$consigne_raw")"
|
|
188
|
-
|
|
189
|
-
if ! agent_pod_validate_folder "$folder"; then
|
|
190
|
-
exit 1
|
|
191
|
-
fi
|
|
192
|
-
# The pod mounts this file read-only: refuse before any object is created.
|
|
193
|
-
if [ ! -f "$AGENT_POD_MODULES_FILE" ]; then
|
|
194
|
-
echo "devzone agent --pod : modules file missing : $AGENT_POD_MODULES_FILE (run devzone enable ai on the workspace)" >&2
|
|
195
|
-
exit 1
|
|
196
|
-
fi
|
|
197
|
-
|
|
198
|
-
# The log of the session stays in the agent state directory (shared with the pod).
|
|
199
|
-
state="${AGENT_STATE:-$HOME/.local/state/oc-lancer}"
|
|
200
|
-
mkdir -p "$state"
|
|
201
|
-
journal_file="$state/${AGENT_POD_SESSION_LABEL}.pod.log"
|
|
202
|
-
: >"$journal_file"
|
|
203
|
-
|
|
204
|
-
pod_name="$(agent_pod_name "$folder")"
|
|
205
|
-
AGENT_POD_ACTIVE_NAME="$pod_name"
|
|
206
|
-
agent_pod_set_trap
|
|
207
|
-
|
|
208
|
-
if ! agent_pod_create_configmap "$pod_name" "$consigne"; then
|
|
209
|
-
echo "devzone agent --pod : unable to create the configmap" >&2
|
|
210
|
-
exit 1
|
|
211
|
-
fi
|
|
212
|
-
|
|
213
|
-
manifest_file="$(agent_pod_build_manifest "$folder" "$consigne" "$pod_name")" || {
|
|
214
|
-
echo "devzone agent --pod : unable to build the manifest" >&2
|
|
215
|
-
exit 1
|
|
216
|
-
}
|
|
217
|
-
AGENT_POD_ACTIVE_MANIFEST="$manifest_file"
|
|
218
|
-
|
|
219
|
-
if ! agent_pod_create "$manifest_file"; then
|
|
220
|
-
echo "devzone agent --pod : unable to create the pod (kubectl create -f)" >&2
|
|
221
|
-
echo "devzone agent --pod : try again without --pod" >&2
|
|
222
|
-
exit 1
|
|
223
|
-
fi
|
|
224
|
-
|
|
225
|
-
phase="$(agent_pod_wait "$pod_name")" || rc=$?
|
|
226
|
-
agent_pod_fetch_logs "$pod_name" "$journal_file"
|
|
227
|
-
echo "=== end of agent session in pod (phase: ${phase:-Unknown})" >>"$journal_file"
|
|
228
|
-
if [ "$rc" -ne 0 ] || [ "$phase" = "Failed" ]; then
|
|
229
|
-
agent_pod_init_failure "$pod_name"
|
|
230
|
-
fi
|
|
231
|
-
agent_pod_show_tail "$journal_file"
|
|
232
|
-
|
|
233
|
-
if [ "$rc" -ne 0 ]; then
|
|
234
|
-
echo "devzone agent --pod : pod did not finish in time (phase: ${phase:-Unknown}) ; log : $journal_file" >&2
|
|
235
|
-
exit 1
|
|
236
|
-
fi
|
|
237
|
-
if [ "$phase" = "Failed" ]; then
|
|
238
|
-
echo "devzone agent --pod : session ended in failure ; log : $journal_file" >&2
|
|
239
|
-
exit 1
|
|
240
|
-
fi
|
|
241
|
-
echo "devzone agent --pod : session ended (phase: $phase) ; log : $journal_file" >&2
|
|
242
|
-
exit 0
|
|
243
|
-
}
|