devzone 0.41.0 → 0.42.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/catalogue-argocd.sh +1 -0
- package/.devcontainer/argocd/services.sh +16 -0
- package/.devcontainer/catalogue/mysql/manifeste.yaml +4 -0
- package/.devcontainer/postgres/postgres.yaml +4 -0
- package/charts/devzone-mysql/templates/service.yaml +2 -0
- package/charts/devzone-mysql/templates/statefulset.yaml +2 -0
- package/charts/devzone-postgres/templates/service.yaml +3 -1
- package/charts/devzone-postgres/templates/statefulset.yaml +5 -3
- package/charts/devzone-postgres/values.yaml +6 -1
- package/charts/devzone-workspace/Chart.yaml +1 -1
- package/charts/devzone-workspace/templates/networkpolicy.yaml +4 -0
- package/charts/devzone-workspace/templates/role.yaml +4 -0
- package/charts/devzone-workspace/templates/rolebinding.yaml +4 -0
- package/charts/devzone-workspace/templates/service.yaml +4 -0
- package/charts/devzone-workspace/templates/serviceaccount.yaml +4 -0
- package/charts/devzone-workspace/templates/statefulset.yaml +4 -0
- package/manage/scripts/argocd-services-svc.sh +2 -0
- package/manage/scripts/argocd-services.sh +1 -0
- package/manage/scripts/argocd-workspace.sh +7 -1
- package/manage/scripts/check-charts.sh +158 -0
- package/manage/scripts/kube-ready.sh +54 -10
- package/manage/workspace.sh +4 -1
- package/package.json +1 -1
|
@@ -88,6 +88,7 @@ catalogue_argocd_active() {
|
|
|
88
88
|
catalogue_argocd_apply() {
|
|
89
89
|
local app="$1" ns="$2" image="$3" port="$4" memory="$5" size="$6" params extra="${7:-}"
|
|
90
90
|
catalogue_argocd_load
|
|
91
|
+
chart_require "$app" || return $?
|
|
91
92
|
params="image=$image port=$port memory=$memory size=$size"
|
|
92
93
|
[ -n "$extra" ] && params="$params $extra"
|
|
93
94
|
# shellcheck disable=SC2086
|
|
@@ -17,6 +17,7 @@
|
|
|
17
17
|
# services_reconcile every service applied or released
|
|
18
18
|
# services_state_of <svc> on | off | empty (not declared)
|
|
19
19
|
# services_note <svc> on|off writes the [services] section
|
|
20
|
+
# chart_require <svc> chart charts/devzone-<svc> named devzone-<svc>, or code 2
|
|
20
21
|
# Sourced after conf.sh and gitops.sh by the workstation
|
|
21
22
|
# (manage/scripts/argocd-services.sh) and by the container (argocd.sh). The
|
|
22
23
|
# includer defines argocd_kubectl, APPS_GENERATOR, ARGOCD_CONF and
|
|
@@ -35,6 +36,18 @@ services_app_of() { printf 'devzone-%s' "$1"; }
|
|
|
35
36
|
# Used by services_namespace_prepare and services_application_apply.
|
|
36
37
|
services_ns_of() { printf 'devzone-%s' "$1"; }
|
|
37
38
|
|
|
39
|
+
# The chart of a service, charts/devzone-<svc> of RACINE (the package), must
|
|
40
|
+
# exist and name itself devzone-<svc> in Chart.yaml. Otherwise a refusal, code
|
|
41
|
+
# 2, before anything is applied (#554)
|
|
42
|
+
chart_require() {
|
|
43
|
+
local svc="$1" chart="$RACINE/charts/devzone-$1"
|
|
44
|
+
if [ -f "$chart/Chart.yaml" ] && grep -qxF "name: devzone-$svc" "$chart/Chart.yaml"; then
|
|
45
|
+
return 0
|
|
46
|
+
fi
|
|
47
|
+
echo "✖ $svc : chart charts/devzone-$svc missing or misnamed (manage/docs/reference.md#charts-de-devzone)" >&2
|
|
48
|
+
return 2
|
|
49
|
+
}
|
|
50
|
+
|
|
38
51
|
# State of a service: [services] of .argocd.conf first, then the line
|
|
39
52
|
# <svc>=on|off of .devzone.modules (compatibility, #538); empty when neither
|
|
40
53
|
# holds the service
|
|
@@ -92,6 +105,7 @@ EOF
|
|
|
92
105
|
# repository at the revision; the parameters hook adds helm parameters
|
|
93
106
|
services_application_apply() {
|
|
94
107
|
local svc="$1" extra=""
|
|
108
|
+
chart_require "$svc" || return $?
|
|
95
109
|
set -- "$(services_app_of "$svc")" service "$(services_ns_of "$svc")" \
|
|
96
110
|
"$DEVZONE_REPO_URL" "$(argocd_revision)" "charts/devzone-$svc"
|
|
97
111
|
if command -v "services_chart_$svc" >/dev/null 2>&1; then
|
|
@@ -118,6 +132,8 @@ services_reconcile() {
|
|
|
118
132
|
state="$(services_state_of "$svc")"
|
|
119
133
|
case "$state" in
|
|
120
134
|
on)
|
|
135
|
+
# Before the namespace and the secret: a misnamed chart applies nothing
|
|
136
|
+
chart_require "$svc" || { code=2; continue; }
|
|
121
137
|
services_namespace_prepare "$svc" || code=1
|
|
122
138
|
if command -v "services_secret_$svc" >/dev/null 2>&1; then
|
|
123
139
|
"services_secret_$svc" || code=1
|
|
@@ -11,6 +11,8 @@ metadata:
|
|
|
11
11
|
namespace: __NS__
|
|
12
12
|
labels:
|
|
13
13
|
app: __APP__
|
|
14
|
+
app.kubernetes.io/name: __APP__
|
|
15
|
+
app.kubernetes.io/part-of: devzone
|
|
14
16
|
app.kubernetes.io/managed-by: devzone
|
|
15
17
|
spec:
|
|
16
18
|
selector:
|
|
@@ -27,6 +29,8 @@ metadata:
|
|
|
27
29
|
namespace: __NS__
|
|
28
30
|
labels:
|
|
29
31
|
app: __APP__
|
|
32
|
+
app.kubernetes.io/name: __APP__
|
|
33
|
+
app.kubernetes.io/part-of: devzone
|
|
30
34
|
app.kubernetes.io/managed-by: devzone
|
|
31
35
|
spec:
|
|
32
36
|
serviceName: __APP__
|
|
@@ -10,6 +10,8 @@ metadata:
|
|
|
10
10
|
namespace: devzone-postgres
|
|
11
11
|
labels:
|
|
12
12
|
app: postgres
|
|
13
|
+
app.kubernetes.io/name: postgres
|
|
14
|
+
app.kubernetes.io/part-of: devzone
|
|
13
15
|
app.kubernetes.io/managed-by: devzone
|
|
14
16
|
spec:
|
|
15
17
|
selector:
|
|
@@ -26,6 +28,8 @@ metadata:
|
|
|
26
28
|
namespace: devzone-postgres
|
|
27
29
|
labels:
|
|
28
30
|
app: postgres
|
|
31
|
+
app.kubernetes.io/name: postgres
|
|
32
|
+
app.kubernetes.io/part-of: devzone
|
|
29
33
|
app.kubernetes.io/managed-by: devzone
|
|
30
34
|
spec:
|
|
31
35
|
serviceName: postgres
|
|
@@ -5,11 +5,13 @@ metadata:
|
|
|
5
5
|
namespace: {{ .Release.Namespace }}
|
|
6
6
|
labels:
|
|
7
7
|
app: postgres
|
|
8
|
+
app.kubernetes.io/name: postgres
|
|
9
|
+
app.kubernetes.io/part-of: devzone
|
|
8
10
|
app.kubernetes.io/managed-by: devzone
|
|
9
11
|
spec:
|
|
10
12
|
selector:
|
|
11
13
|
app: postgres
|
|
12
14
|
ports:
|
|
13
15
|
- name: postgres
|
|
14
|
-
port:
|
|
16
|
+
port: {{ .Values.port }}
|
|
15
17
|
targetPort: 5432
|
|
@@ -5,6 +5,8 @@ metadata:
|
|
|
5
5
|
namespace: {{ .Release.Namespace }}
|
|
6
6
|
labels:
|
|
7
7
|
app: postgres
|
|
8
|
+
app.kubernetes.io/name: postgres
|
|
9
|
+
app.kubernetes.io/part-of: devzone
|
|
8
10
|
app.kubernetes.io/managed-by: devzone
|
|
9
11
|
spec:
|
|
10
12
|
serviceName: postgres
|
|
@@ -40,13 +42,13 @@ spec:
|
|
|
40
42
|
resources:
|
|
41
43
|
requests:
|
|
42
44
|
cpu: {{ .Values.resources.requests.cpu }}
|
|
43
|
-
memory: {{ .Values.
|
|
45
|
+
memory: {{ .Values.memory }}
|
|
44
46
|
volumeMounts:
|
|
45
|
-
- name:
|
|
47
|
+
- name: {{ .Values.claim }}
|
|
46
48
|
mountPath: /var/lib/postgresql/data
|
|
47
49
|
volumeClaimTemplates:
|
|
48
50
|
- metadata:
|
|
49
|
-
name:
|
|
51
|
+
name: {{ .Values.claim }}
|
|
50
52
|
labels:
|
|
51
53
|
app.kubernetes.io/managed-by: devzone
|
|
52
54
|
spec:
|
|
@@ -3,9 +3,14 @@
|
|
|
3
3
|
# secret postgres-admin (superuser password) is created apart by devzone,
|
|
4
4
|
# never by the chart (#516: secrets out of Git).
|
|
5
5
|
image: postgres:16.15-alpine
|
|
6
|
+
# Port of the Service (the container always listens on 5432)
|
|
7
|
+
port: 5432
|
|
8
|
+
# Memory request of the container
|
|
9
|
+
memory: 256Mi
|
|
10
|
+
# Name of the volume claim template mounted on the container
|
|
11
|
+
claim: donnees
|
|
6
12
|
# Size of the data volume (POSTGRES_TAILLE of the helm-direct path)
|
|
7
13
|
size: 5Gi
|
|
8
14
|
resources:
|
|
9
15
|
requests:
|
|
10
16
|
cpu: 100m
|
|
11
|
-
memory: 256Mi
|
|
@@ -4,6 +4,10 @@ kind: NetworkPolicy
|
|
|
4
4
|
metadata:
|
|
5
5
|
name: {{ include "devzone-workspace.fullname" . }}
|
|
6
6
|
namespace: {{ .Release.Namespace }}
|
|
7
|
+
labels:
|
|
8
|
+
app.kubernetes.io/name: {{ include "devzone-workspace.name" . }}
|
|
9
|
+
app.kubernetes.io/part-of: devzone
|
|
10
|
+
app.kubernetes.io/managed-by: devzone
|
|
7
11
|
spec:
|
|
8
12
|
podSelector: {}
|
|
9
13
|
policyTypes:
|
|
@@ -3,6 +3,10 @@ kind: Role
|
|
|
3
3
|
metadata:
|
|
4
4
|
name: devzone-workspace
|
|
5
5
|
namespace: {{ .Release.Namespace }}
|
|
6
|
+
labels:
|
|
7
|
+
app.kubernetes.io/name: {{ include "devzone-workspace.name" . }}
|
|
8
|
+
app.kubernetes.io/part-of: devzone
|
|
9
|
+
app.kubernetes.io/managed-by: devzone
|
|
6
10
|
# Rights of kubedock (0.23.0, read in its sources), limited to the namespace:
|
|
7
11
|
# pods (create and delete the test containers, list and follow them),
|
|
8
12
|
# pods/log, pods/exec and pods/portforward (logs, commands, ports), services and
|
|
@@ -3,6 +3,10 @@ kind: RoleBinding
|
|
|
3
3
|
metadata:
|
|
4
4
|
name: devzone-workspace
|
|
5
5
|
namespace: {{ .Release.Namespace }}
|
|
6
|
+
labels:
|
|
7
|
+
app.kubernetes.io/name: {{ include "devzone-workspace.name" . }}
|
|
8
|
+
app.kubernetes.io/part-of: devzone
|
|
9
|
+
app.kubernetes.io/managed-by: devzone
|
|
6
10
|
subjects:
|
|
7
11
|
- kind: ServiceAccount
|
|
8
12
|
name: {{ include "devzone-workspace.serviceAccountName" . }}
|
|
@@ -3,6 +3,10 @@ kind: Service
|
|
|
3
3
|
metadata:
|
|
4
4
|
name: {{ include "devzone-workspace.fullname" . }}
|
|
5
5
|
namespace: {{ .Release.Namespace }}
|
|
6
|
+
labels:
|
|
7
|
+
app.kubernetes.io/name: {{ include "devzone-workspace.name" . }}
|
|
8
|
+
app.kubernetes.io/part-of: devzone
|
|
9
|
+
app.kubernetes.io/managed-by: devzone
|
|
6
10
|
spec:
|
|
7
11
|
clusterIP: None
|
|
8
12
|
selector:
|
|
@@ -4,4 +4,8 @@ kind: ServiceAccount
|
|
|
4
4
|
metadata:
|
|
5
5
|
name: {{ include "devzone-workspace.serviceAccountName" . }}
|
|
6
6
|
namespace: {{ .Release.Namespace }}
|
|
7
|
+
labels:
|
|
8
|
+
app.kubernetes.io/name: {{ include "devzone-workspace.name" . }}
|
|
9
|
+
app.kubernetes.io/part-of: devzone
|
|
10
|
+
app.kubernetes.io/managed-by: devzone
|
|
7
11
|
{{- end -}}
|
|
@@ -3,6 +3,10 @@ kind: StatefulSet
|
|
|
3
3
|
metadata:
|
|
4
4
|
name: {{ include "devzone-workspace.fullname" . }}
|
|
5
5
|
namespace: {{ .Release.Namespace }}
|
|
6
|
+
labels:
|
|
7
|
+
app.kubernetes.io/name: {{ include "devzone-workspace.name" . }}
|
|
8
|
+
app.kubernetes.io/part-of: devzone
|
|
9
|
+
app.kubernetes.io/managed-by: devzone
|
|
6
10
|
spec:
|
|
7
11
|
serviceName: {{ include "devzone-workspace.fullname" . }}
|
|
8
12
|
replicas: {{ .Values.replicaCount }}
|
|
@@ -81,6 +81,8 @@ services_argocd_toggle() {
|
|
|
81
81
|
echo "✖ $svc through Argo CD takes no option (got: $*)" >&2
|
|
82
82
|
return 1
|
|
83
83
|
fi
|
|
84
|
+
# Before [services] is written: a refused chart leaves the state unchanged
|
|
85
|
+
chart_require "$svc" || return $?
|
|
84
86
|
echo "▶ $svc as an Argo CD Application (charts/devzone-$svc at $(argocd_revision))…"
|
|
85
87
|
services_note "$svc" on
|
|
86
88
|
services_reconcile
|
|
@@ -109,6 +109,7 @@ workspace_deploy() {
|
|
|
109
109
|
params="image.tag=$tag"
|
|
110
110
|
[ -z "$with_image" ] || params="$params image.repository=$repository"
|
|
111
111
|
[ "$tag" != latest ] || params="$params image.pullPolicy=Always"
|
|
112
|
+
chart_require workspace || return $?
|
|
112
113
|
# GitOps repository created or designated first, with its root Application
|
|
113
114
|
gitops_init || return 1
|
|
114
115
|
gitops_root || return 1
|
|
@@ -137,6 +137,7 @@ argocd_passwords_refresh() {
|
|
|
137
137
|
|
|
138
138
|
# Installs Argo CD (pinned chart and values), idempotent (upgrade --install)
|
|
139
139
|
argocd_install() {
|
|
140
|
+
chart_require argocd || return 2
|
|
140
141
|
argocd_memory_ok || return 2
|
|
141
142
|
echo "▶ Argo CD $ARGOCD_CHART_VERSION in $ARGOCD_NS (helm, up to ${ARGOCD_WAIT}s)…"
|
|
142
143
|
ak create namespace "$ARGOCD_NS" --dry-run=client -o yaml | ak apply -f - >/dev/null
|
|
@@ -153,10 +154,15 @@ argocd_install() {
|
|
|
153
154
|
}
|
|
154
155
|
|
|
155
156
|
# Installs it when wanted and missing (workspace start); a refusal (memory)
|
|
156
|
-
# is told and the start goes on with helm direct
|
|
157
|
+
# is told and the start goes on with helm direct. A cluster that does not
|
|
158
|
+
# answer is not "helm direct": the start has already stopped on it (#565)
|
|
157
159
|
argocd_ensure() {
|
|
158
160
|
argocd_wanted || return 0
|
|
159
161
|
argocd_installed && return 0
|
|
162
|
+
if ! kube_ready_reason >/dev/null; then
|
|
163
|
+
echo "⚠ Argo CD not checked: the cluster does not answer (devzone workspace services enable argocd once it does)" >&2
|
|
164
|
+
return 0
|
|
165
|
+
fi
|
|
160
166
|
argocd_install || echo "⚠ Argo CD not installed: the workspace is deployed with helm directly (devzone workspace services enable argocd to retry)" >&2
|
|
161
167
|
return 0
|
|
162
168
|
}
|
|
@@ -0,0 +1,158 @@
|
|
|
1
|
+
#!/usr/bin/env bash
|
|
2
|
+
# CI check of the convention of the devzone charts (#554), documented in the
|
|
3
|
+
# section "Charts de devzone" of manage/docs/reference.md. Each folder of
|
|
4
|
+
# charts/ is checked: its name, Chart.yaml, then its family, by its
|
|
5
|
+
# dependencies: a wrapper (Chart.lock, oci:// recommended) or a service
|
|
6
|
+
# (templates without a hard-coded namespace, Secret, Ingress or LoadBalancer,
|
|
7
|
+
# the three labels on each object; the common keys in values.yaml). Every
|
|
8
|
+
# charts/devzone-<x> named by the code must be a folder. helm lint and helm
|
|
9
|
+
# template run when helm is installed. A fault is printed as
|
|
10
|
+
# "✖ charts/<x> : <rule>" and the run exits 1; otherwise
|
|
11
|
+
# "✔ charts : N charts conformes". Tests: CHARTS_DIR, CHARTS_CODE_DIRS and
|
|
12
|
+
# CHARTS_NO_HELM=1. bash 3.2 (macOS).
|
|
13
|
+
|
|
14
|
+
set -u
|
|
15
|
+
|
|
16
|
+
ICI="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
|
17
|
+
ROOT="$(cd "$ICI/../.." && pwd)"
|
|
18
|
+
CHARTS_DIR="${CHARTS_DIR:-$ROOT/charts}"
|
|
19
|
+
CHARTS_CODE_DIRS="${CHARTS_CODE_DIRS:-$ROOT/.devcontainer $ROOT/manage/scripts}"
|
|
20
|
+
# The workstation keeps its own values (per volume, not a shared service)
|
|
21
|
+
CHARTS_NO_COMMON="devzone-workspace"
|
|
22
|
+
COMMON_KEYS="image size memory port claim resources"
|
|
23
|
+
FAULTS=0
|
|
24
|
+
COUNT=0
|
|
25
|
+
|
|
26
|
+
fault() {
|
|
27
|
+
printf '✖ charts/%s : %s\n' "$1" "$2"
|
|
28
|
+
FAULTS=$((FAULTS + 1))
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
# Top-level key of Chart.yaml (file, key), quotes removed
|
|
32
|
+
chart_key() {
|
|
33
|
+
sed -n "s/^$2:[[:space:]]*//p" "$1" | head -1 |
|
|
34
|
+
sed -e 's/[[:space:]]*$//' -e 's/^"\(.*\)"$/\1/' -e "s/^'\(.*\)'\$/\1/"
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
# Chart.yaml: name equal to the folder, type, version (semver), appVersion and
|
|
38
|
+
# description not empty
|
|
39
|
+
charts_check_chart_yaml() {
|
|
40
|
+
local f="$1/Chart.yaml" name="$2" re='^[0-9]+\.[0-9]+\.[0-9]+([-+][0-9A-Za-z.+-]*)?$'
|
|
41
|
+
[ "$(chart_key "$f" name)" = "$name" ] || fault "$name" "Chart.yaml name must be \"$name\""
|
|
42
|
+
[ "$(chart_key "$f" type)" = application ] || fault "$name" "Chart.yaml type must be application"
|
|
43
|
+
[[ "$(chart_key "$f" version)" =~ $re ]] || fault "$name" "Chart.yaml version must be semver"
|
|
44
|
+
[ -n "$(chart_key "$f" appVersion)" ] || fault "$name" "Chart.yaml appVersion must not be empty"
|
|
45
|
+
[ -n "$(chart_key "$f" description)" ] || fault "$name" "Chart.yaml description must not be empty"
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
# Wrapper: Chart.lock committed; a repository outside oci:// is a warning
|
|
49
|
+
charts_check_wrapper() {
|
|
50
|
+
local dir="$1" name="$2"
|
|
51
|
+
[ -f "$dir/Chart.lock" ] || fault "$name" "wrapper without Chart.lock (commit it)"
|
|
52
|
+
if grep -E '^[[:space:]]*repository:' "$dir/Chart.yaml" | grep -qv 'oci://'; then
|
|
53
|
+
echo "⚠ charts/$name : a dependency repository is not oci:// (recommended)"
|
|
54
|
+
fi
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
# Service: objects (a kind: line) with the labels, no hard-coded namespace,
|
|
58
|
+
# no Secret, no Ingress, no LoadBalancer
|
|
59
|
+
charts_check_templates() {
|
|
60
|
+
local dir="$1" name="$2" f rel label
|
|
61
|
+
for f in "$dir"/templates/*.yaml; do
|
|
62
|
+
[ -f "$f" ] || continue
|
|
63
|
+
rel="templates/$(basename "$f")"
|
|
64
|
+
if grep -E '^[[:space:]]*namespace:' "$f" | grep -qv 'Release\.Namespace'; then
|
|
65
|
+
fault "$name" "$rel: namespace must be {{ .Release.Namespace }}, not hard-coded"
|
|
66
|
+
fi
|
|
67
|
+
grep -Eq '^kind:[[:space:]]*Secret' "$f" && fault "$name" "$rel: no Secret in a chart (created apart)"
|
|
68
|
+
grep -Eq '^kind:[[:space:]]*Ingress' "$f" && fault "$name" "$rel: no Ingress in a chart"
|
|
69
|
+
grep -Eq 'type:[[:space:]]*LoadBalancer' "$f" && fault "$name" "$rel: no LoadBalancer in a chart"
|
|
70
|
+
grep -Eq '^kind:' "$f" || continue
|
|
71
|
+
for label in 'app.kubernetes.io/name:' 'app.kubernetes.io/part-of: devzone' 'app.kubernetes.io/managed-by: devzone'; do
|
|
72
|
+
grep -Fq "$label" "$f" || fault "$name" "$rel: label $label missing"
|
|
73
|
+
done
|
|
74
|
+
done
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
# Service: the common keys of values.yaml (the workstation is exempt)
|
|
78
|
+
charts_check_values() {
|
|
79
|
+
local dir="$1" name="$2" key
|
|
80
|
+
case " $CHARTS_NO_COMMON " in *" $name "*) return 0 ;; esac
|
|
81
|
+
for key in $COMMON_KEYS; do
|
|
82
|
+
grep -Eq "^$key:" "$dir/values.yaml" || fault "$name" "values.yaml lacks the common key $key"
|
|
83
|
+
done
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
# helm lint and template, on a copy: the wrapper gets its dependency built
|
|
87
|
+
# first, with an empty DOCKER_CONFIG (anonymous pull)
|
|
88
|
+
charts_check_helm() {
|
|
89
|
+
local dir="$1" name="$2" tmp conf
|
|
90
|
+
[ "${CHARTS_NO_HELM:-0}" = 1 ] && return 0
|
|
91
|
+
command -v helm >/dev/null 2>&1 || return 0
|
|
92
|
+
tmp="$(mktemp -d)" || return 0
|
|
93
|
+
conf="$(mktemp -d)"
|
|
94
|
+
cp -R "$dir" "$tmp/$name"
|
|
95
|
+
if grep -q '^dependencies:' "$dir/Chart.yaml"; then
|
|
96
|
+
DOCKER_CONFIG="$conf" helm dependency build "$tmp/$name" >"$tmp/log" 2>&1 ||
|
|
97
|
+
fault "$name" "helm dependency build fails: $(tail -1 "$tmp/log")"
|
|
98
|
+
fi
|
|
99
|
+
helm lint --quiet "$tmp/$name" >"$tmp/log" 2>&1 || fault "$name" "helm lint fails: $(tail -1 "$tmp/log")"
|
|
100
|
+
DOCKER_CONFIG="$conf" helm template "$name" "$tmp/$name" >/dev/null 2>"$tmp/log" ||
|
|
101
|
+
fault "$name" "helm template fails: $(tail -1 "$tmp/log")"
|
|
102
|
+
rm -rf "$tmp" "$conf"
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
# One folder of charts/
|
|
106
|
+
charts_check_dir() {
|
|
107
|
+
local dir="$1" name re='^devzone-[a-z0-9-]+$'
|
|
108
|
+
name="$(basename "$dir")"
|
|
109
|
+
COUNT=$((COUNT + 1))
|
|
110
|
+
[[ "$name" =~ $re ]] || fault "$name" "folder name must match devzone-[a-z0-9-]+"
|
|
111
|
+
if [ ! -f "$dir/Chart.yaml" ]; then
|
|
112
|
+
fault "$name" "Chart.yaml missing"
|
|
113
|
+
return 0
|
|
114
|
+
fi
|
|
115
|
+
[ -f "$dir/values.yaml" ] || fault "$name" "values.yaml missing"
|
|
116
|
+
charts_check_chart_yaml "$dir" "$name"
|
|
117
|
+
if grep -q '^dependencies:' "$dir/Chart.yaml"; then
|
|
118
|
+
charts_check_wrapper "$dir" "$name"
|
|
119
|
+
else
|
|
120
|
+
charts_check_templates "$dir" "$name"
|
|
121
|
+
charts_check_values "$dir" "$name"
|
|
122
|
+
fi
|
|
123
|
+
charts_check_helm "$dir" "$name"
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
# Each charts/devzone-<x> named by the code must be a folder of CHARTS_DIR;
|
|
127
|
+
# $svc or $app (variables) are not names and do not match
|
|
128
|
+
charts_check_references() {
|
|
129
|
+
local dir hits hit file name
|
|
130
|
+
for dir in $CHARTS_CODE_DIRS; do
|
|
131
|
+
[ -d "$dir" ] || continue
|
|
132
|
+
hits="$(grep -rnoE 'charts/devzone-[a-z0-9-]+' "$dir" 2>/dev/null)" || hits=""
|
|
133
|
+
while IFS= read -r hit; do
|
|
134
|
+
[ -n "$hit" ] || continue
|
|
135
|
+
file="${hit%%:*}"
|
|
136
|
+
name="${hit##*charts/}"
|
|
137
|
+
if [ ! -d "$CHARTS_DIR/$name" ]; then
|
|
138
|
+
fault "$name" "named in $file but the folder is absent"
|
|
139
|
+
fi
|
|
140
|
+
done <<EOF
|
|
141
|
+
$hits
|
|
142
|
+
EOF
|
|
143
|
+
done
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
if [ ! -d "$CHARTS_DIR" ]; then
|
|
147
|
+
echo "✖ charts : folder not found: $CHARTS_DIR"
|
|
148
|
+
exit 1
|
|
149
|
+
fi
|
|
150
|
+
for dir in "$CHARTS_DIR"/*/; do
|
|
151
|
+
[ -d "$dir" ] || continue
|
|
152
|
+
charts_check_dir "${dir%/}"
|
|
153
|
+
done
|
|
154
|
+
charts_check_references
|
|
155
|
+
if [ "$FAULTS" -ne 0 ]; then
|
|
156
|
+
exit 1
|
|
157
|
+
fi
|
|
158
|
+
echo "✔ charts : $COUNT charts conformes"
|
|
@@ -1,31 +1,75 @@
|
|
|
1
1
|
#!/usr/bin/env bash
|
|
2
|
-
# Shared check of the Kubernetes cluster (#497), sourced by poste.sh
|
|
3
|
-
# create-mode.sh
|
|
4
|
-
# Compatible with bash 3.2 (macOS) and Linux.
|
|
2
|
+
# Shared check of the Kubernetes cluster (#497, #565), sourced by poste.sh,
|
|
3
|
+
# create-mode.sh (creation) and workspace.sh (workspace start). Sourced only:
|
|
4
|
+
# no code at file level. Compatible with bash 3.2 (macOS) and Linux.
|
|
5
5
|
|
|
6
6
|
# Returns 0 when kubectl and helm are present and the cluster answers within 5 s
|
|
7
7
|
# (context devzone if declared, otherwise the current context). Otherwise
|
|
8
8
|
# prints one short line on stdout (kubectl missing, helm missing, or
|
|
9
|
-
# cluster <context> unreachable (<server>)) and returns 1.
|
|
9
|
+
# cluster <context> unreachable (<server>)) and returns 1. With --hint, prints
|
|
10
|
+
# the message for the user instead (#565, see kube_unreachable_hint).
|
|
10
11
|
kube_ready_reason() {
|
|
11
|
-
local context server
|
|
12
|
+
local context server hint=no
|
|
13
|
+
[ "${1:-}" = --hint ] && hint=yes
|
|
12
14
|
command -v kubectl >/dev/null 2>&1 || {
|
|
13
|
-
|
|
15
|
+
kube_say "kubectl missing" "$hint"
|
|
14
16
|
return 1
|
|
15
17
|
}
|
|
16
18
|
command -v helm >/dev/null 2>&1 || {
|
|
17
|
-
|
|
19
|
+
kube_say "helm missing" "$hint"
|
|
18
20
|
return 1
|
|
19
21
|
}
|
|
20
22
|
if kubectl config get-contexts -o name 2>/dev/null | grep -qx 'devzone'; then
|
|
21
23
|
kubectl cluster-info --request-timeout=5s --context devzone >/dev/null 2>&1 && return 0
|
|
22
24
|
context=devzone
|
|
23
|
-
server="$(kubectl config view --minify --context devzone -o 'jsonpath={.clusters[0].server}' 2>/dev/null || true)"
|
|
25
|
+
server="$(kubectl config view --minify --context devzone -o 'jsonpath={.clusters[0].cluster.server}' 2>/dev/null || true)"
|
|
24
26
|
else
|
|
25
27
|
kubectl cluster-info --request-timeout=5s >/dev/null 2>&1 && return 0
|
|
26
28
|
context="$(kubectl config current-context 2>/dev/null || true)"
|
|
27
|
-
server="$(kubectl config view --minify -o 'jsonpath={.clusters[0].server}' 2>/dev/null || true)"
|
|
29
|
+
server="$(kubectl config view --minify -o 'jsonpath={.clusters[0].cluster.server}' 2>/dev/null || true)"
|
|
30
|
+
fi
|
|
31
|
+
if [ "$hint" = yes ]; then
|
|
32
|
+
kube_unreachable_hint "${context:-none}" "${server:-unknown server}"
|
|
33
|
+
else
|
|
34
|
+
echo "cluster ${context:-none} unreachable (${server:-unknown server})"
|
|
28
35
|
fi
|
|
29
|
-
echo "cluster ${context:-none} unreachable (${server:-unknown server})"
|
|
30
36
|
return 1
|
|
31
37
|
}
|
|
38
|
+
|
|
39
|
+
# One reason line: as is, or as a ✖ line for the user (--hint).
|
|
40
|
+
kube_say() {
|
|
41
|
+
if [ "$2" = yes ]; then
|
|
42
|
+
echo "✖ $1"
|
|
43
|
+
else
|
|
44
|
+
echo "$1"
|
|
45
|
+
fi
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
# Cluster name of a context (empty when unknown).
|
|
49
|
+
kube_context_cluster() {
|
|
50
|
+
kubectl config view --minify --context "$1" -o 'jsonpath={.clusters[0].name}' 2>/dev/null || true
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
# Message of an unreachable cluster <context> at <server> (#565). The cluster of
|
|
54
|
+
# Docker Desktop (context docker-desktop, or a local server 127.0.0.1 or
|
|
55
|
+
# localhost of a cluster named docker-desktop) runs inside Docker Desktop: when
|
|
56
|
+
# docker info fails, the cause is Docker Desktop stopped; when Docker answers,
|
|
57
|
+
# Kubernetes is disabled in it. Any other context gets the generic message.
|
|
58
|
+
kube_unreachable_hint() {
|
|
59
|
+
local context="$1" server="$2" cluster host
|
|
60
|
+
cluster="$(kube_context_cluster "$context")"
|
|
61
|
+
host="${server#*://}"
|
|
62
|
+
host="${host%%[:/]*}"
|
|
63
|
+
if [ "$context" = docker-desktop ] ||
|
|
64
|
+
{ [ "$cluster" = docker-desktop ] && { [ "$host" = 127.0.0.1 ] || [ "$host" = localhost ]; }; }; then
|
|
65
|
+
if ! docker info >/dev/null 2>&1; then
|
|
66
|
+
echo "✖ Docker Desktop is stopped: the Kubernetes cluster of this machine runs inside it. Start Docker Desktop, then: make shell"
|
|
67
|
+
echo " Tip: Settings → General → Start Docker Desktop when you sign in"
|
|
68
|
+
else
|
|
69
|
+
echo "✖ Kubernetes cluster $context unreachable ($server): enable Kubernetes in Docker Desktop (Settings → Kubernetes) or check kubectl config get-contexts"
|
|
70
|
+
fi
|
|
71
|
+
return 0
|
|
72
|
+
fi
|
|
73
|
+
echo "✖ Kubernetes cluster $context unreachable ($server)"
|
|
74
|
+
echo " Check the contexts: kubectl config get-contexts"
|
|
75
|
+
}
|
package/manage/workspace.sh
CHANGED
|
@@ -48,9 +48,10 @@ default_image_tag() {
|
|
|
48
48
|
fi
|
|
49
49
|
}
|
|
50
50
|
|
|
51
|
-
# Installs or upgrades the workspace in the cluster.
|
|
51
|
+
# Installs or upgrades the workspace in the cluster; the cluster is checked first (#565): no Argo CD, helm or pod wait for a stopped one.
|
|
52
52
|
start_workspace() {
|
|
53
53
|
local repo tag image with_image="" args=()
|
|
54
|
+
kube_ready_reason --hint >&2 || return 1
|
|
54
55
|
repo="$IMAGE_REPO"
|
|
55
56
|
tag="$(default_image_tag)"
|
|
56
57
|
while [ $# -gt 0 ]; do
|
|
@@ -172,6 +173,8 @@ copy_from() {
|
|
|
172
173
|
# French names of the command and compatibility aliases (lot 3, #508)
|
|
173
174
|
# shellcheck source=manage/scripts/workspace-aliases.sh
|
|
174
175
|
. "$HERE/scripts/workspace-aliases.sh"
|
|
176
|
+
# shellcheck source=manage/scripts/kube-ready.sh
|
|
177
|
+
. "$HERE/scripts/kube-ready.sh"
|
|
175
178
|
# shellcheck source=manage/scripts/workspace-wait.sh
|
|
176
179
|
. "$HERE/scripts/workspace-wait.sh"
|
|
177
180
|
# shellcheck source=manage/scripts/workspace-clone.sh
|