devzone 0.36.6 → 0.37.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.devcontainer/argocd/application.sh +69 -0
- package/.devcontainer/argocd/apps.sh +262 -0
- package/.devcontainer/argocd/argocd.sh +46 -1
- package/.devcontainer/argocd/conf.sh +141 -0
- package/.devcontainer/argocd/gitops.sh +214 -0
- package/.devcontainer/argocd/values.yaml +4 -0
- package/.devcontainer/devzone +75 -4
- package/.devcontainer/etat-json.sh +13 -1
- package/.devcontainer/services-admin.sh +105 -0
- package/README.md +30 -30
- package/charts/devzone-postgres/Chart.yaml +6 -0
- package/charts/devzone-postgres/templates/service.yaml +15 -0
- package/charts/devzone-postgres/templates/statefulset.yaml +56 -0
- package/charts/devzone-postgres/values.yaml +11 -0
- package/manage/devzone +11 -6
- package/manage/scripts/argocd-services.sh +243 -0
- package/manage/scripts/argocd-workspace.sh +219 -0
- package/manage/scripts/ports-workspace.sh +17 -10
- package/manage/scripts/services-workspace.sh +162 -0
- package/manage/scripts/workspace-wait.sh +2 -2
- package/manage/workspace.sh +28 -7
- package/package.json +1 -1
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
apiVersion: apps/v1
|
|
2
|
+
kind: StatefulSet
|
|
3
|
+
metadata:
|
|
4
|
+
name: postgres
|
|
5
|
+
namespace: {{ .Release.Namespace }}
|
|
6
|
+
labels:
|
|
7
|
+
app: postgres
|
|
8
|
+
app.kubernetes.io/managed-by: devzone
|
|
9
|
+
spec:
|
|
10
|
+
serviceName: postgres
|
|
11
|
+
replicas: 1
|
|
12
|
+
selector:
|
|
13
|
+
matchLabels:
|
|
14
|
+
app: postgres
|
|
15
|
+
template:
|
|
16
|
+
metadata:
|
|
17
|
+
labels:
|
|
18
|
+
app: postgres
|
|
19
|
+
app.kubernetes.io/managed-by: devzone
|
|
20
|
+
spec:
|
|
21
|
+
containers:
|
|
22
|
+
- name: postgres
|
|
23
|
+
image: {{ .Values.image }}
|
|
24
|
+
env:
|
|
25
|
+
- name: POSTGRES_PASSWORD
|
|
26
|
+
valueFrom:
|
|
27
|
+
secretKeyRef:
|
|
28
|
+
name: postgres-admin
|
|
29
|
+
key: password
|
|
30
|
+
- name: PGDATA
|
|
31
|
+
value: /var/lib/postgresql/data/pgdata
|
|
32
|
+
ports:
|
|
33
|
+
- containerPort: 5432
|
|
34
|
+
name: postgres
|
|
35
|
+
readinessProbe:
|
|
36
|
+
exec:
|
|
37
|
+
command: ["pg_isready", "-U", "postgres"]
|
|
38
|
+
initialDelaySeconds: 5
|
|
39
|
+
periodSeconds: 5
|
|
40
|
+
resources:
|
|
41
|
+
requests:
|
|
42
|
+
cpu: {{ .Values.resources.requests.cpu }}
|
|
43
|
+
memory: {{ .Values.resources.requests.memory }}
|
|
44
|
+
volumeMounts:
|
|
45
|
+
- name: donnees
|
|
46
|
+
mountPath: /var/lib/postgresql/data
|
|
47
|
+
volumeClaimTemplates:
|
|
48
|
+
- metadata:
|
|
49
|
+
name: donnees
|
|
50
|
+
labels:
|
|
51
|
+
app.kubernetes.io/managed-by: devzone
|
|
52
|
+
spec:
|
|
53
|
+
accessModes: ["ReadWriteOnce"]
|
|
54
|
+
resources:
|
|
55
|
+
requests:
|
|
56
|
+
storage: {{ .Values.size }}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
# Same objects as .devcontainer/postgres/postgres.yaml, the helm-direct path:
|
|
2
|
+
# manage/test/chart-postgres.bats checks that both renderings agree. The
|
|
3
|
+
# secret postgres-admin (superuser password) is created apart by devzone,
|
|
4
|
+
# never by the chart (#516: secrets out of Git).
|
|
5
|
+
image: postgres:16.15-alpine
|
|
6
|
+
# Size of the data volume (POSTGRES_TAILLE of the helm-direct path)
|
|
7
|
+
size: 5Gi
|
|
8
|
+
resources:
|
|
9
|
+
requests:
|
|
10
|
+
cpu: 100m
|
|
11
|
+
memory: 256Mi
|
package/manage/devzone
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
#!/usr/bin/env bash
|
|
2
2
|
# Commande devzone sur ta machine (paquet npm) :
|
|
3
3
|
# devzone <dossier> crée un devzone dans <dossier> puis le lance
|
|
4
|
-
# devzone
|
|
5
|
-
# devzone
|
|
4
|
+
# devzone update dans un dossier devzone : passe à la version du paquet
|
|
5
|
+
# devzone uninstall dans un dossier devzone : retire tout ce qu'il a créé
|
|
6
6
|
# devzone --version | --help
|
|
7
7
|
# Dans le conteneur, « devzone » est une autre commande : les modules
|
|
8
8
|
# (.devcontainer/devzone).
|
|
@@ -421,14 +421,19 @@ aide() {
|
|
|
421
421
|
devzone $(version) : environnement de développement conteneurisé
|
|
422
422
|
|
|
423
423
|
devzone <dossier> crée un devzone dans <dossier> puis le lance (make up)
|
|
424
|
-
devzone
|
|
424
|
+
devzone update [--oui] [--sans-reconstruire]
|
|
425
425
|
dans un dossier devzone : passe à la version du paquet
|
|
426
426
|
(sauvegarde les fichiers remplacés, propose make rebuild)
|
|
427
|
-
devzone
|
|
427
|
+
devzone uninstall dans un dossier devzone : retire conteneur, image, volumes
|
|
428
428
|
(à lancer avant npm uninstall -g devzone)
|
|
429
|
-
devzone workspace
|
|
430
|
-
devzone workspace vscode|
|
|
429
|
+
devzone workspace start|stop|status|shell
|
|
430
|
+
devzone workspace vscode|copy-to|copy-from|migrate|revert|clean-docker
|
|
431
431
|
poste Kubernetes : pilote le chart devzone-workspace
|
|
432
|
+
devzone workspace services enable|disable <service>|status
|
|
433
|
+
services (gitlab, postgres, argocd) du workspace Kubernetes
|
|
434
|
+
devzone workspace argocd status|init|apply|app add|list|remove
|
|
435
|
+
Argo CD du workspace : dépôt GitOps, .argocd.conf, projets
|
|
436
|
+
(anciens noms français acceptés : mettre-a-jour, desinstaller, demarrer…)
|
|
432
437
|
devzone --version
|
|
433
438
|
EOF
|
|
434
439
|
}
|
|
@@ -0,0 +1,243 @@
|
|
|
1
|
+
#!/usr/bin/env bash
|
|
2
|
+
# Deployments held by Argo CD in the Kubernetes workspace (#516), sourced by
|
|
3
|
+
# manage/workspace.sh after argocd-workspace.sh: the workspace itself, the
|
|
4
|
+
# postgres service, the argocd services switch and devzone workspace argocd.
|
|
5
|
+
# workspace_deploy <repository> <tag> <with-image> start: Application, else helm direct
|
|
6
|
+
# workspace_undeploy stop: Application, else helm uninstall
|
|
7
|
+
# argocd_toggle enable|disable devzone workspace services … argocd
|
|
8
|
+
# postgres_argocd enable|disable [--yes] postgres as an Application
|
|
9
|
+
# argocd_cmd status | init | apply | app add|list|remove devzone workspace argocd …
|
|
10
|
+
# Secrets stay out of Git: created here, only referenced by the charts.
|
|
11
|
+
# bash 3.2 (macOS).
|
|
12
|
+
|
|
13
|
+
WORKSPACE_APP="devzone-workspace"
|
|
14
|
+
POSTGRES_APP="devzone-postgres"
|
|
15
|
+
POSTGRES_NS="devzone-postgres"
|
|
16
|
+
|
|
17
|
+
# The only option of a removal: --yes (--oui still accepted); prints 1 or 0
|
|
18
|
+
yes_flag() {
|
|
19
|
+
local usage="$1" arg found=0
|
|
20
|
+
shift
|
|
21
|
+
for arg in "$@"; do
|
|
22
|
+
case "$arg" in
|
|
23
|
+
--yes | --oui) found=1 ;;
|
|
24
|
+
*) echo "✖ unknown option: $arg (devzone workspace $usage)" >&2; return 1 ;;
|
|
25
|
+
esac
|
|
26
|
+
done
|
|
27
|
+
echo "$found"
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
# [y/N] in a terminal; without one, --yes is required
|
|
31
|
+
confirm_removal() {
|
|
32
|
+
local answer=""
|
|
33
|
+
[ "${2:-0}" = 1 ] && return 0
|
|
34
|
+
if [ ! -t 0 ]; then
|
|
35
|
+
echo "✖ no terminal: confirmation impossible, run again with --yes" >&2
|
|
36
|
+
return 1
|
|
37
|
+
fi
|
|
38
|
+
read -r -p "$1 [y/N] " answer || true
|
|
39
|
+
case "$answer" in y | Y | yes | YES | o | O | oui) return 0 ;; esac
|
|
40
|
+
echo "✖ cancelled, nothing changed" >&2
|
|
41
|
+
return 1
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
# shellcheck disable=SC2034 # read by apps.sh
|
|
45
|
+
APPS_CMD="devzone workspace argocd app"
|
|
46
|
+
# shellcheck disable=SC2034 # read by apps.sh
|
|
47
|
+
APPS_GENERATOR="$RACINE/.devcontainer/argocd/application.sh"
|
|
48
|
+
# shellcheck disable=SC2034 # read by gitops.sh
|
|
49
|
+
GITOPS_CMD="devzone workspace argocd init"
|
|
50
|
+
# .argocd.conf of the devzone folder of the workstation (conf.sh)
|
|
51
|
+
# shellcheck disable=SC2034 # read by conf.sh and apps.sh
|
|
52
|
+
ARGOCD_CONF_DIR="$PWD"
|
|
53
|
+
# shellcheck disable=SC2034
|
|
54
|
+
ARGOCD_CONF="$PWD/.argocd.conf"
|
|
55
|
+
# shellcheck source=../../.devcontainer/argocd/conf.sh
|
|
56
|
+
# shellcheck disable=SC1091
|
|
57
|
+
. "$RACINE/.devcontainer/argocd/conf.sh"
|
|
58
|
+
# shellcheck source=../../.devcontainer/argocd/gitops.sh
|
|
59
|
+
# shellcheck disable=SC1091
|
|
60
|
+
. "$RACINE/.devcontainer/argocd/gitops.sh"
|
|
61
|
+
# shellcheck source=../../.devcontainer/argocd/apps.sh
|
|
62
|
+
# shellcheck disable=SC1091
|
|
63
|
+
. "$RACINE/.devcontainer/argocd/apps.sh"
|
|
64
|
+
argocd_kubectl() { ak "$@"; }
|
|
65
|
+
|
|
66
|
+
# workspace start and argocd apply: the declarations of .argocd.conf held
|
|
67
|
+
argocd_reconcile() {
|
|
68
|
+
argocd_installed || return 0
|
|
69
|
+
gitops_init || return 1
|
|
70
|
+
gitops_root || return 1
|
|
71
|
+
apps_reconcile
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
# Root token of the devzone GitLab for app add: the file of the workstation,
|
|
75
|
+
# else the one of the pod (the module was installed there, #528); never printed
|
|
76
|
+
apps_gitlab_token() {
|
|
77
|
+
if [ -s "$PWD/workspace/.gitlab/root-token" ]; then
|
|
78
|
+
cat "$PWD/workspace/.gitlab/root-token"
|
|
79
|
+
else
|
|
80
|
+
ak -n "$NAMESPACE" exec "$POD" -c workspace -- cat "$DOSSIER_PROJETS/workspace/.gitlab/root-token" 2>/dev/null || true
|
|
81
|
+
fi
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
# Argo CD holds the devzone charts only with a Git revision (release tag or
|
|
85
|
+
# DEVZONE_ARGOCD_REVISION): a development clone stays on helm direct
|
|
86
|
+
argocd_holds_charts() {
|
|
87
|
+
argocd_active && [ -n "$(argocd_revision)" ]
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
argocd_clone_notice() {
|
|
91
|
+
if argocd_active && [ -z "$(argocd_revision)" ]; then
|
|
92
|
+
echo "ℹ development clone (version 0.0.0): helm direct; DEVZONE_ARGOCD_REVISION=<branch> to go through Argo CD"
|
|
93
|
+
fi
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
# Release secrets of a release deployed with helm before: deleted, so that
|
|
97
|
+
# Argo CD adopts the live resources without any helm uninstall (no downtime)
|
|
98
|
+
helm_release_forget() {
|
|
99
|
+
ak -n "$2" delete secret -l "owner=helm,name=$1" --ignore-not-found >/dev/null 2>&1 || true
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
workspace_deploy() {
|
|
103
|
+
local repository="$1" tag="$2" with_image="$3" params
|
|
104
|
+
if ! argocd_holds_charts; then
|
|
105
|
+
argocd_clone_notice
|
|
106
|
+
workspace_helm_deploy "$repository" "$tag" "$with_image"
|
|
107
|
+
return
|
|
108
|
+
fi
|
|
109
|
+
params="image.tag=$tag"
|
|
110
|
+
[ -z "$with_image" ] || params="$params image.repository=$repository"
|
|
111
|
+
[ "$tag" != latest ] || params="$params image.pullPolicy=Always"
|
|
112
|
+
# GitOps repository created or designated first, with its root Application
|
|
113
|
+
gitops_init || return 1
|
|
114
|
+
gitops_root || return 1
|
|
115
|
+
echo "▶ Application $WORKSPACE_APP (Argo CD, charts/devzone-workspace at $(argocd_revision))…"
|
|
116
|
+
helm_release_forget devzone-workspace devzone-workspace
|
|
117
|
+
# shellcheck disable=SC2086
|
|
118
|
+
argocd_apply_application "$WORKSPACE_APP" workspace devzone-workspace \
|
|
119
|
+
"$DEVZONE_REPO_URL" "$(argocd_revision)" charts/devzone-workspace $params
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
workspace_undeploy() {
|
|
123
|
+
if argocd_installed && argocd_application_exists "$WORKSPACE_APP"; then
|
|
124
|
+
echo "▶ Application $WORKSPACE_APP deleted (Argo CD removes the pod, the volumes stay)…"
|
|
125
|
+
argocd_delete_application "$WORKSPACE_APP"
|
|
126
|
+
else
|
|
127
|
+
# shellcheck disable=SC2046
|
|
128
|
+
helm $(drapeau_helm) uninstall devzone-workspace --namespace devzone-workspace
|
|
129
|
+
fi
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
# devzone workspace services enable|disable argocd: the workstation installs
|
|
133
|
+
# or removes it itself; the state line follows what succeeded
|
|
134
|
+
argocd_toggle() {
|
|
135
|
+
local action="$1"
|
|
136
|
+
shift
|
|
137
|
+
if [ "$#" -ne 0 ]; then
|
|
138
|
+
echo "✖ services $action argocd takes no option (got: $*)" >&2
|
|
139
|
+
return 1
|
|
140
|
+
fi
|
|
141
|
+
case "$action" in
|
|
142
|
+
enable) argocd_install && state_note argocd on && gitops_init && gitops_root ;;
|
|
143
|
+
disable) argocd_uninstall && state_note argocd off ;;
|
|
144
|
+
esac
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
# Namespace of the service: labelled, isolated like the other devzone-*
|
|
148
|
+
postgres_namespace_prepare() {
|
|
149
|
+
ak create namespace "$POSTGRES_NS" --dry-run=client -o yaml | ak apply -f - >/dev/null
|
|
150
|
+
ak label namespace "$POSTGRES_NS" app.kubernetes.io/managed-by=devzone --overwrite >/dev/null
|
|
151
|
+
ak -n "$POSTGRES_NS" apply -f - >/dev/null <<EOF
|
|
152
|
+
apiVersion: networking.k8s.io/v1
|
|
153
|
+
kind: NetworkPolicy
|
|
154
|
+
metadata:
|
|
155
|
+
name: devzone-meme-namespace
|
|
156
|
+
labels:
|
|
157
|
+
app.kubernetes.io/managed-by: devzone
|
|
158
|
+
spec:
|
|
159
|
+
podSelector: {}
|
|
160
|
+
ingress:
|
|
161
|
+
- from:
|
|
162
|
+
- podSelector: {}
|
|
163
|
+
EOF
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
# Superuser secret postgres-admin, created apart: an existing secret is kept
|
|
167
|
+
# and mirrored; otherwise a password generated on the workstation. Mirror
|
|
168
|
+
# workspace/.postgres/admin-password (600) and .password; never printed
|
|
169
|
+
postgres_secret_ensure() {
|
|
170
|
+
local dir="$PWD/workspace/.postgres" file password
|
|
171
|
+
file="$dir/admin-password"
|
|
172
|
+
mkdir -p "$dir"
|
|
173
|
+
chmod 700 "$dir"
|
|
174
|
+
password="$(ak -n "$POSTGRES_NS" get secret postgres-admin \
|
|
175
|
+
-o go-template='{{.data.password | base64decode}}' 2>/dev/null)" || password=""
|
|
176
|
+
if [ -n "$password" ]; then
|
|
177
|
+
(umask 077 && printf '%s' "$password" >"$file")
|
|
178
|
+
else
|
|
179
|
+
if [ ! -s "$file" ]; then
|
|
180
|
+
(umask 077 && openssl rand -hex 24 | tr -d '\n' >"$file")
|
|
181
|
+
fi
|
|
182
|
+
ak -n "$POSTGRES_NS" create secret generic postgres-admin --from-file=password="$file" >/dev/null
|
|
183
|
+
fi
|
|
184
|
+
chmod 600 "$file"
|
|
185
|
+
argocd_passwords_refresh
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
postgres_argocd() {
|
|
189
|
+
local action="$1" yes
|
|
190
|
+
shift
|
|
191
|
+
case "$action" in
|
|
192
|
+
enable)
|
|
193
|
+
if [ "$#" -ne 0 ]; then
|
|
194
|
+
echo "✖ postgres through Argo CD takes no option (got: $*)" >&2
|
|
195
|
+
return 1
|
|
196
|
+
fi
|
|
197
|
+
echo "▶ postgres as an Argo CD Application (charts/devzone-postgres at $(argocd_revision))…"
|
|
198
|
+
postgres_namespace_prepare
|
|
199
|
+
postgres_secret_ensure
|
|
200
|
+
argocd_apply_application "$POSTGRES_APP" service "$POSTGRES_NS" \
|
|
201
|
+
"$DEVZONE_REPO_URL" "$(argocd_revision)" charts/devzone-postgres
|
|
202
|
+
echo "✔ Application $POSTGRES_APP declared; status: devzone workspace argocd status; local access: devzone workspace ports"
|
|
203
|
+
;;
|
|
204
|
+
disable)
|
|
205
|
+
yes="$(yes_flag "services disable postgres [--yes]" "$@")" || return 1
|
|
206
|
+
confirm_removal "Remove PostgreSQL and ALL its databases (Application and namespace $POSTGRES_NS)?" "$yes" || return 1
|
|
207
|
+
argocd_delete_application "$POSTGRES_APP"
|
|
208
|
+
ak delete namespace "$POSTGRES_NS" --wait=true --ignore-not-found >/dev/null
|
|
209
|
+
rm -rf "$PWD/workspace/.postgres"
|
|
210
|
+
argocd_passwords_refresh
|
|
211
|
+
echo "✔ postgres removed: Application, namespace $POSTGRES_NS and databases"
|
|
212
|
+
;;
|
|
213
|
+
esac
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
# devzone workspace argocd status | app …
|
|
217
|
+
argocd_cmd() {
|
|
218
|
+
case "${1:-status}" in
|
|
219
|
+
status | etat) argocd_status ;;
|
|
220
|
+
init)
|
|
221
|
+
gitops_init "${@:2}" || return $?
|
|
222
|
+
if argocd_installed; then gitops_root; fi
|
|
223
|
+
;;
|
|
224
|
+
apply)
|
|
225
|
+
if ! argocd_installed; then
|
|
226
|
+
echo "✖ Argo CD not installed: devzone workspace services enable argocd" >&2
|
|
227
|
+
return 1
|
|
228
|
+
fi
|
|
229
|
+
argocd_reconcile
|
|
230
|
+
;;
|
|
231
|
+
app)
|
|
232
|
+
if ! argocd_installed; then
|
|
233
|
+
echo "✖ Argo CD not installed: devzone workspace services enable argocd" >&2
|
|
234
|
+
return 1
|
|
235
|
+
fi
|
|
236
|
+
argocd_app "${@:2}"
|
|
237
|
+
;;
|
|
238
|
+
*)
|
|
239
|
+
echo "✖ devzone workspace argocd status | init [--repo <url>|--none] | apply | app add <repo url> [path] [--name N] [--revision R] | app list | app remove <N>" >&2
|
|
240
|
+
return 1
|
|
241
|
+
;;
|
|
242
|
+
esac
|
|
243
|
+
}
|
|
@@ -0,0 +1,219 @@
|
|
|
1
|
+
#!/usr/bin/env bash
|
|
2
|
+
# Argo CD of the Kubernetes workspace, driven from the workstation (#516).
|
|
3
|
+
# Sourced by manage/workspace.sh (drapeau_kubectl, drapeau_helm, RACINE: the
|
|
4
|
+
# package; $PWD: the devzone folder of the workstation, its .devzone.modules,
|
|
5
|
+
# workspace/.argocd and .password).
|
|
6
|
+
# argocd_wanted 0 unless .devzone.modules says argocd=off (on by default)
|
|
7
|
+
# argocd_installed namespace devzone-argocd present
|
|
8
|
+
# argocd_active wanted and installed: Applications instead of helm direct
|
|
9
|
+
# argocd_ensure installs it when wanted and missing (workspace start)
|
|
10
|
+
# argocd_install | argocd_uninstall | argocd_status
|
|
11
|
+
# argocd_revision Git revision of the devzone charts; empty on a dev clone
|
|
12
|
+
# argocd_apply_application / argocd_delete_application
|
|
13
|
+
# Why: the pod has no administrator access (#430); the workstation has helm
|
|
14
|
+
# and kubectl. The admin password goes to workspace/.argocd/admin.env and
|
|
15
|
+
# .password of the workstation, never on screen. bash 3.2 (macOS).
|
|
16
|
+
|
|
17
|
+
ARGOCD_NS="devzone-argocd"
|
|
18
|
+
ARGOCD_CHART_VERSION="${ARGOCD_VERSION:-10.14.0}"
|
|
19
|
+
ARGOCD_LOCAL_PORT="${ARGOCD_PORT:-8443}"
|
|
20
|
+
ARGOCD_WAIT="${ARGOCD_ATTENTE:-600}"
|
|
21
|
+
ARGOCD_MIN_MEMORY_KI=1048576
|
|
22
|
+
DEVZONE_REPO_URL="${DEVZONE_REPO_URL:-https://github.com/SimBienvenueHoulBoumi/devzone.git}"
|
|
23
|
+
|
|
24
|
+
argocd_values() { printf '%s/.devcontainer/argocd/values.yaml' "$RACINE"; }
|
|
25
|
+
argocd_generator() { printf '%s/.devcontainer/argocd/application.sh' "$RACINE"; }
|
|
26
|
+
argocd_secrets_dir() { printf '%s/workspace/.argocd' "$PWD"; }
|
|
27
|
+
|
|
28
|
+
# kubectl of the workstation, context devzone when it exists
|
|
29
|
+
ak() {
|
|
30
|
+
# shellcheck disable=SC2046
|
|
31
|
+
kubectl $(drapeau_kubectl) "$@"
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
# Last value of a key of .devzone.modules of the workstation (empty if none)
|
|
35
|
+
state_read() {
|
|
36
|
+
grep "^$1=" .devzone.modules 2>/dev/null | tail -1 | cut -d= -f2- || true
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
# key=value written in .devzone.modules of the workstation, other lines kept
|
|
40
|
+
state_note() {
|
|
41
|
+
local f=".devzone.modules" tmp
|
|
42
|
+
tmp="$f.tmp.$$"
|
|
43
|
+
{
|
|
44
|
+
if [ -f "$f" ]; then grep -v "^$1=" "$f" || true; fi
|
|
45
|
+
echo "$1=$2"
|
|
46
|
+
} >"$tmp" && mv "$tmp" "$f"
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
argocd_wanted() { [ "$(state_read argocd)" != off ]; }
|
|
50
|
+
|
|
51
|
+
argocd_installed() { ak get namespace "$ARGOCD_NS" >/dev/null 2>&1; }
|
|
52
|
+
|
|
53
|
+
argocd_active() { argocd_wanted && argocd_installed; }
|
|
54
|
+
|
|
55
|
+
# Git revision of the devzone charts: DEVZONE_ARGOCD_REVISION, else the tag of
|
|
56
|
+
# the package version; empty on a development clone (0.0.0: the local chart
|
|
57
|
+
# is not in Git)
|
|
58
|
+
argocd_revision() {
|
|
59
|
+
local version
|
|
60
|
+
if [ -n "${DEVZONE_ARGOCD_REVISION:-}" ]; then
|
|
61
|
+
printf '%s' "$DEVZONE_ARGOCD_REVISION"
|
|
62
|
+
return 0
|
|
63
|
+
fi
|
|
64
|
+
version="$(sed -n 's/.*"version": *"\([^"]*\)".*/\1/p' "$RACINE/package.json" | head -1)"
|
|
65
|
+
case "$version" in
|
|
66
|
+
'' | 0.0.0) ;;
|
|
67
|
+
*) printf 'v%s' "$version" ;;
|
|
68
|
+
esac
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
# Kubernetes memory quantity in Ki (Ki, Mi, Gi, Ti, K, M, G, bytes)
|
|
72
|
+
argocd_quantity_ki() {
|
|
73
|
+
local q="${1:-}" n
|
|
74
|
+
case "$q" in
|
|
75
|
+
*Ki) n="${q%Ki}"; echo $((n)) ;;
|
|
76
|
+
*Mi) n="${q%Mi}"; echo $((n * 1024)) ;;
|
|
77
|
+
*Gi) n="${q%Gi}"; echo $((n * 1024 * 1024)) ;;
|
|
78
|
+
*Ti) n="${q%Ti}"; echo $((n * 1024 * 1024 * 1024)) ;;
|
|
79
|
+
*K | *k) n="${q%[Kk]}"; echo $((n * 1000 / 1024)) ;;
|
|
80
|
+
*M) n="${q%M}"; echo $((n * 1000 * 1000 / 1024)) ;;
|
|
81
|
+
*G) n="${q%G}"; echo $((n * 1000 * 1000 * 1000 / 1024)) ;;
|
|
82
|
+
*)
|
|
83
|
+
case "$q" in
|
|
84
|
+
'' | *[!0-9]*) echo 0 ;;
|
|
85
|
+
*) echo $((q / 1024)) ;;
|
|
86
|
+
esac
|
|
87
|
+
;;
|
|
88
|
+
esac
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
# Refuses under 1 Gi of allocatable memory in the cluster (sum of the nodes)
|
|
92
|
+
argocd_memory_ok() {
|
|
93
|
+
local lines value total=0
|
|
94
|
+
lines="$(ak get nodes -o jsonpath='{range .items[*]}{.status.allocatable.memory}{"\n"}{end}' 2>/dev/null)" || lines=""
|
|
95
|
+
if [ -z "$lines" ]; then
|
|
96
|
+
echo "✖ argocd: cluster unreachable or nodes unreadable (kubectl config get-contexts)" >&2
|
|
97
|
+
return 2
|
|
98
|
+
fi
|
|
99
|
+
while IFS= read -r value; do
|
|
100
|
+
[ -n "$value" ] || continue
|
|
101
|
+
total=$((total + $(argocd_quantity_ki "$value")))
|
|
102
|
+
done <<<"$lines"
|
|
103
|
+
if [ "$total" -lt "$ARGOCD_MIN_MEMORY_KI" ]; then
|
|
104
|
+
echo "✖ argocd: at least 1 Gi of allocatable memory is needed in the cluster (available: $((total / 1024)) Mi); enlarge the cluster (Docker Desktop → Settings → Resources), then: devzone workspace services enable argocd" >&2
|
|
105
|
+
return 2
|
|
106
|
+
fi
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
# Initial admin password, read with kubectl (go-template base64decode: no
|
|
110
|
+
# base64 of the workstation involved), written in workspace/.argocd/admin.env
|
|
111
|
+
# (600) and in .password; never printed
|
|
112
|
+
argocd_save_admin_password() {
|
|
113
|
+
local dir password
|
|
114
|
+
dir="$(argocd_secrets_dir)"
|
|
115
|
+
password="$(ak -n "$ARGOCD_NS" get secret argocd-initial-admin-secret \
|
|
116
|
+
-o go-template='{{.data.password | base64decode}}' 2>/dev/null)" || password=""
|
|
117
|
+
if [ -z "$password" ]; then
|
|
118
|
+
echo "⚠ argocd: admin password unreadable (secret argocd-initial-admin-secret); .password not updated" >&2
|
|
119
|
+
return 0
|
|
120
|
+
fi
|
|
121
|
+
mkdir -p "$dir"
|
|
122
|
+
chmod 700 "$dir"
|
|
123
|
+
(
|
|
124
|
+
umask 077
|
|
125
|
+
printf 'ARGOCD_URL=https://localhost:%s\nARGOCD_USER=admin\nARGOCD_PASSWORD=%s\n' "$ARGOCD_LOCAL_PORT" "$password" >"$dir/admin.env"
|
|
126
|
+
)
|
|
127
|
+
chmod 600 "$dir/admin.env"
|
|
128
|
+
argocd_passwords_refresh
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
# .password of the workstation regenerated from workspace/.*/ (password.sh of the package)
|
|
132
|
+
argocd_passwords_refresh() {
|
|
133
|
+
DEVZONE_RACINE="$PWD" bash "$RACINE/.devcontainer/password.sh" regenerer 2>/dev/null ||
|
|
134
|
+
echo "⚠ .password not updated (bash .devcontainer/password.sh regenerer)" >&2
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
# Installs Argo CD (pinned chart and values), idempotent (upgrade --install)
|
|
138
|
+
argocd_install() {
|
|
139
|
+
argocd_memory_ok || return 2
|
|
140
|
+
echo "▶ Argo CD $ARGOCD_CHART_VERSION in $ARGOCD_NS (helm, up to ${ARGOCD_WAIT}s)…"
|
|
141
|
+
ak create namespace "$ARGOCD_NS" --dry-run=client -o yaml | ak apply -f - >/dev/null
|
|
142
|
+
ak label namespace "$ARGOCD_NS" app.kubernetes.io/managed-by=devzone --overwrite >/dev/null
|
|
143
|
+
helm repo add argo https://argoproj.github.io/argo-helm >/dev/null 2>&1 || true
|
|
144
|
+
helm repo update >/dev/null 2>&1 || true
|
|
145
|
+
# shellcheck disable=SC2046
|
|
146
|
+
helm $(drapeau_helm) upgrade --install argocd argo/argo-cd \
|
|
147
|
+
--version "$ARGOCD_CHART_VERSION" --namespace "$ARGOCD_NS" \
|
|
148
|
+
-f "$(argocd_values)" --timeout "${ARGOCD_WAIT}s" --wait || return 1
|
|
149
|
+
argocd_save_admin_password
|
|
150
|
+
echo "✔ Argo CD ready: https://localhost:$ARGOCD_LOCAL_PORT once devzone workspace ports runs; user admin, password in .password"
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
# Installs it when wanted and missing (workspace start); a refusal (memory)
|
|
154
|
+
# is told and the start goes on with helm direct
|
|
155
|
+
argocd_ensure() {
|
|
156
|
+
argocd_wanted || return 0
|
|
157
|
+
argocd_installed && return 0
|
|
158
|
+
argocd_install || echo "⚠ Argo CD not installed: the workspace is deployed with helm directly (devzone workspace services enable argocd to retry)" >&2
|
|
159
|
+
return 0
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
# Applications removed without cascade (finalizer dropped first: the services
|
|
163
|
+
# stay, under helm direct; the GitOps repository keeps its files), then helm
|
|
164
|
+
# uninstall and the namespace
|
|
165
|
+
argocd_uninstall() {
|
|
166
|
+
local app
|
|
167
|
+
if argocd_installed; then
|
|
168
|
+
echo "▶ Argo CD removal: Applications released (their resources stay), release and namespace deleted…"
|
|
169
|
+
while IFS= read -r app; do
|
|
170
|
+
[ -n "$app" ] || continue
|
|
171
|
+
gitops_direct_delete_application "${app#*/}" keep
|
|
172
|
+
done <<<"$(ak -n "$ARGOCD_NS" get applications.argoproj.io -o name 2>/dev/null || true)"
|
|
173
|
+
# shellcheck disable=SC2046
|
|
174
|
+
helm $(drapeau_helm) uninstall argocd --namespace "$ARGOCD_NS" >/dev/null 2>&1 || true
|
|
175
|
+
ak delete namespace "$ARGOCD_NS" --wait=true --ignore-not-found >/dev/null
|
|
176
|
+
fi
|
|
177
|
+
rm -rf "$(argocd_secrets_dir)"
|
|
178
|
+
argocd_passwords_refresh
|
|
179
|
+
echo "✔ Argo CD removed; the services stay, under helm direct"
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
# Applies the Application <name> of <kind> to <namespace> from <repo> at
|
|
183
|
+
# <revision>, <path>; the other arguments are Helm parameters key=value.
|
|
184
|
+
# In the GitOps repository when one is designated (gitops.sh), else directly
|
|
185
|
+
argocd_apply_application() {
|
|
186
|
+
gitops_apply_application "$@"
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
# Deletes an Application (and its file of the GitOps repository); keep:
|
|
190
|
+
# finalizer dropped first, its resources stay
|
|
191
|
+
argocd_delete_application() {
|
|
192
|
+
gitops_delete_application "$@"
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
argocd_application_exists() {
|
|
196
|
+
ak -n "$ARGOCD_NS" get application.argoproj.io "$1" >/dev/null 2>&1
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
# Installed or not, then the Applications with their sync and health status
|
|
200
|
+
argocd_status() {
|
|
201
|
+
if ! argocd_installed; then
|
|
202
|
+
echo "○ argocd not installed: devzone workspace services enable argocd"
|
|
203
|
+
return 0
|
|
204
|
+
fi
|
|
205
|
+
if argocd_wanted; then
|
|
206
|
+
echo "✔ argocd installed: https://localhost:$ARGOCD_LOCAL_PORT (devzone workspace ports), user admin, password in .password"
|
|
207
|
+
else
|
|
208
|
+
echo "⚠ argocd installed but argocd=off in .devzone.modules: devzone workspace services enable argocd, or disable to remove it"
|
|
209
|
+
fi
|
|
210
|
+
if gitops_enabled; then
|
|
211
|
+
echo " GitOps repository: $(gitops_repo) (apps/, root Application $GITOPS_ROOT_APP)"
|
|
212
|
+
else
|
|
213
|
+
echo " no GitOps repository: Applications applied directly (devzone workspace argocd init)"
|
|
214
|
+
fi
|
|
215
|
+
ak -n "$ARGOCD_NS" get applications.argoproj.io \
|
|
216
|
+
-o custom-columns='APPLICATION:.metadata.name,KIND:.metadata.labels.devzone\.io/kind,SYNC:.status.sync.status,HEALTH:.status.health.status,REVISION:.spec.source.targetRevision' \
|
|
217
|
+
2>/dev/null | sed 's/^/ /'
|
|
218
|
+
return 0
|
|
219
|
+
}
|
|
@@ -53,18 +53,25 @@ pw_ports_pod() {
|
|
|
53
53
|
done
|
|
54
54
|
}
|
|
55
55
|
|
|
56
|
-
# Services de devzone à relayer, une ligne « port|namespace|cible »
|
|
57
|
-
# modules actifs : postgres (5432) et pgAdmin s'il existe dans le
|
|
56
|
+
# Services de devzone à relayer, une ligne « port|namespace|cible[|port distant] »
|
|
57
|
+
# par service des modules actifs : postgres (5432) et pgAdmin s'il existe dans le
|
|
58
|
+
# namespace, mysql (3306), et l'interface d'Argo CD (8443 → 443) quand elle est là (#516).
|
|
58
59
|
pw_services() {
|
|
60
|
+
local port
|
|
59
61
|
if grep -qxE 'postgres=(on|true|oui)' .devzone.modules 2>/dev/null; then
|
|
60
62
|
echo "5432|devzone-postgres|svc/postgres"
|
|
61
|
-
local port
|
|
62
63
|
port="$(pw_kubectl --namespace devzone-postgres get svc pgadmin -o "$PW_JSONPATH" 2>/dev/null || true)"
|
|
63
64
|
case "$port" in '' | *[!0-9]*) ;; *) echo "$port|devzone-postgres|svc/pgadmin" ;; esac
|
|
64
65
|
fi
|
|
65
66
|
if grep -qxE 'mysql=(on|true|oui)' .devzone.modules 2>/dev/null; then
|
|
66
67
|
echo "3306|devzone-mysql|svc/mysql"
|
|
67
68
|
fi
|
|
69
|
+
# Argo CD UI: https port of svc/argocd-server on 127.0.0.1:8443, unless argocd=off
|
|
70
|
+
if ! grep -qx 'argocd=off' .devzone.modules 2>/dev/null; then
|
|
71
|
+
port="$(pw_kubectl --namespace devzone-argocd get svc argocd-server \
|
|
72
|
+
-o 'jsonpath={.spec.ports[?(@.name=="https")].port}' 2>/dev/null || true)"
|
|
73
|
+
case "$port" in '' | *[!0-9]*) ;; *) echo "${DEVZONE_ARGOCD_PORT:-8443}|devzone-argocd|svc/argocd-server|$port" ;; esac
|
|
74
|
+
fi
|
|
68
75
|
}
|
|
69
76
|
|
|
70
77
|
# Le port $1 est-il déjà pris sur le poste ? (lsof, sinon nc -z)
|
|
@@ -76,10 +83,10 @@ pw_pris() {
|
|
|
76
83
|
fi
|
|
77
84
|
}
|
|
78
85
|
|
|
79
|
-
# Lance le relais du port $1 vers
|
|
80
|
-
# port pris sur le poste : une seule ligne d'avertissement par port.
|
|
86
|
+
# Lance le relais du port $1 vers le port $4 (défaut : $1) de la cible $3 du namespace
|
|
87
|
+
# $2, sauf s'il vit déjà ; port pris sur le poste : une seule ligne d'avertissement par port.
|
|
81
88
|
pw_relayer() {
|
|
82
|
-
local port="$1" ns="$2" cible="$3" d pid
|
|
89
|
+
local port="$1" ns="$2" cible="$3" distant="${4:-$1}" d pid
|
|
83
90
|
d="$(pw_dir)"
|
|
84
91
|
pid="$(cat "$d/relais/$port" 2>/dev/null || true)"
|
|
85
92
|
pw_vivant "$pid" && return 0
|
|
@@ -88,7 +95,7 @@ pw_relayer() {
|
|
|
88
95
|
return 0
|
|
89
96
|
fi
|
|
90
97
|
# shellcheck disable=SC2046
|
|
91
|
-
kubectl $(pw_ctx) --namespace "$ns" port-forward --address 127.0.0.1 "$cible" "$port:$
|
|
98
|
+
kubectl $(pw_ctx) --namespace "$ns" port-forward --address 127.0.0.1 "$cible" "$port:$distant" </dev/null >/dev/null 2>&1 &
|
|
92
99
|
echo $! >"$d/relais/$port"
|
|
93
100
|
rm -f "$d/pris/$port"
|
|
94
101
|
echo "→ port $port relayé sur 127.0.0.1"
|
|
@@ -105,13 +112,13 @@ pw_retirer() {
|
|
|
105
112
|
|
|
106
113
|
# Un tour du veilleur : relaie les nouveaux ports, retire ceux qui ont disparu.
|
|
107
114
|
pw_tour() {
|
|
108
|
-
local d voulus="" p ns cible l f
|
|
115
|
+
local d voulus="" p ns cible distant l f
|
|
109
116
|
d="$(pw_dir)"
|
|
110
117
|
mkdir -p "$d/relais" "$d/pris"
|
|
111
|
-
while IFS='|' read -r p ns cible; do
|
|
118
|
+
while IFS='|' read -r p ns cible distant; do
|
|
112
119
|
[ -n "$p" ] || continue
|
|
113
120
|
voulus="$voulus $p "
|
|
114
|
-
pw_relayer "$p" "$ns" "$cible"
|
|
121
|
+
pw_relayer "$p" "$ns" "$cible" "${distant:-$p}"
|
|
115
122
|
done <<<"$(pw_services)"
|
|
116
123
|
for p in $(pw_ports_pod); do
|
|
117
124
|
case "$voulus" in *" $p "*) continue ;; esac
|