devzone 7.5.0 → 7.5.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.
@@ -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
- }
@@ -1,184 +0,0 @@
1
- #!/usr/bin/env bash
2
- # devzone workspace egress observation|strict|off|status|allow <domain>|deny <domain>
3
- # (#633), sourced by manage/workspace.sh after workspace-update.sh.
4
- # egress_workspace <subcommand> [domain] dispatch of the command above
5
- # egress_params key=value parameters of the chart, replayed
6
- # by workspace_deploy at each start and update
7
- # The mode and the added domains are kept in .devzone.modules (egress=,
8
- # egress_domains=, state_read and state_note of argocd-workspace.sh). Each
9
- # change redeploys the workspace at the image it runs: same image tag, same
10
- # Argo CD revision, the pod is not recreated. Only the devzone agent sessions
11
- # started with --pod go through the proxy in strict mode. bash 3.2 (macOS).
12
-
13
- # Base list of the chart (egressProxy.allowedDomains in values.yaml): not
14
- # editable with allow or deny, changed in the chart
15
- EGRESS_BASE=".opencode.ai .npmjs.org .github.com"
16
-
17
- # Domain: lowercase letters, digits, hyphens and dots, at least one dot, an
18
- # optional leading dot (subdomains); no space, comma, * or /
19
- egress_domain_ok() {
20
- printf '%s\n' "$1" | grep -Eq '^\.?[a-z0-9-]+(\.[a-z0-9-]+)+$'
21
- }
22
-
23
- # Chart parameters of the proxy from .devzone.modules: nothing when off (or
24
- # unset), else enabled, mode and the added domains (comma-separated)
25
- egress_params() {
26
- local mode domains
27
- mode="$(state_read egress)"
28
- case "$mode" in
29
- observation | strict) ;;
30
- *) return 0 ;;
31
- esac
32
- printf 'egressProxy.enabled=true egressProxy.mode=%s' "$mode"
33
- domains="$(state_read egress_domains)"
34
- if [ -n "$domains" ]; then printf ' egressProxy.extraDomains=%s' "$domains"; fi
35
- }
36
-
37
- # Waits for the proxy after the redeploy. Argo CD creates its Deployment a few
38
- # seconds to a minute after the sync: the Deployment is looked up every
39
- # DEVZONE_EGRESS_STEP s (3 by default) up to DEVZONE_EGRESS_WAIT s (90 by
40
- # default); then its rollout is awaited for DEVZONE_EGRESS_ROLLOUT s (120 by
41
- # default). Returns 1 when either is not reached.
42
- egress_wait_proxy() {
43
- local limit="${DEVZONE_EGRESS_WAIT:-90}" rollout="${DEVZONE_EGRESS_ROLLOUT:-120}" pas="${DEVZONE_EGRESS_STEP:-3}" attendu=0
44
- until ak -n "$NAMESPACE" get deployment devzone-workspace-egress-proxy >/dev/null 2>&1; do
45
- if [ "$attendu" -ge "$limit" ]; then
46
- echo "⚠ the egress proxy was not created by Argo CD after $limit s: the setting is kept, check devzone workspace argocd status" >&2
47
- return 1
48
- fi
49
- if [ $((limit - attendu)) -lt "$pas" ]; then pas=$((limit - attendu)); fi
50
- sleep "$pas"
51
- attendu=$((attendu + pas))
52
- done
53
- if ! ak -n "$NAMESPACE" rollout status deployment/devzone-workspace-egress-proxy --timeout="${rollout}s"; then
54
- echo "⚠ egress proxy not ready after $rollout s: the setting is kept, see devzone workspace egress status" >&2
55
- return 1
56
- fi
57
- }
58
-
59
- # Redeploys the workspace at the image of the current Argo CD Application
60
- # (targetRevision and image.tag, as update_current); then waits for the proxy
61
- # when it is on. Without Application (helm direct), the setting is only kept:
62
- # devzone workspace start applies it.
63
- egress_redeploy() {
64
- local rev tag
65
- read -r rev tag <<<"$(update_current)" || true
66
- if [ -z "$rev" ] || [ -z "$tag" ]; then
67
- echo "ℹ no Argo CD Application: the setting is kept, devzone workspace start applies it"
68
- return 0
69
- fi
70
- export DEVZONE_ARGOCD_REVISION="$rev"
71
- workspace_deploy "$IMAGE_REPO" "$tag" "" || return 1
72
- if [ -n "$(egress_params)" ]; then
73
- echo "▶ waiting for the egress proxy…"
74
- egress_wait_proxy || return 1
75
- fi
76
- }
77
-
78
- # observation | strict | off: memorised, then the workspace is redeployed
79
- egress_set_mode() {
80
- kube_ready_reason --hint >&2 || return 1
81
- state_note egress "$1"
82
- egress_redeploy || return 1
83
- echo "✔ egress $1"
84
- if [ "$1" = strict ]; then
85
- echo "ℹ strict: only the devzone agent sessions started with --pod are filtered; the workspace stays open"
86
- fi
87
- }
88
-
89
- # allow | deny <domain>: the list of added domains has no duplicate; deny only
90
- # removes what was added, never the base list
91
- egress_domain_edit() {
92
- local action="$1" domain="$2" list new base=no present=no
93
- if ! egress_domain_ok "$domain"; then
94
- echo "✖ domain not valid: $domain (lowercase letters, digits, hyphens and dots, at least one dot, optional leading dot; no space, comma, * or /)" >&2
95
- return 1
96
- fi
97
- case " $EGRESS_BASE " in *" $domain "*) base=yes ;; esac
98
- list="$(state_read egress_domains)"
99
- case ",$list," in *",$domain,"*) present=yes ;; esac
100
- if [ "$action" = allow ]; then
101
- if [ "$base" = yes ]; then
102
- echo "ℹ $domain is in the base list (egressProxy.allowedDomains): already allowed"
103
- return 0
104
- fi
105
- if [ "$present" = yes ]; then
106
- echo "ℹ already allowed: $domain"
107
- return 0
108
- fi
109
- new="${list:+$list,}$domain"
110
- else
111
- if [ "$base" = yes ]; then
112
- echo "✖ $domain is in the base list: change it in egressProxy.allowedDomains of the chart (nothing changed)" >&2
113
- return 1
114
- fi
115
- if [ "$present" = no ]; then
116
- echo "✖ $domain was not added with allow: nothing changed" >&2
117
- return 1
118
- fi
119
- new="$(printf '%s' "$list" | tr ',' '\n' | grep -vxF -- "$domain" | paste -sd, -)" || new=""
120
- fi
121
- kube_ready_reason --hint >&2 || return 1
122
- state_note egress_domains "$new"
123
- echo "✔ $action $domain"
124
- egress_redeploy
125
- }
126
-
127
- # Mode of the proxy (label of its Service, off when none), readiness, number of
128
- # allowed domains (ACL lines of the ConfigMap), then the domains contacted in
129
- # the last 2000 lines of the access log: count and state (allowed, refused, or
130
- # observed in observation mode). Columns of the squid native log: 4 result, 6
131
- # method, 7 host:port.
132
- egress_status() {
133
- local mode ready count table
134
- kube_ready_reason --hint >&2 || return 1
135
- mode="$(ak -n "$NAMESPACE" get service egress-proxy -o 'jsonpath={.metadata.labels.devzone\.io/egress-mode}' 2>/dev/null)" || mode=""
136
- if [ -z "$mode" ]; then
137
- echo "egress off"
138
- return 0
139
- fi
140
- ready="$(ak -n "$NAMESPACE" get deployment devzone-workspace-egress-proxy -o 'jsonpath={.status.readyReplicas}' 2>/dev/null || true)"
141
- if [ "${ready:-0}" -ge 1 ] 2>/dev/null; then ready="ready"; else ready="not ready"; fi
142
- count="$(ak -n "$NAMESPACE" get configmap devzone-workspace-egress-proxy -o 'jsonpath={.data.squid\.conf}' 2>/dev/null |
143
- grep -c 'acl allowed dstdomain ' || true)"
144
- echo "egress $mode, proxy $ready, allowed domains: ${count:-0}"
145
- table="$(ak -n "$NAMESPACE" logs deployment/devzone-workspace-egress-proxy -c access-log --tail=2000 2>/dev/null |
146
- awk -v mode="$mode" '
147
- $6 == "CONNECT" {
148
- host = $7
149
- sub(/:[0-9]+$/, "", host)
150
- hits[host]++
151
- if ($4 ~ /DENIED/) refused[host] = 1
152
- }
153
- END {
154
- for (h in hits) {
155
- state = refused[h] ? "refused" : (mode == "observation" ? "observed" : "allowed")
156
- printf " %-40s %6d %s\n", h, hits[h], state
157
- }
158
- }' | sort)" || table=""
159
- if [ -z "$table" ]; then
160
- echo " no domain contacted in the recent log"
161
- else
162
- printf ' %-40s %6s %s\n' domain accesses state
163
- echo "$table"
164
- fi
165
- }
166
-
167
- # Dispatch of devzone workspace egress
168
- egress_workspace() {
169
- case "${1:-}" in
170
- observation | strict | off) egress_set_mode "$1" ;;
171
- status) egress_status ;;
172
- allow | deny)
173
- if [ "$#" -ne 2 ]; then
174
- echo "✖ egress $1 takes one domain: devzone workspace egress $1 <domain>" >&2
175
- return 1
176
- fi
177
- egress_domain_edit "$1" "$2"
178
- ;;
179
- *)
180
- echo "✖ unknown egress argument: ${1:-none} (devzone workspace egress observation|strict|off|status|allow <domain>|deny <domain>)" >&2
181
- return 1
182
- ;;
183
- esac
184
- }
@@ -1,106 +0,0 @@
1
- #!/usr/bin/env bash
2
- # devzone workspace update [--version X.Y.Z] [--yes] (#622): the workspace moves
3
- # to the latest stable release, or to X.Y.Z: image, charts and Argo CD
4
- # Application at that tag. Sourced by manage/workspace.sh, which defines
5
- # IMAGE_REPO, kube_ready_reason, workspace_deploy, services_reconcile and the
6
- # Argo CD helpers (argocd-workspace.sh, argocd-services.sh).
7
- # update_workspace [--version X.Y.Z] [--yes]
8
- # Nothing is written before the image of the release is seen on ghcr.io and
9
- # the update is confirmed (--yes is required without a terminal). No gh, no
10
- # Docker: git ls-remote for the tags, curl for the registry. The registry token
11
- # is read into a variable and only sent in a request, never printed. bash 3.2
12
- # (macOS).
13
-
14
- # Latest stable release: tags vX.Y.Z only (no pre-release), in version order;
15
- # prints its number without the v, nothing when none is found
16
- update_latest_version() {
17
- git ls-remote --tags --refs "$DEVZONE_REPO_URL" 2>/dev/null |
18
- awk '$2 ~ /^refs\/tags\/v[0-9]+\.[0-9]+\.[0-9]+$/ { sub("refs/tags/v", "", $2); print $2 }' |
19
- sort -V | tail -1
20
- }
21
-
22
- # The image of the release on ghcr.io: anonymous pull token, then the manifest
23
- # headers. Status 0 when the image exists; a failing network counts as absent
24
- update_image_exists() {
25
- local repo_path="${IMAGE_REPO#ghcr.io/}" token
26
- token="$(curl -fsS "https://ghcr.io/token?scope=repository:$repo_path:pull" 2>/dev/null |
27
- sed -n 's/.*"token" *: *"\([^"]*\)".*/\1/p')" || token=""
28
- [ -n "$token" ] || return 1
29
- curl -fsSI -H "Authorization: Bearer $token" \
30
- -H "Accept: application/vnd.oci.image.index.v1+json,application/vnd.docker.distribution.manifest.list.v2+json" \
31
- "https://ghcr.io/v2/$repo_path/manifests/$1" >/dev/null 2>&1
32
- }
33
-
34
- # "<targetRevision> <image.tag>" of the Application devzone-workspace; empty
35
- # when there is none (workspace installed with helm direct)
36
- update_current() {
37
- ak -n "$ARGOCD_NS" get application.argoproj.io "$WORKSPACE_APP" \
38
- -o jsonpath='{.spec.source.targetRevision} {.spec.source.helm.parameters[?(@.name=="image.tag")].value}' 2>/dev/null || true
39
- }
40
-
41
- update_workspace() {
42
- local version="" yes=no answer
43
- while [ $# -gt 0 ]; do
44
- case "$1" in
45
- --version)
46
- if [ $# -lt 2 ] || [ -z "$2" ]; then
47
- echo "✖ option --version: give X.Y.Z (devzone workspace update [--version X.Y.Z] [--yes])" >&2
48
- return 1
49
- fi
50
- version="$2"
51
- shift 2
52
- ;;
53
- --yes)
54
- yes=yes
55
- shift
56
- ;;
57
- *)
58
- echo "✖ unknown option: $1 (devzone workspace update [--version X.Y.Z] [--yes])" >&2
59
- return 1
60
- ;;
61
- esac
62
- done
63
- kube_ready_reason --hint >&2 || return 1
64
- if [ -n "$version" ]; then
65
- grep -Eq '^[0-9]+\.[0-9]+\.[0-9]+$' <<<"$version" || {
66
- echo "✖ option --version: expected X.Y.Z, got: $version" >&2
67
- return 1
68
- }
69
- else
70
- version="$(update_latest_version || true)"
71
- [ -n "$version" ] || {
72
- echo "✖ no stable release found in $DEVZONE_REPO_URL (network, or no vX.Y.Z tag): nothing changed" >&2
73
- return 1
74
- }
75
- fi
76
- if ! update_image_exists "$version"; then
77
- echo "✖ image $IMAGE_REPO:$version not found on ghcr.io (the release may still be publishing, or the network is down): nothing changed" >&2
78
- return 1
79
- fi
80
- if [ "$(update_current)" = "v$version $version" ]; then
81
- echo "✔ already up to date: v$version"
82
- return 0
83
- fi
84
- echo "⚠ the workspace pod will be recreated: the VS Code windows attached to it will disconnect"
85
- if [ "$yes" != yes ]; then
86
- if [ ! -t 0 ]; then
87
- echo "✖ no terminal to confirm: run again with --yes (devzone workspace update --yes)" >&2
88
- return 1
89
- fi
90
- read -r -p "Update the workspace to v$version? [y/N] " answer || answer=""
91
- case "$answer" in
92
- y | Y | yes) ;;
93
- *)
94
- echo "✖ canceled, nothing changed" >&2
95
- return 1
96
- ;;
97
- esac
98
- fi
99
- # Same path as workspace start, at the release: Argo CD revision and image tag
100
- export DEVZONE_ARGOCD_REVISION="v$version"
101
- workspace_deploy "$IMAGE_REPO" "$version" ""
102
- if argocd_holds_charts; then
103
- services_reconcile || return 1
104
- fi
105
- echo "✔ workspace on v$version; follow the rollout: devzone workspace status"
106
- }
@@ -1,56 +0,0 @@
1
- #!/usr/bin/env bash
2
- # Waits for the workspace pod after helm upgrade (#486, #494, #512), sourced by
3
- # manage/workspace.sh: moved here to keep workspace.sh under 250 lines (#515).
4
- # Uses kubectl_flag and helm_flag from workspace.sh.
5
-
6
- # Waits for the workspace pod; missing image or slow pod are reported clearly.
7
- wait_for_pod() {
8
- local image="$1" timeout step start state events arch target_revision pod_revision
9
- timeout="${DEVZONE_WORKSPACE_WAIT:-120}"
10
- step="${DEVZONE_WORKSPACE_STEP:-2}"
11
- start="$SECONDS"
12
- while [ $((SECONDS - start)) -lt "$timeout" ]; do
13
- # Why: after helm upgrade the pod is still the old one; judge only the revision the StatefulSet is updating to, within the same wait bound.
14
- # shellcheck disable=SC2046
15
- target_revision="$(kubectl $(kubectl_flag) get statefulset devzone-workspace --namespace devzone-workspace -o jsonpath='{.status.updateRevision}' 2>/dev/null)" || true
16
- # shellcheck disable=SC2046
17
- pod_revision="$(kubectl $(kubectl_flag) get pod devzone-workspace-0 --namespace devzone-workspace -o jsonpath='{.metadata.labels.controller-revision-hash}' 2>/dev/null)" || true
18
- if [ -z "$target_revision" ] || [ -z "$pod_revision" ] || [ "$target_revision" != "$pod_revision" ]; then sleep "$step"; continue; fi
19
- # shellcheck disable=SC2046
20
- state="$(kubectl $(kubectl_flag) get pod devzone-workspace-0 --namespace devzone-workspace \
21
- -o jsonpath='{.status.phase} {.status.initContainerStatuses[*].state.waiting.reason} {.status.containerStatuses[*].state.waiting.reason}' 2>/dev/null)" || true
22
- case "$state" in
23
- *ErrImagePull* | *ImagePullBackOff*)
24
- # shellcheck disable=SC2046
25
- events="$(kubectl $(kubectl_flag) get events --namespace devzone-workspace \
26
- --field-selector involvedObject.name=devzone-workspace-0 \
27
- -o jsonpath='{.items[*].message}' 2>/dev/null)" || true
28
- case "$events" in
29
- *"no match for platform"*)
30
- # shellcheck disable=SC2046
31
- arch="$(kubectl $(kubectl_flag) get nodes \
32
- -o jsonpath='{.items[0].status.nodeInfo.architecture}' 2>/dev/null)" || true
33
- echo "✖ image $image has no build for $arch: devzone releases publish it for amd64 and arm64." >&2
34
- ;;
35
- *)
36
- echo "✖ image $image not found: it is published at each devzone release." >&2
37
- ;;
38
- esac
39
- echo " For a manually built image: devzone workspace start --image <repository:tag>" >&2
40
- # Argo CD Application or helm release (#516): selfHeal would otherwise recreate the pod
41
- workspace_undeploy >/dev/null 2>&1 || true
42
- return 1
43
- ;;
44
- Running*)
45
- echo "✔ workspace started ($image)"
46
- return 0
47
- ;;
48
- esac
49
- sleep "$step"
50
- done
51
- echo "⚠ pod not ready after $timeout s: devzone workspace status" >&2
52
- return 0
53
- }
54
-
55
- # compatibility alias, removed with lot 4 (#509)
56
- attendre_pod() { wait_for_pod "$@"; }