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,162 @@
|
|
|
1
|
+
#!/usr/bin/env bash
|
|
2
|
+
# devzone workspace services (#528): installs or removes the devzone services
|
|
3
|
+
# (gitlab, postgres, argocd) of a Kubernetes workspace from the workstation.
|
|
4
|
+
# Sourced by manage/workspace.sh (drapeau_kubectl, 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|argocd> [options] | status"
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
services_known() {
|
|
26
|
+
case "${1:-}" in
|
|
27
|
+
gitlab | postgres | argocd) return 0 ;;
|
|
28
|
+
esac
|
|
29
|
+
return 1
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
# Namespace of a service in the cluster (gitlab: default instance)
|
|
33
|
+
services_namespace() {
|
|
34
|
+
case "$1" in
|
|
35
|
+
gitlab) echo devzone-gitlab ;;
|
|
36
|
+
postgres) echo devzone-postgres ;;
|
|
37
|
+
argocd) echo devzone-argocd ;;
|
|
38
|
+
esac
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
# The workspace pod must be running: the installer runs inside it
|
|
42
|
+
services_pod_running() {
|
|
43
|
+
local phase
|
|
44
|
+
# shellcheck disable=SC2046
|
|
45
|
+
phase="$(kubectl $(drapeau_kubectl) get pod "$POD" --namespace "$NAMESPACE" \
|
|
46
|
+
-o jsonpath='{.status.phase}' 2>/dev/null)" || phase=""
|
|
47
|
+
[ "$phase" = Running ]
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
# Temporary administrator: ServiceAccount of the workspace namespace bound to
|
|
51
|
+
# cluster-admin (idempotent apply)
|
|
52
|
+
services_admin_create() {
|
|
53
|
+
# shellcheck disable=SC2046
|
|
54
|
+
kubectl $(drapeau_kubectl) apply -f - >/dev/null <<EOF
|
|
55
|
+
apiVersion: v1
|
|
56
|
+
kind: ServiceAccount
|
|
57
|
+
metadata:
|
|
58
|
+
name: $SERVICES_ADMIN_SA
|
|
59
|
+
namespace: $NAMESPACE
|
|
60
|
+
---
|
|
61
|
+
apiVersion: rbac.authorization.k8s.io/v1
|
|
62
|
+
kind: ClusterRoleBinding
|
|
63
|
+
metadata:
|
|
64
|
+
name: $SERVICES_ADMIN_SA
|
|
65
|
+
roleRef:
|
|
66
|
+
apiGroup: rbac.authorization.k8s.io
|
|
67
|
+
kind: ClusterRole
|
|
68
|
+
name: cluster-admin
|
|
69
|
+
subjects:
|
|
70
|
+
- kind: ServiceAccount
|
|
71
|
+
name: $SERVICES_ADMIN_SA
|
|
72
|
+
namespace: $NAMESPACE
|
|
73
|
+
EOF
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
services_admin_delete() {
|
|
77
|
+
# shellcheck disable=SC2046
|
|
78
|
+
kubectl $(drapeau_kubectl) delete clusterrolebinding "$SERVICES_ADMIN_SA" \
|
|
79
|
+
--ignore-not-found >/dev/null 2>&1 || true
|
|
80
|
+
# shellcheck disable=SC2046
|
|
81
|
+
kubectl $(drapeau_kubectl) delete serviceaccount "$SERVICES_ADMIN_SA" \
|
|
82
|
+
--namespace "$NAMESPACE" --ignore-not-found >/dev/null 2>&1 || true
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
# Runs the installer in the pod: temporary administrator created, token on
|
|
86
|
+
# stdin of kubectl exec, administrator removed whatever the outcome
|
|
87
|
+
services_run() {
|
|
88
|
+
local action="$1" service="$2" token code=0
|
|
89
|
+
shift 2
|
|
90
|
+
if ! services_known "$service"; then
|
|
91
|
+
echo "✖ unknown service: ${service:-(none)} ($(services_usage))" >&2
|
|
92
|
+
return 1
|
|
93
|
+
fi
|
|
94
|
+
# Argo CD itself, and postgres when Argo CD holds the devzone charts: done
|
|
95
|
+
# by the workstation, no installer in the pod (#516)
|
|
96
|
+
if [ "$service" = argocd ]; then
|
|
97
|
+
argocd_toggle "$action" "$@"
|
|
98
|
+
return
|
|
99
|
+
fi
|
|
100
|
+
if [ "$service" = postgres ] && argocd_holds_charts; then
|
|
101
|
+
postgres_argocd "$action" "$@"
|
|
102
|
+
return
|
|
103
|
+
fi
|
|
104
|
+
if ! services_pod_running; then
|
|
105
|
+
echo "✖ workspace pod $POD not running: devzone workspace start" >&2
|
|
106
|
+
return 1
|
|
107
|
+
fi
|
|
108
|
+
echo "▶ temporary administrator $SERVICES_ADMIN_SA (removed at the end)…"
|
|
109
|
+
if ! services_admin_create; then
|
|
110
|
+
echo "✖ cannot create the temporary administrator: cluster-admin rights needed on the workstation" >&2
|
|
111
|
+
return 1
|
|
112
|
+
fi
|
|
113
|
+
trap services_admin_delete EXIT
|
|
114
|
+
# shellcheck disable=SC2046
|
|
115
|
+
if ! token="$(kubectl $(drapeau_kubectl) create token "$SERVICES_ADMIN_SA" \
|
|
116
|
+
--namespace "$NAMESPACE" --duration "$SERVICES_TOKEN_DURATION")" || [ -z "$token" ]; then
|
|
117
|
+
echo "✖ cannot get a token of the temporary administrator (kubectl 1.24 or more)" >&2
|
|
118
|
+
services_admin_delete
|
|
119
|
+
trap - EXIT
|
|
120
|
+
return 1
|
|
121
|
+
fi
|
|
122
|
+
echo "▶ $action $service in the pod $POD…"
|
|
123
|
+
# The installer of the pod still spells --oui (#510): --yes translated
|
|
124
|
+
set -- "${@/--yes/--oui}"
|
|
125
|
+
# shellcheck disable=SC2046
|
|
126
|
+
printf '%s\n' "$token" | kubectl $(drapeau_kubectl) exec -i "$POD" --namespace "$NAMESPACE" \
|
|
127
|
+
-c workspace -- bash "$SERVICES_ADMIN_SCRIPT" "$action" "$service" "$@" || code=$?
|
|
128
|
+
services_admin_delete
|
|
129
|
+
trap - EXIT
|
|
130
|
+
if [ "$code" -ne 0 ]; then
|
|
131
|
+
echo "✖ $action $service failed (code $code); in the pod: devzone status" >&2
|
|
132
|
+
return "$code"
|
|
133
|
+
fi
|
|
134
|
+
echo "✔ $action $service done; in the pod: devzone status; local access: devzone workspace ports"
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
# One line per service: installed (namespace present) or not
|
|
138
|
+
services_status() {
|
|
139
|
+
local s ns
|
|
140
|
+
for s in gitlab postgres argocd; do
|
|
141
|
+
ns="$(services_namespace "$s")"
|
|
142
|
+
# shellcheck disable=SC2046
|
|
143
|
+
if kubectl $(drapeau_kubectl) get namespace "$ns" >/dev/null 2>&1; then
|
|
144
|
+
echo " ✔ $s installed (namespace $ns): devzone workspace services disable $s"
|
|
145
|
+
else
|
|
146
|
+
echo " ○ $s not installed: devzone workspace services enable $s"
|
|
147
|
+
fi
|
|
148
|
+
done
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
services() {
|
|
152
|
+
local sub="${1:-}"
|
|
153
|
+
case "$sub" in
|
|
154
|
+
enable | activer) services_run enable "${2:-}" "${@:3}" ;;
|
|
155
|
+
disable | desactiver) services_run disable "${2:-}" "${@:3}" ;;
|
|
156
|
+
status | etat | '') services_status ;;
|
|
157
|
+
*)
|
|
158
|
+
echo "✖ unknown subcommand: $sub ($(services_usage))" >&2
|
|
159
|
+
return 1
|
|
160
|
+
;;
|
|
161
|
+
esac
|
|
162
|
+
}
|
|
@@ -37,8 +37,8 @@ attendre_pod() {
|
|
|
37
37
|
;;
|
|
38
38
|
esac
|
|
39
39
|
echo " Pour une image construite à la main : devzone workspace demarrer --image <repository:tag>" >&2
|
|
40
|
-
#
|
|
41
|
-
|
|
40
|
+
# Application Argo CD ou release helm (#516) : sinon selfHeal recréerait le pod
|
|
41
|
+
workspace_undeploy >/dev/null 2>&1 || true
|
|
42
42
|
return 1
|
|
43
43
|
;;
|
|
44
44
|
Running*)
|
package/manage/workspace.sh
CHANGED
|
@@ -77,6 +77,18 @@ demarrer() {
|
|
|
77
77
|
esac
|
|
78
78
|
done
|
|
79
79
|
image="$depot:$tag"
|
|
80
|
+
# Argo CD first when wanted (#516): the workspace is then an Application
|
|
81
|
+
argocd_ensure
|
|
82
|
+
workspace_deploy "$depot" "$tag" "$avec_image"
|
|
83
|
+
# Projects of .argocd.conf held too (#516)
|
|
84
|
+
argocd_reconcile || true
|
|
85
|
+
attendre_pod "$image" || return 1
|
|
86
|
+
ports_demarrer silence
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
# helm direct: the chart of the package, image set by the options
|
|
90
|
+
workspace_helm_deploy() {
|
|
91
|
+
local depot="$1" tag="$2" avec_image="$3" args=()
|
|
80
92
|
args=(--namespace devzone-workspace --create-namespace)
|
|
81
93
|
if [ -n "$avec_image" ]; then
|
|
82
94
|
args+=(--set "image.repository=$depot" --set "image.tag=$tag")
|
|
@@ -90,15 +102,12 @@ demarrer() {
|
|
|
90
102
|
fi
|
|
91
103
|
# shellcheck disable=SC2046
|
|
92
104
|
helm $(drapeau_helm) upgrade --install devzone-workspace "$(chemin_chart)" "${args[@]}"
|
|
93
|
-
attendre_pod "$image" || return 1
|
|
94
|
-
ports_demarrer silence
|
|
95
105
|
}
|
|
96
106
|
|
|
97
|
-
# Désinstalle le workspace du cluster.
|
|
107
|
+
# Désinstalle le workspace du cluster (Application Argo CD ou release helm).
|
|
98
108
|
arreter() {
|
|
99
109
|
ports_arreter
|
|
100
|
-
|
|
101
|
-
helm $(drapeau_helm) uninstall devzone-workspace --namespace devzone-workspace
|
|
110
|
+
workspace_undeploy
|
|
102
111
|
}
|
|
103
112
|
|
|
104
113
|
# Affiche l'état des pods du workspace.
|
|
@@ -169,6 +178,12 @@ copier_depuis() {
|
|
|
169
178
|
. "$ICI/scripts/migrer-retour.sh"
|
|
170
179
|
# shellcheck source=scripts/ports-workspace.sh
|
|
171
180
|
. "$ICI/scripts/ports-workspace.sh"
|
|
181
|
+
# shellcheck source=scripts/services-workspace.sh
|
|
182
|
+
. "$ICI/scripts/services-workspace.sh"
|
|
183
|
+
# shellcheck source=scripts/argocd-workspace.sh
|
|
184
|
+
. "$ICI/scripts/argocd-workspace.sh"
|
|
185
|
+
# shellcheck source=scripts/argocd-services.sh
|
|
186
|
+
. "$ICI/scripts/argocd-services.sh"
|
|
172
187
|
|
|
173
188
|
# English command names are accepted, French ones unchanged (#502).
|
|
174
189
|
# A copied devzone may miss the aliases file: then no normalization.
|
|
@@ -193,16 +208,22 @@ case "${1:-}" in
|
|
|
193
208
|
migrer) migrer "${@:2}" ;;
|
|
194
209
|
revenir) revenir "${@:2}" ;;
|
|
195
210
|
nettoyer-docker) nettoyer_docker "${@:2}" ;;
|
|
211
|
+
services) services "${@:2}" ;;
|
|
212
|
+
argocd) argocd_cmd "${@:2}" ;;
|
|
196
213
|
'' | -h | --help | aide)
|
|
197
|
-
echo "devzone workspace demarrer|arreter|etat|shell|vscode|copier-vers|copier-depuis|ports|migrer|revenir|nettoyer-docker"
|
|
214
|
+
echo "devzone workspace demarrer|arreter|etat|shell|vscode|copier-vers|copier-depuis|ports|services|argocd|migrer|revenir|nettoyer-docker"
|
|
198
215
|
echo " demarrer [--image dépôt:tag] installe le workspace (image de la version de devzone par défaut)"
|
|
199
216
|
echo " ports [demarrer|arreter|etat] applications et services du pod sur localhost du poste"
|
|
217
|
+
echo " services enable|disable <service> [options] | status"
|
|
218
|
+
echo " devzone services (gitlab, postgres, argocd) of the cluster, installed from the workstation"
|
|
219
|
+
echo " argocd status | app add <repo url> [path] [--name N] [--revision R] | app list | app remove <N>"
|
|
220
|
+
echo " Argo CD of the workspace: deployments held in Git, your projects as Applications"
|
|
200
221
|
echo " migrer [--oui] copie le poste Docker vers le workspace Kubernetes (rien n'est supprimé)"
|
|
201
222
|
echo " revenir [--rapatrier] retour au poste Docker ; --rapatrier : projets du pod recopiés d'abord"
|
|
202
223
|
echo " nettoyer-docker supprime les volumes Docker devzone-*, après confirmation [o/N] (--oui)"
|
|
203
224
|
;;
|
|
204
225
|
*)
|
|
205
|
-
echo "✖ sous-commande inconnue : $1 (devzone workspace demarrer|arreter|etat|shell|vscode|copier-vers|copier-depuis|ports|migrer|revenir|nettoyer-docker)" >&2
|
|
226
|
+
echo "✖ sous-commande inconnue : $1 (devzone workspace demarrer|arreter|etat|shell|vscode|copier-vers|copier-depuis|ports|services|argocd|migrer|revenir|nettoyer-docker)" >&2
|
|
206
227
|
exit 1
|
|
207
228
|
;;
|
|
208
229
|
esac
|