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.
Files changed (50) hide show
  1. package/.devcontainer/devcontainer.json +1 -1
  2. package/.devcontainer/devzone +13 -20
  3. package/.devcontainer/devzone-modules.sh +1 -1
  4. package/.devcontainer/devzone-repair.sh +2 -2
  5. package/.devcontainer/devzone-services.sh +7 -7
  6. package/.devcontainer/devzone-status.sh +5 -5
  7. package/.devcontainer/help.sh +3 -1
  8. package/.devcontainer/versions.env +3 -0
  9. package/.devcontainer/workspace-init.sh +8 -9
  10. package/.gitattributes +8 -0
  11. package/README.md +1 -1
  12. package/bin/SHA256SUMS +6 -6
  13. package/bin/devzone-darwin-amd64 +0 -0
  14. package/bin/devzone-darwin-arm64 +0 -0
  15. package/bin/devzone-linux-amd64 +0 -0
  16. package/bin/devzone-linux-arm64 +0 -0
  17. package/bin/devzone-windows-amd64.exe +0 -0
  18. package/bin/devzone-windows-arm64.exe +0 -0
  19. package/charts/devzone-mysql/values.yaml +1 -1
  20. package/charts/devzone-postgres/values.yaml +1 -1
  21. package/manage/devzone +2 -2
  22. package/manage/scripts/uninstall.sh +1 -1
  23. package/manage/scripts/workspace/argocd-workspace.sh +2 -2
  24. package/package.json +1 -1
  25. package/.devcontainer/agent-errors.sh +0 -156
  26. package/.devcontainer/agent-local.sh +0 -63
  27. package/.devcontainer/agent-model.sh +0 -113
  28. package/.devcontainer/agent-pod-egress.sh +0 -36
  29. package/.devcontainer/agent-pod-manifest.sh +0 -250
  30. package/.devcontainer/agent-pod.sh +0 -243
  31. package/.devcontainer/agent-session.sh +0 -242
  32. package/.devcontainer/agent-state-json.sh +0 -117
  33. package/.devcontainer/agent-workspace.sh +0 -97
  34. package/.devcontainer/agent.sh +0 -247
  35. package/.devcontainer/catalog/app.sh +0 -202
  36. package/.devcontainer/catalog/catalog-watcher.sh +0 -127
  37. package/.devcontainer/catalog.sh +0 -208
  38. package/.devcontainer/chart-direct.sh +0 -49
  39. package/.devcontainer/cluster.sh +0 -388
  40. package/.devcontainer/clusters.sh +0 -86
  41. package/.devcontainer/devzone-cluster.sh +0 -209
  42. package/.devcontainer/isolation.sh +0 -65
  43. package/.devcontainer/kube-account.sh +0 -107
  44. package/.devcontainer/kube-prompt.sh +0 -42
  45. package/.devcontainer/memory.sh +0 -113
  46. package/.devcontainer/metrics-server.sh +0 -100
  47. package/.devcontainer/packages.sh +0 -228
  48. package/.devcontainer/password.sh +0 -148
  49. package/.devcontainer/ports-json.sh +0 -31
  50. package/.devcontainer/ports.sh +0 -132
@@ -1,86 +0,0 @@
1
- #!/usr/bin/env bash
2
- # View of the connected clusters (#337): visible contexts, type, state, namespace.
3
- ICI="$(cd -P "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
4
- if ! declare -F cluster_is_local >/dev/null 2>&1; then
5
- # shellcheck source=SCRIPTDIR/cluster.sh
6
- # shellcheck disable=SC1091
7
- . "$ICI/cluster.sh"
8
- fi
9
-
10
- # Shows the view of the connected clusters.
11
- clusters_show() {
12
- local contexts=() ctx ctx_work ctx_services tmp i ns type state mark marks
13
- ctx_work="$(kubectl config current-context 2>/dev/null || true)"
14
- ctx_services="$(cluster_saved 2>/dev/null || true)"
15
- while IFS= read -r ctx; do
16
- [ -n "$ctx" ] || continue
17
- contexts+=("$ctx")
18
- done < <(kubectl config get-contexts -o name 2>/dev/null || true)
19
-
20
- if [ "${#contexts[@]}" -eq 0 ]; then
21
- echo "no cluster: kind create cluster, or devzone enable kubernetes"
22
- return 0
23
- fi
24
-
25
- printf '%s %-14s %-8s %-12s %s\n' " " "CONTEXT" "TYPE" "STATE" "NAMESPACE"
26
- tmp="$(mktemp -d)"
27
- for i in "${!contexts[@]}"; do
28
- ctx="${contexts[$i]}"
29
- (
30
- if kubectl --context "$ctx" --request-timeout=3s get --raw /readyz >/dev/null 2>&1; then
31
- echo reachable
32
- else
33
- echo unreachable
34
- fi
35
- ) >"$tmp/$i" &
36
- done
37
- wait
38
- for i in "${!contexts[@]}"; do
39
- ctx="${contexts[$i]}"
40
- state="$(cat "$tmp/$i" 2>/dev/null || echo unreachable)"
41
- if cluster_is_local "$ctx" >/dev/null 2>&1; then
42
- type=local
43
- else
44
- type=remote
45
- fi
46
- ns="$(kubectl config view -o jsonpath="{.contexts[?(@.name==\"$ctx\")].context.namespace}" 2>/dev/null || true)"
47
- [ -n "$ns" ] || ns=default
48
- mark=""
49
- marks=0
50
- if [ "$ctx" = "$ctx_work" ]; then
51
- mark+="★"
52
- marks=$((marks + 1))
53
- fi
54
- if [ "$ctx" = "$ctx_services" ]; then
55
- mark+="●"
56
- marks=$((marks + 1))
57
- fi
58
- while [ "$marks" -lt 2 ]; do
59
- mark+=" "
60
- marks=$((marks + 1))
61
- done
62
- printf '%s %-14s %-8s %-12s %s\n' "$mark" "$ctx" "$type" "$state" "$ns"
63
- done
64
- rm -rf "$tmp"
65
- echo
66
- echo "★ working cluster (kubectl, k9s, helm) · ● devzone services cluster (devzone cluster)"
67
- # Display of the NetworkPolicy isolation state for the services cluster
68
- if [ -n "$ctx_services" ] && cluster_is_local "$ctx_services"; then
69
- if kubectl --context "$ctx_services" get networkpolicy devzone-meme-namespace -n devzone-postgres >/dev/null 2>&1; then
70
- printf ' ✔ isolated (NetworkPolicy) → %s\n' "$ctx_services"
71
- else
72
- printf ' ⚠ isolated (NetworkPolicy missing) → %s\n' "$ctx_services"
73
- fi
74
- printf ' devzone → %s\n' "$ctx_services"
75
- fi
76
- return 0
77
- }
78
-
79
- # Aliases of the devzone clusters command.
80
- clusters() { clusters_show "$@"; }
81
- # Alias for the tests and direct calls.
82
- devzone_clusters() { clusters_show "$@"; }
83
-
84
- if [ "${BASH_SOURCE[0]}" = "$0" ]; then
85
- clusters_show "$@"
86
- fi
@@ -1,209 +0,0 @@
1
- #!/usr/bin/env bash
2
- # shellcheck shell=bash
3
- # devzone, working cluster: change, use.
4
- # Sourced by .devcontainer/devzone (split of the 1 600 lines file, #722):
5
- # functions only, shared variables are defined in devzone.
6
-
7
- # All the databases disappear: confirmation in the terminal (without a terminal,
8
- # the command is explicit); a yes or --yes sets DELETE_DATA, read by
9
- # apply_mysql to run delete-data (#441); only --yes reaches this function.
10
- confirm_removal() {
11
- local app="$1" answer arg
12
- DELETE_DATA=""
13
- [ "$(value_of "$app")" = on ] || return 0
14
- for arg in "${@:2}"; do
15
- case "$arg" in --yes) DELETE_DATA=1 ;; esac
16
- done
17
- [ -z "$DELETE_DATA" ] || return 0
18
- cluster_interactive || return 0
19
- # mysql: the question is about the namespace (volume and databases stay);
20
- # postgres: everything goes, the refusal cancels; gitlab: the Rails secret
21
- # stays, its deletion only happens on a full uninstall on purpose
22
- if [ "$app" = mysql ]; then
23
- printf 'Disabling mysql removes the server; the volume and databases stay. Also delete the devzone-mysql namespace and its volumes? [y/N] ' >&2
24
- elif [ "$app" = gitlab ]; then
25
- printf 'Disabling gitlab keeps the Rails secret (browser sessions stay valid at reinstall). Also delete the Rails secret? [y/N] ' >&2
26
- else
27
- printf 'Disabling %s deletes all its databases. Continue? [y/N] ' "$app" >&2
28
- fi
29
- read -r answer || answer=""
30
- case "$answer" in
31
- y | Y | yes) DELETE_DATA=1; return 0 ;;
32
- esac
33
- # refusal: mysql and gitlab still disable (data kept), postgres cancels
34
- case "$app" in
35
- mysql | gitlab) return 0 ;;
36
- *) echo "Aborted: nothing was deleted."; return 1 ;;
37
- esac
38
- }
39
-
40
- # devzone cluster [CTX] [--yes]: shows the services cluster, or moves the
41
- # services to it (uninstalled from the old one, installed on the new one: data
42
- # not migrated, hence the confirmation)
43
- change_cluster() {
44
- local wanted="" yes="" confirm_ctx="" expect="" arg current new answer ctx_old ctx_new NS
45
- NS=devzone-postgres
46
- for arg in "$@"; do
47
- if [ -n "$expect" ]; then
48
- confirm_ctx="$arg"
49
- expect=""
50
- continue
51
- fi
52
- case "$arg" in
53
- --yes) yes=1 ;;
54
- --confirm) expect=1 ;;
55
- -*) echo "devzone : unknown argument: $arg (devzone cluster [CTX] [--yes] [--confirm CTX])" >&2; return 2 ;;
56
- *) wanted="$arg" ;;
57
- esac
58
- done
59
- if [ -n "$expect" ]; then
60
- echo "devzone : --confirm expects a context" >&2
61
- return 2
62
- fi
63
- current="$(cluster_saved)"
64
- if [ -z "$wanted" ]; then
65
- if [ -z "$current" ]; then
66
- echo "devzone : no cluster chosen (set when a module is enabled: devzone enable postgres)"
67
- elif cluster_is_dedicated "$current"; then
68
- echo "devzone : cluster $current (dedicated kind, in the container)"
69
- else
70
- echo "devzone : cluster $current (host cluster)"
71
- fi
72
- echo " possible: $(cluster_candidates | tr '\n' ' ')"
73
- return 0
74
- fi
75
- if [ -n "$confirm_ctx" ]; then
76
- new="$(cluster_choose "$wanted" --confirm "$confirm_ctx")" || return 2
77
- else
78
- new="$(cluster_choose "$wanted")" || return 2
79
- fi
80
- if [ "$new" = "$current" ]; then
81
- echo "devzone : already on $new, nothing to do."
82
- return 0
83
- fi
84
- ctx_old="$current"
85
- ctx_new="$new"
86
- if [ "$(value_of postgres)" = on ]; then
87
- if [ -z "$yes" ]; then
88
- if ! cluster_interactive; then
89
- echo "devzone : the postgres databases will be deleted from $ctx_old (not migrated): devzone cluster $ctx_new --yes" >&2
90
- return 1
91
- fi
92
- printf 'postgres will be reinstalled on %s, its databases deleted from %s (not migrated). Continue? [y/N] ' "$ctx_new" "$ctx_old" >&2
93
- read -r answer || answer=""
94
- case "$answer" in
95
- y | Y | yes) ;;
96
- *) echo "Aborted: nothing changed."; return 0 ;;
97
- esac
98
- fi
99
- # Removes PostgreSQL from the old cluster (explicit context);
100
- # namespace and RoleBinding by the administrator (#430)
101
- export KUBECONFIG="$HOME/.kube/config:$HOME/.kube/hote.config"
102
- account_remove "$ctx_old" "$NS" >/dev/null 2>&1 || true
103
- account_admin "$ctx_old" delete namespace "$NS" --wait=true >/dev/null 2>&1 || true
104
- cluster_release "$ctx_old"
105
- # The new cluster becomes the devzone context
106
- cluster_save "$ctx_new"
107
- # Sets the devzone context on the new cluster (cluster + user:
108
- # important command, failure shown and rendered #396)
109
- if ! devzone_context_set "$ctx_new"; then
110
- echo "devzone : cannot set the devzone context on $ctx_new" >&2
111
- return 1
112
- fi
113
- # Installs PostgreSQL on the new cluster (via --context devzone which now points to it)
114
- devzone postgres install
115
- else
116
- cluster_save "$ctx_new"
117
- # Sets the devzone context on the new cluster (cluster + user:
118
- # important command, failure shown and rendered #396)
119
- if ! devzone_context_set "$ctx_new"; then
120
- echo "devzone : cannot set the devzone context on $ctx_new" >&2
121
- return 1
122
- fi
123
- fi
124
- echo "devzone : services cluster: $ctx_new"
125
- }
126
-
127
- # Switches the user's working cluster (#341). Never touches the devzone services
128
- # cluster: no cluster_save, no cluster= line in the state.
129
- use_cluster() {
130
- local ctx="" confirm_ctx="" namespace="" answer arg current
131
- while [ "$#" -gt 0 ]; do
132
- arg="$1"
133
- shift
134
- case "$arg" in
135
- -n | --namespace)
136
- if [ "$#" -eq 0 ]; then
137
- echo "devzone : -n expects a namespace" >&2
138
- return 2
139
- fi
140
- namespace="$1"
141
- shift
142
- ;;
143
- --namespace=*) namespace="${arg#*=}" ;;
144
- --confirm)
145
- if [ "$#" -eq 0 ]; then
146
- echo "devzone : --confirm expects a context" >&2
147
- return 2
148
- fi
149
- confirm_ctx="$1"
150
- shift
151
- ;;
152
- --confirm=*) confirm_ctx="${arg#*=}" ;;
153
- -*)
154
- echo "devzone : unknown argument: $arg (devzone use CTX [-n NS] [--confirm CTX])" >&2
155
- return 2
156
- ;;
157
- *)
158
- if [ -n "$ctx" ]; then
159
- echo "devzone : unknown argument: $arg (devzone use CTX [-n NS] [--confirm CTX])" >&2
160
- return 2
161
- fi
162
- ctx="$arg"
163
- ;;
164
- esac
165
- done
166
- if [ -z "$ctx" ]; then
167
- if [ -z "$namespace" ]; then
168
- echo "devzone : missing context: devzone use CTX" >&2
169
- return 2
170
- fi
171
- current="$(kubectl config current-context 2>/dev/null || true)"
172
- if [ -z "$current" ]; then
173
- echo "devzone : no current context" >&2
174
- return 2
175
- fi
176
- ctx="$current"
177
- fi
178
- if ! kubectl config get-contexts -o name 2>/dev/null | grep -qxF -- "$ctx"; then
179
- echo "devzone : unknown context: $ctx (see kubectl config get-contexts)" >&2
180
- return 2
181
- fi
182
- current="$(kubectl config current-context 2>/dev/null || true)"
183
- if [ "$ctx" != "$current" ]; then
184
- if ! cluster_is_local "$ctx"; then
185
- if [ -n "$confirm_ctx" ]; then
186
- if [ "$confirm_ctx" != "$ctx" ]; then
187
- echo "devzone : remote cluster refused: $ctx (--confirm $ctx)" >&2
188
- return 2
189
- fi
190
- elif cluster_interactive; then
191
- printf 'remote cluster: %s; type its name to confirm: ' "$ctx" >&2
192
- read -r answer || answer=""
193
- if [ "$answer" != "$ctx" ]; then
194
- echo "devzone : remote cluster refused: $ctx (--confirm $ctx)" >&2
195
- return 2
196
- fi
197
- else
198
- echo "devzone : remote cluster refused: $ctx (--confirm $ctx)" >&2
199
- return 2
200
- fi
201
- fi
202
- kubectl config use-context "$ctx" >/dev/null
203
- fi
204
- if [ -n "$namespace" ]; then
205
- kubectl config set-context "$ctx" --namespace "$namespace" >/dev/null
206
- fi
207
- echo "working cluster: $ctx"
208
- [ -z "$namespace" ] || echo "namespace: $namespace"
209
- }
@@ -1,65 +0,0 @@
1
- #!/usr/bin/env bash
2
- # Network isolation and access authorization between devzone namespaces.
3
- # File <= 250 lines: functions namespace_isolate, allow, forbid.
4
- # These functions modify NetworkPolicies in the Kubernetes cluster.
5
- # Loaded by argocd.sh, catalog.sh, the mysql and postgres Go modules, gitlab.sh; shipped with the package.
6
-
7
- # Sets an isolating NetworkPolicy in a namespace.
8
- # Only the pods of the same namespace can reach the services.
9
- namespace_isolate() {
10
- local ns="${1:-}"
11
- [ -n "$ns" ] || { echo "devzone : namespace missing" >&2; return 2; }
12
-
13
- kubectl --context devzone -n "$ns" apply -f - <<EOF
14
- apiVersion: networking.k8s.io/v1
15
- kind: NetworkPolicy
16
- metadata:
17
- name: devzone-meme-namespace
18
- labels:
19
- app.kubernetes.io/managed-by: devzone
20
- spec:
21
- podSelector: {}
22
- ingress:
23
- - from:
24
- - podSelector: {}
25
- EOF
26
- }
27
-
28
- # Adds a namespaceSelector rule to the NetworkPolicy of the target namespace,
29
- # allowing access from outside this namespace.
30
- # Without this rule, an application in another namespace cannot reach the
31
- # devzone services (postgres, etc.).
32
- allow() {
33
- local target_ns="${1:-}" patch output
34
- [ -n "$target_ns" ] || { echo "devzone : target namespace missing" >&2; return 2; }
35
-
36
- kubectl --context devzone -n "$target_ns" get networkpolicy devzone-meme-namespace \
37
- -o yaml 2>/dev/null | kubectl --context devzone -n "$target_ns" apply -f - >/dev/null 2>&1 ||
38
- { echo "devzone : cannot apply the isolating NetworkPolicy in $target_ns" >&2; return 1; }
39
-
40
- patch="$(jq -nc '{"spec":{"ingress":[{"from":[{"podSelector":{},
41
- "namespaceSelector":{"matchLabels":{"app.kubernetes.io/managed-by":"devzone"}}}]}]}}')"
42
- if ! output="$(kubectl --context devzone -n "$target_ns" patch networkpolicy devzone-meme-namespace \
43
- -p "$patch" 2>&1)"; then
44
- echo "devzone : cannot allow access to $target_ns : $output" >&2
45
- return 1
46
- fi
47
-
48
- echo "devzone : rule allowed to $target_ns"
49
- }
50
-
51
- # Removes the namespaceSelector rule from the NetworkPolicy,
52
- # blocking access again from the given namespace.
53
- forbid() {
54
- local target_ns="${1:-}" patch output
55
- [ -n "$target_ns" ] || { echo "devzone : target namespace missing" >&2; return 2; }
56
-
57
- patch="$(jq -nc '{"spec":{"ingress":[{"from":[{"podSelector":{}}]}]}}')"
58
- if ! output="$(kubectl --context devzone -n "$target_ns" patch networkpolicy devzone-meme-namespace \
59
- -p "$patch" 2>&1)"; then
60
- echo "devzone : cannot forbid access to $target_ns : $output" >&2
61
- return 1
62
- fi
63
-
64
- echo "devzone : rule forbidden to $target_ns"
65
- }
@@ -1,107 +0,0 @@
1
- #!/usr/bin/env bash
2
- # Limited Kubernetes account (#430): the devzone context (projects, relays,
3
- # agents) can only act in the devzone-* namespaces. The account is the
4
- # ServiceAccount devzone-agent of the devzone-system namespace, bound to the
5
- # edit ClusterRole (no RBAC, no quotas) in each devzone namespace by a
6
- # RoleBinding. The installers alone use the admin context (host context in
7
- # ~/.kube/hote.config, kind cluster in ~/.kube/config); the shells use
8
- # ~/.kube/config and the agents the limited ~/.kube/agent.config (devzone
9
- # context only, #844).
10
- # Library sourced by cluster.sh.
11
-
12
- ACCOUNT_NS=devzone-system
13
- ACCOUNT_SA=devzone-agent
14
- ACCOUNT_CONFIG="${DEVZONE_KUBE_CONFIG:-$HOME/.kube/config}"
15
-
16
- # kubeconfig file that holds the admin context ctx: hote.config if it lists it
17
- # (host clusters), otherwise ~/.kube/config (kind clusters of the container).
18
- account_admin_config() {
19
- local ctx="$1" host="${DEVZONE_KUBE_HOST:-$HOME/.kube/hote.config}"
20
- if [ -n "$ctx" ] && [ -f "$host" ]; then
21
- if KUBECONFIG="$host" kubectl config get-contexts -o name 2>/dev/null | grep -qx -- "$ctx"; then
22
- echo "$host"
23
- return 0
24
- fi
25
- fi
26
- echo "$ACCOUNT_CONFIG"
27
- }
28
-
29
- # kubectl on the admin context: explicit kubeconfig that holds this context,
30
- # never the combined KUBECONFIG (the admin never goes through the limited
31
- # account). Without a known context: the one kubectl uses.
32
- account_admin() {
33
- local ctx="$1" conf
34
- shift
35
- if [ -z "$ctx" ]; then
36
- ctx="$(kubectl config current-context 2>/dev/null || true)"
37
- fi
38
- conf="$(account_admin_config "$ctx")"
39
- if [ -n "$ctx" ]; then
40
- kubectl --kubeconfig="$conf" --context "$ctx" "$@"
41
- else
42
- kubectl --kubeconfig="$conf" "$@"
43
- fi
44
- }
45
-
46
- # helm on the admin context ctx: the charts create CRDs, ClusterRoles or
47
- # RoleBindings, beyond the limited account's rights (edit).
48
- # Usage: account_helm <ctx> <helm args…>
49
- account_helm() {
50
- local ctx="$1" conf
51
- shift
52
- if [ -z "$ctx" ]; then
53
- ctx="$(kubectl config current-context 2>/dev/null || true)"
54
- fi
55
- conf="$(account_admin_config "$ctx")"
56
- if [ -n "$ctx" ]; then
57
- helm --kubeconfig "$conf" --kube-context "$ctx" "$@"
58
- else
59
- helm --kubeconfig "$conf" "$@"
60
- fi
61
- }
62
-
63
- # Admin context of an installation: the chosen services cluster (cluster_saved
64
- # of cluster.sh), otherwise the current kubectl context.
65
- account_context() {
66
- local ctx
67
- ctx="$(cluster_saved 2>/dev/null || true)"
68
- if [ -n "$ctx" ]; then
69
- echo "$ctx"
70
- return 0
71
- fi
72
- kubectl config current-context 2>/dev/null || true
73
- }
74
-
75
- # Allows the account in namespace ns: devzone-agent RoleBinding to the edit
76
- # ClusterRole (read, write, secrets, NetworkPolicies — no RBAC, no quotas), set
77
- # with the admin context after the namespace is created.
78
- # The account is set up first if missing: devzone-system namespace and
79
- # devzone-agent ServiceAccount, so an installation on a still blank cluster
80
- # makes the account usable at the next token renewal.
81
- account_allow() {
82
- local ctx="$1" ns="$2"
83
- account_admin "$ctx" create namespace "$ACCOUNT_NS" --dry-run=client -o yaml |
84
- account_admin "$ctx" apply -f - >/dev/null || return 1
85
- account_admin "$ctx" -n "$ACCOUNT_NS" create serviceaccount "$ACCOUNT_SA" \
86
- --dry-run=client -o yaml | account_admin "$ctx" apply -f - >/dev/null || return 1
87
- account_admin "$ctx" -n "$ns" create rolebinding "$ACCOUNT_SA" \
88
- --clusterrole=edit --serviceaccount="$ACCOUNT_NS:$ACCOUNT_SA" \
89
- --dry-run=client -o yaml | account_admin "$ctx" apply -f - >/dev/null || return 1
90
- }
91
-
92
- # Removes the account's permission in namespace ns (uninstall): RoleBinding
93
- # deleted with the admin context.
94
- account_remove() {
95
- local ctx="$1" ns="$2"
96
- account_admin "$ctx" -n "$ns" delete rolebinding "$ACCOUNT_SA" \
97
- --ignore-not-found >/dev/null || return 1
98
- }
99
-
100
- # Creates and labels namespace ns as administrator, then allows the account.
101
- account_namespace() {
102
- local ctx="$1" ns="$2"
103
- account_admin "$ctx" create namespace "$ns" --dry-run=client -o yaml |
104
- account_admin "$ctx" apply -f - >/dev/null || return 1
105
- account_admin "$ctx" label namespace "$ns" "$CLUSTER_LABEL" --overwrite >/dev/null || return 1
106
- account_allow "$ctx" "$ns" || return 1
107
- }
@@ -1,42 +0,0 @@
1
- #!/usr/bin/env bash
2
- # Kubernetes prompt of the shell (#337): ⎈ ctx/ns.
3
-
4
- # Renders the Kubernetes prompt (⎈ ctx/ns), with a cache keyed on the mtime.
5
- devzone_kube_prompt() {
6
- local kubeconfig="${KUBECONFIG:-$HOME/.kube/config:$HOME/.kube/hote.config}"
7
- local files=() f sig="" cache mtime ctx ns result ici
8
- ici="$(cd -P "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
9
- IFS=':' read -ra files <<<"$kubeconfig"
10
- for f in "${files[@]}"; do
11
- [ -n "$f" ] || continue
12
- if [ -f "$f" ]; then
13
- mtime="$(stat -c '%Y' "$f" 2>/dev/null || echo 0)"
14
- else
15
- mtime="missing"
16
- fi
17
- sig+="${f}:${mtime};"
18
- done
19
- cache="${XDG_CACHE_HOME:-$HOME/.cache}/devzone-kube-prompt"
20
- mkdir -p "$(dirname "$cache")"
21
- if [ -f "$cache" ]; then
22
- if [ "$(sed -n '1p' "$cache" 2>/dev/null)" = "$sig" ]; then
23
- sed -n '2p' "$cache" 2>/dev/null
24
- return 0
25
- fi
26
- fi
27
- ctx="$(kubectl config current-context 2>/dev/null || true)"
28
- if [ -z "$ctx" ]; then
29
- result=""
30
- else
31
- ns="$(kubectl config view -o jsonpath="{.contexts[?(@.name==\"$ctx\")].context.namespace}" 2>/dev/null || true)"
32
- [ -n "$ns" ] || ns=default
33
- # shellcheck disable=SC1090,SC1091
34
- if ( . "$ici/cluster.sh"; cluster_is_local "$ctx" ) >/dev/null 2>&1; then
35
- result="$(printf '\001\033[36m\002⎈ %s/%s\001\033[0m\002' "$ctx" "$ns")"
36
- else
37
- result="$(printf '\001\033[1;31m\002⎈ %s/%s remote\001\033[0m\002' "$ctx" "$ns")"
38
- fi
39
- fi
40
- printf '%s\n%s\n' "$sig" "$result" >"$cache"
41
- printf '%s\n' "$result"
42
- }
@@ -1,113 +0,0 @@
1
- #!/usr/bin/env bash
2
- # Memory check of the services cluster (#608, #612): a module refuses its
3
- # installation when the allocatable memory of the nodes is below its minimum.
4
- # Sourced by the modules (gitlab, llm) and by the tests; bash 3.2 (macOS).
5
- # quantity_ki <quantity> Kubernetes quantity in Ki
6
- # memory_cluster_ki allocatable memory of the cluster, in Ki
7
- # check_module_memory <module> <minimum_gi> [hint]
8
- # Messages in English. Return 0 when the memory is enough, 2 when it is not or
9
- # when the cluster is unreachable.
10
-
11
- # Globals written by memory_cluster_ki (#612) and read by
12
- # check_module_memory, which calls the function directly: a call written
13
- # memory="$(memory_cluster_ki)" would run it in a subshell and lose them.
14
- # Callers that only need the number keep using $(memory_cluster_ki): the
15
- # value is still printed on stdout (argocd, gitlab, llm are unaffected).
16
- # MEMORY_KI same value as on stdout, in Ki
17
- # MEMORY_RULE "maximum" when every node is a kind node (the nodes share
18
- # one VM), "sum" otherwise
19
- MEMORY_KI=""
20
- MEMORY_RULE=""
21
-
22
- # Converts a Kubernetes memory quantity (Ki, Mi, Gi, Ti, K, M, G, bytes)
23
- # into Ki, to total the allocatable memory of the nodes.
24
- quantity_ki() {
25
- local q="${1:-}" number
26
- case "$q" in
27
- *Ki) number="${q%Ki}"; echo $((number)) ;;
28
- *Mi) number="${q%Mi}"; echo $((number * 1024)) ;;
29
- *Gi) number="${q%Gi}"; echo $((number * 1024 * 1024)) ;;
30
- *Ti) number="${q%Ti}"; echo $((number * 1024 * 1024 * 1024)) ;;
31
- *K | *k) number="${q%[Kk]}"; echo $((number * 1000 / 1024)) ;;
32
- *M) number="${q%M}"; echo $((number * 1000 * 1000 / 1024)) ;;
33
- *G) number="${q%G}"; echo $((number * 1000 * 1000 * 1000 / 1024)) ;;
34
- *)
35
- case "$q" in
36
- '' | *[!0-9]*) echo 0 ;;
37
- *) echo $((q / 1024)) ;;
38
- esac
39
- ;;
40
- esac
41
- }
42
-
43
- # Allocatable memory of the services cluster nodes, in Ki. Reading the nodes
44
- # is reserved to the administrator (#430). One kubectl call gives, per node,
45
- # its providerID and its allocatable memory on one "<providerID>|<memory>"
46
- # line (#612). A kind cluster runs on a single Docker daemon: its nodes share
47
- # the memory of one VM and each of them declares the whole VM, so adding them
48
- # up lies. When every providerID starts with "kind://" the greatest node
49
- # memory is returned (MEMORY_RULE=maximum); as soon as one node has no such
50
- # prefix or an empty providerID the sum is returned (MEMORY_RULE=sum), as
51
- # before. Known limit, documented: k3d and minikube in Docker mode share a VM
52
- # too but are not kind, they stay on the sum. A line without the separator
53
- # carries the memory alone, so it is a node without providerID (sum).
54
- memory_cluster_ki() {
55
- local output line providerID memory node total=0 max=0 n=0 all_kind=1
56
- MEMORY_KI=""
57
- MEMORY_RULE=""
58
- output="$(account_admin "$(account_context)" get nodes \
59
- -o jsonpath='{range .items[*]}{.spec.providerID}{"|"}{.status.allocatable.memory}{"\n"}{end}' 2>/dev/null)" || return 1
60
- [ -n "$output" ] || return 1
61
- while IFS= read -r line; do
62
- [ -n "$line" ] || continue
63
- case "$line" in
64
- *'|'*)
65
- providerID="${line%%|*}"
66
- memory="${line#*|}"
67
- ;;
68
- *)
69
- providerID=""
70
- memory="$line"
71
- ;;
72
- esac
73
- node="$(quantity_ki "$memory")"
74
- total=$((total + node))
75
- if [ "$node" -gt "$max" ]; then max="$node"; fi
76
- case "$providerID" in
77
- kind://*) ;;
78
- *) all_kind=0 ;;
79
- esac
80
- n=$((n + 1))
81
- done <<<"$output"
82
- if [ "$n" -gt 0 ] && [ "$all_kind" -eq 1 ]; then
83
- MEMORY_RULE="maximum"
84
- MEMORY_KI="$max"
85
- else
86
- MEMORY_RULE="sum"
87
- MEMORY_KI="$total"
88
- fi
89
- echo "$MEMORY_KI"
90
- }
91
-
92
- # Refuses the installation of <module> under <minimum_gi> GiB of allocatable
93
- # memory. The message says the minimum, the available memory and how to enlarge
94
- # the cluster; [hint] adds an optional hint (for example --preset light).
95
- # On a kind cluster (#612) the available memory is the one of a single node
96
- # and the message says so. Return 0 when the memory is enough, 2 when it is
97
- # not or the cluster is unreachable.
98
- check_module_memory() {
99
- local module_name="$1" minimum_gi="$2" hint="${3:-}" memory precision=""
100
- if ! memory_cluster_ki >/dev/null; then
101
- echo "devzone : ${module_name} : services cluster unreachable: devzone cluster" >&2
102
- return 2
103
- fi
104
- memory="$MEMORY_KI"
105
- if [ "$MEMORY_RULE" = "maximum" ]; then
106
- precision=" (memory of a single node: kind cluster, shared VM)"
107
- fi
108
- if [ "$memory" -lt "$((minimum_gi * 1048576))" ]; then
109
- echo "devzone : ${module_name} : at least ${minimum_gi} GiB of allocatable memory is needed in the cluster (available: $((memory / 1048576)) GiB)${precision} ; enlarge the cluster (Docker Desktop → Settings → Resources) then retry: devzone enable ${module_name}${hint:+ ; hint: ${hint}}" >&2
110
- return 2
111
- fi
112
- return 0
113
- }