devzone 2.0.0 → 4.0.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/agent-errors.sh +6 -6
- package/.devcontainer/agent-pod-manifest.sh +4 -4
- package/.devcontainer/agent-session.sh +2 -2
- package/.devcontainer/agent-state-json.sh +2 -2
- package/.devcontainer/agent-workspace.sh +1 -1
- package/.devcontainer/agent.sh +7 -7
- package/.devcontainer/ai/host-models.sh +2 -2
- package/.devcontainer/ai/plugins/devzone-guard-v2.js +3 -3
- package/.devcontainer/ai/plugins/devzone-guard.js +3 -3
- package/.devcontainer/argocd/argocd.sh +90 -89
- package/.devcontainer/argocd/catalog-argocd.sh +2 -2
- package/.devcontainer/argocd/services-hook.sh +3 -3
- package/.devcontainer/argocd/services.sh +1 -1
- package/.devcontainer/catalog/app.sh +114 -116
- package/.devcontainer/catalog/catalog-watcher.sh +62 -62
- package/.devcontainer/catalog/mysql/app.conf +1 -1
- package/.devcontainer/catalog/mysql/install.sh +40 -40
- package/.devcontainer/catalog/mysql/mysql.sh +141 -141
- package/.devcontainer/catalog/mysql/volume.sh +39 -39
- package/.devcontainer/catalog.sh +112 -112
- package/.devcontainer/chart-direct.sh +1 -1
- package/.devcontainer/cluster.sh +216 -218
- package/.devcontainer/clusters.sh +41 -41
- package/.devcontainer/command-aliases.sh +17 -8
- package/.devcontainer/devzone +93 -1496
- package/.devcontainer/devzone-ai-guard.sh +76 -0
- package/.devcontainer/devzone-ai.sh +201 -0
- package/.devcontainer/devzone-cluster.sh +210 -0
- package/.devcontainer/devzone-modules.sh +126 -0
- package/.devcontainer/devzone-platform.sh +189 -0
- package/.devcontainer/devzone-repair.sh +94 -0
- package/.devcontainer/devzone-services.sh +241 -0
- package/.devcontainer/devzone-skill.sh +97 -0
- package/.devcontainer/devzone-status.sh +140 -0
- package/.devcontainer/devzone-version.sh +78 -0
- package/.devcontainer/git-identity.sh +28 -0
- package/.devcontainer/gitlab/chart.sh +2 -2
- package/.devcontainer/gitlab/gitlab.sh +81 -82
- package/.devcontainer/gitlab/installation.sh +109 -109
- package/.devcontainer/gitlab/secrets.sh +47 -47
- package/.devcontainer/gitlab/seed.sh +77 -77
- package/.devcontainer/gitlab/test-gitlab.sh +242 -243
- package/.devcontainer/help.sh +1 -1
- package/.devcontainer/isolation.sh +30 -30
- package/.devcontainer/kind-wrapper.sh +17 -17
- package/.devcontainer/kube-account.sh +112 -113
- package/.devcontainer/kube-config.sh +45 -46
- package/.devcontainer/{invite-kube.sh → kube-prompt.sh} +6 -6
- package/.devcontainer/kube-reachable.sh +40 -40
- package/.devcontainer/memory.sh +1 -1
- package/.devcontainer/metrics-server.sh +2 -2
- package/.devcontainer/opencode.jsonc +2 -2
- package/.devcontainer/packages.sh +136 -135
- package/.devcontainer/password.sh +1 -1
- package/.devcontainer/ports-auto.sh +152 -153
- package/.devcontainer/ports-json.sh +16 -15
- package/.devcontainer/ports.sh +126 -122
- package/.devcontainer/post-create.sh +52 -52
- package/.devcontainer/postgres/postgres.sh +174 -174
- package/.devcontainer/rename-legacy-files.sh +103 -0
- package/.devcontainer/services-admin.sh +3 -3
- package/.devcontainer/skills/devzone/SKILL.md +40 -41
- package/.devcontainer/startup.sh +48 -49
- package/.devcontainer/state-gitops.sh +1 -1
- package/.devcontainer/state-json.sh +36 -62
- package/.devcontainer/state.sh +2 -2
- package/.devcontainer/workspace-init.sh +16 -2
- package/Makefile +1 -1
- package/README.md +191 -195
- package/charts/devzone-workspace/templates/statefulset.yaml +1 -1
- package/manage/devzone +7 -11
- package/manage/scripts/argocd-workspace.sh +1 -1
- package/manage/scripts/{check-charts.sh → ci/check-charts.sh} +1 -1
- package/manage/scripts/{check-english.sh → ci/check-english.sh} +1 -1
- package/manage/scripts/{check-go-layout.sh → ci/check-go-layout.sh} +1 -1
- package/manage/scripts/{check-names.sh → ci/check-names.sh} +7 -6
- package/manage/scripts/{check-utf8-vars.sh → ci/check-utf8-vars.sh} +1 -1
- package/manage/scripts/{versions.sh → ci/versions.sh} +8 -8
- package/manage/scripts/create-cluster.sh +1 -1
- package/manage/scripts/create-mode.sh +11 -18
- package/manage/scripts/devzone-create.sh +7 -35
- package/manage/scripts/devzone-manifest.sh +1 -1
- package/manage/scripts/devzone-update.sh +12 -8
- package/manage/scripts/launch.sh +7 -48
- package/manage/scripts/ports-apps.sh +1 -1
- package/manage/scripts/ports-workspace.sh +7 -7
- package/manage/scripts/poste.sh +6 -7
- package/manage/scripts/uninstall.sh +8 -8
- package/manage/scripts/workspace-egress.sh +2 -2
- package/manage/scripts/workspace-update.sh +5 -2
- package/manage/scripts/workspace-wait.sh +2 -2
- package/manage/workspace.sh +2 -12
- package/package.json +1 -1
- package/.devcontainer/docker-relay.sh +0 -149
- package/.devcontainer/docker-without-host.sh +0 -12
- package/.devcontainer/git-identite.sh +0 -28
- package/manage/scripts/docker-workstation.sh +0 -73
- package/manage/scripts/migrate-revert.sh +0 -60
- package/manage/scripts/migrate.sh +0 -243
- /package/manage/scripts/{ci-dns.sh → ci/ci-dns.sh} +0 -0
package/.devcontainer/help.sh
CHANGED
|
@@ -13,7 +13,7 @@ devzone_aide() {
|
|
|
13
13
|
devzone enable <module> enable and apply at once
|
|
14
14
|
devzone disable <module> [--yes] disable and apply at once (--yes: also deletes the data)
|
|
15
15
|
devzone apply install what is enabled (post-create.sh)
|
|
16
|
-
devzone repair repair
|
|
16
|
+
devzone repair repair gitlab, postgres, ports, passwords
|
|
17
17
|
devzone start full start (startup scripts and summary)
|
|
18
18
|
devzone metrics [context…] install metrics-server (kubectl top, k9s)
|
|
19
19
|
devzone use CTX [--confirm CTX] switch the kubectl working cluster
|
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
#!/usr/bin/env bash
|
|
2
|
-
#
|
|
3
|
-
#
|
|
4
|
-
#
|
|
5
|
-
#
|
|
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
|
+
# Helpers of manage/test/commun.bash: kube_isole.
|
|
6
6
|
|
|
7
|
-
#
|
|
8
|
-
#
|
|
9
|
-
|
|
7
|
+
# Sets an isolating NetworkPolicy in a namespace.
|
|
8
|
+
# Only the pods of the same namespace can reach the services.
|
|
9
|
+
namespace_isolate() {
|
|
10
10
|
local ns="${1:-}"
|
|
11
|
-
[ -n "$ns" ] || { echo "devzone : namespace
|
|
11
|
+
[ -n "$ns" ] || { echo "devzone : namespace missing" >&2; return 2; }
|
|
12
12
|
|
|
13
13
|
kubectl --context devzone -n "$ns" apply -f - <<EOF
|
|
14
14
|
apiVersion: networking.k8s.io/v1
|
|
@@ -25,41 +25,41 @@ spec:
|
|
|
25
25
|
EOF
|
|
26
26
|
}
|
|
27
27
|
|
|
28
|
-
#
|
|
29
|
-
#
|
|
30
|
-
#
|
|
31
|
-
#
|
|
32
|
-
|
|
33
|
-
local
|
|
34
|
-
[ -n "$
|
|
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
35
|
|
|
36
|
-
kubectl --context devzone -n "$
|
|
37
|
-
-o yaml 2>/dev/null | kubectl --context devzone -n "$
|
|
38
|
-
{ echo "devzone :
|
|
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
39
|
|
|
40
40
|
patch="$(jq -nc '{"spec":{"ingress":[{"from":[{"podSelector":{},
|
|
41
41
|
"namespaceSelector":{"matchLabels":{"app.kubernetes.io/managed-by":"devzone"}}}]}]}}')"
|
|
42
|
-
if !
|
|
42
|
+
if ! output="$(kubectl --context devzone -n "$target_ns" patch networkpolicy devzone-meme-namespace \
|
|
43
43
|
-p "$patch" 2>&1)"; then
|
|
44
|
-
echo "devzone :
|
|
44
|
+
echo "devzone : cannot allow access to $target_ns : $output" >&2
|
|
45
45
|
return 1
|
|
46
46
|
fi
|
|
47
47
|
|
|
48
|
-
echo "devzone :
|
|
48
|
+
echo "devzone : rule allowed to $target_ns"
|
|
49
49
|
}
|
|
50
50
|
|
|
51
|
-
#
|
|
52
|
-
#
|
|
53
|
-
|
|
54
|
-
local
|
|
55
|
-
[ -n "$
|
|
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
56
|
|
|
57
57
|
patch="$(jq -nc '{"spec":{"ingress":[{"from":[{"podSelector":{}}]}]}}')"
|
|
58
|
-
if !
|
|
58
|
+
if ! output="$(kubectl --context devzone -n "$target_ns" patch networkpolicy devzone-meme-namespace \
|
|
59
59
|
-p "$patch" 2>&1)"; then
|
|
60
|
-
echo "devzone :
|
|
60
|
+
echo "devzone : cannot forbid access to $target_ns : $output" >&2
|
|
61
61
|
return 1
|
|
62
62
|
fi
|
|
63
63
|
|
|
64
|
-
echo "devzone :
|
|
65
|
-
}
|
|
64
|
+
echo "devzone : rule forbidden to $target_ns"
|
|
65
|
+
}
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
#!/usr/bin/env bash
|
|
2
|
-
#
|
|
3
|
-
#
|
|
4
|
-
#
|
|
5
|
-
#
|
|
6
|
-
#
|
|
2
|
+
# kind wrapper (#291), installed as /usr/local/bin/kind; the real binary is
|
|
3
|
+
# kind-reel. With the host's Docker, a cluster created by « kind create cluster »
|
|
4
|
+
# writes server: https://127.0.0.1:<port>: unreachable from the container. After
|
|
5
|
+
# a successful creation or kubeconfig export, the address is made reachable
|
|
6
|
+
# (kube-reachable.sh). Everything else passes through unchanged.
|
|
7
7
|
set -uo pipefail
|
|
8
8
|
|
|
9
|
-
KIND_REEL="${
|
|
9
|
+
KIND_REEL="${DEVZONE_KIND_REAL:-/usr/local/bin/kind-reel}"
|
|
10
10
|
ICI="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
|
11
11
|
if [ -f "$ICI/kube-reachable.sh" ]; then
|
|
12
12
|
# shellcheck source=SCRIPTDIR/kube-reachable.sh
|
|
@@ -25,21 +25,21 @@ case "${1:-} ${2:-}" in
|
|
|
25
25
|
*) exit 0 ;;
|
|
26
26
|
esac
|
|
27
27
|
|
|
28
|
-
#
|
|
29
|
-
#
|
|
30
|
-
|
|
31
|
-
|
|
28
|
+
# File written by kind: --kubeconfig if given, otherwise the first of KUBECONFIG,
|
|
29
|
+
# otherwise ~/.kube/config (same rule as kind)
|
|
30
|
+
file=""
|
|
31
|
+
previous=""
|
|
32
32
|
for arg in "$@"; do
|
|
33
33
|
case "$arg" in
|
|
34
|
-
--kubeconfig=*)
|
|
34
|
+
--kubeconfig=*) file="${arg#--kubeconfig=}" ;;
|
|
35
35
|
esac
|
|
36
|
-
[ "$
|
|
37
|
-
|
|
36
|
+
[ "$previous" = "--kubeconfig" ] && file="$arg"
|
|
37
|
+
previous="$arg"
|
|
38
38
|
done
|
|
39
|
-
if [ -z "$
|
|
40
|
-
|
|
39
|
+
if [ -z "$file" ] && [ -n "${KUBECONFIG:-}" ]; then
|
|
40
|
+
file="${KUBECONFIG%%:*}"
|
|
41
41
|
fi
|
|
42
|
-
[ -n "$
|
|
42
|
+
[ -n "$file" ] || file="$HOME/.kube/config"
|
|
43
43
|
|
|
44
|
-
|
|
44
|
+
kube_reachable_from_container "$file"
|
|
45
45
|
exit 0
|
|
@@ -1,44 +1,43 @@
|
|
|
1
1
|
#!/usr/bin/env bash
|
|
2
|
-
#
|
|
3
|
-
# agents)
|
|
4
|
-
# ServiceAccount devzone-agent
|
|
5
|
-
# edit (
|
|
6
|
-
#
|
|
7
|
-
#
|
|
8
|
-
#
|
|
9
|
-
#
|
|
10
|
-
#
|
|
11
|
-
# kube-account.sh jeton
|
|
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, with a 24 h TokenRequest token renewed at startup (startup.sh) and
|
|
7
|
+
# by « devzone repair ». The installers alone use the admin context (host context
|
|
8
|
+
# in ~/.kube/hote.config, kind cluster in ~/.kube/config); shells and agents only
|
|
9
|
+
# have ~/.kube/config.
|
|
10
|
+
# Library sourced by cluster.sh; executable for the token:
|
|
11
|
+
# kube-account.sh jeton (argument kept: called by startup.sh and devzone repair)
|
|
12
12
|
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
13
|
+
ACCOUNT_NS=devzone-system
|
|
14
|
+
ACCOUNT_SA=devzone-agent
|
|
15
|
+
ACCOUNT_DURATION=24h
|
|
16
|
+
ACCOUNT_CONFIG="${DEVZONE_KUBE_CONFIG:-$HOME/.kube/config}"
|
|
17
17
|
|
|
18
|
-
#
|
|
19
|
-
#
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
echo "$hote"
|
|
18
|
+
# kubeconfig file that holds the admin context ctx: hote.config if it lists it
|
|
19
|
+
# (host clusters), otherwise ~/.kube/config (kind clusters of the container).
|
|
20
|
+
account_admin_config() {
|
|
21
|
+
local ctx="$1" host="${DEVZONE_KUBE_HOST:-$HOME/.kube/hote.config}"
|
|
22
|
+
if [ -n "$ctx" ] && [ -f "$host" ]; then
|
|
23
|
+
if KUBECONFIG="$host" kubectl config get-contexts -o name 2>/dev/null | grep -qx -- "$ctx"; then
|
|
24
|
+
echo "$host"
|
|
26
25
|
return 0
|
|
27
26
|
fi
|
|
28
27
|
fi
|
|
29
|
-
echo "$
|
|
28
|
+
echo "$ACCOUNT_CONFIG"
|
|
30
29
|
}
|
|
31
30
|
|
|
32
|
-
# kubectl
|
|
33
|
-
#
|
|
34
|
-
#
|
|
35
|
-
|
|
31
|
+
# kubectl on the admin context: explicit kubeconfig that holds this context,
|
|
32
|
+
# never the combined KUBECONFIG (the admin never goes through the limited
|
|
33
|
+
# account). Without a known context: the one kubectl uses.
|
|
34
|
+
account_admin() {
|
|
36
35
|
local ctx="$1" conf
|
|
37
36
|
shift
|
|
38
37
|
if [ -z "$ctx" ]; then
|
|
39
38
|
ctx="$(kubectl config current-context 2>/dev/null || true)"
|
|
40
39
|
fi
|
|
41
|
-
conf="$(
|
|
40
|
+
conf="$(account_admin_config "$ctx")"
|
|
42
41
|
if [ -n "$ctx" ]; then
|
|
43
42
|
kubectl --kubeconfig="$conf" --context "$ctx" "$@"
|
|
44
43
|
else
|
|
@@ -46,16 +45,16 @@ compte_admin() {
|
|
|
46
45
|
fi
|
|
47
46
|
}
|
|
48
47
|
|
|
49
|
-
# helm
|
|
50
|
-
#
|
|
51
|
-
# Usage
|
|
52
|
-
|
|
48
|
+
# helm on the admin context ctx: the charts create CRDs, ClusterRoles or
|
|
49
|
+
# RoleBindings, beyond the limited account's rights (edit).
|
|
50
|
+
# Usage: account_helm <ctx> <helm args…>
|
|
51
|
+
account_helm() {
|
|
53
52
|
local ctx="$1" conf
|
|
54
53
|
shift
|
|
55
54
|
if [ -z "$ctx" ]; then
|
|
56
55
|
ctx="$(kubectl config current-context 2>/dev/null || true)"
|
|
57
56
|
fi
|
|
58
|
-
conf="$(
|
|
57
|
+
conf="$(account_admin_config "$ctx")"
|
|
59
58
|
if [ -n "$ctx" ]; then
|
|
60
59
|
helm --kubeconfig "$conf" --kube-context "$ctx" "$@"
|
|
61
60
|
else
|
|
@@ -63,11 +62,11 @@ compte_helm() {
|
|
|
63
62
|
fi
|
|
64
63
|
}
|
|
65
64
|
|
|
66
|
-
#
|
|
67
|
-
#
|
|
68
|
-
|
|
65
|
+
# Admin context of an installation: the chosen services cluster (cluster_saved
|
|
66
|
+
# of cluster.sh), otherwise the current kubectl context.
|
|
67
|
+
account_context() {
|
|
69
68
|
local ctx
|
|
70
|
-
ctx="$(
|
|
69
|
+
ctx="$(cluster_saved 2>/dev/null || true)"
|
|
71
70
|
if [ -n "$ctx" ]; then
|
|
72
71
|
echo "$ctx"
|
|
73
72
|
return 0
|
|
@@ -75,126 +74,126 @@ compte_ctx() {
|
|
|
75
74
|
kubectl config current-context 2>/dev/null || true
|
|
76
75
|
}
|
|
77
76
|
|
|
78
|
-
#
|
|
79
|
-
# devzone-
|
|
80
|
-
#
|
|
81
|
-
|
|
77
|
+
# Sets up the limited account with the admin context: devzone-system namespace
|
|
78
|
+
# and devzone-agent ServiceAccount (idempotent, resumed at startup and at each
|
|
79
|
+
# installation).
|
|
80
|
+
account_setup() {
|
|
82
81
|
local ctx="$1"
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
--dry-run=client -o yaml |
|
|
82
|
+
account_admin "$ctx" create namespace "$ACCOUNT_NS" --dry-run=client -o yaml |
|
|
83
|
+
account_admin "$ctx" apply -f - >/dev/null || return 1
|
|
84
|
+
account_admin "$ctx" -n "$ACCOUNT_NS" create serviceaccount "$ACCOUNT_SA" \
|
|
85
|
+
--dry-run=client -o yaml | account_admin "$ctx" apply -f - >/dev/null || return 1
|
|
87
86
|
}
|
|
88
87
|
|
|
89
|
-
#
|
|
90
|
-
# ClusterRole
|
|
91
|
-
#
|
|
92
|
-
#
|
|
93
|
-
#
|
|
94
|
-
|
|
88
|
+
# Allows the account in namespace ns: devzone-agent RoleBinding to the edit
|
|
89
|
+
# ClusterRole (read, write, secrets, NetworkPolicies — no RBAC, no quotas), set
|
|
90
|
+
# with the admin context after the namespace is created.
|
|
91
|
+
# The account is set up first if missing: an installation on a still blank
|
|
92
|
+
# cluster makes the account usable at the next token renewal.
|
|
93
|
+
account_allow() {
|
|
95
94
|
local ctx="$1" ns="$2"
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
--clusterrole=edit --serviceaccount="$
|
|
99
|
-
--dry-run=client -o yaml |
|
|
95
|
+
account_setup "$ctx" || return 1
|
|
96
|
+
account_admin "$ctx" -n "$ns" create rolebinding "$ACCOUNT_SA" \
|
|
97
|
+
--clusterrole=edit --serviceaccount="$ACCOUNT_NS:$ACCOUNT_SA" \
|
|
98
|
+
--dry-run=client -o yaml | account_admin "$ctx" apply -f - >/dev/null || return 1
|
|
100
99
|
}
|
|
101
100
|
|
|
102
|
-
#
|
|
103
|
-
#
|
|
104
|
-
|
|
101
|
+
# Removes the account's permission in namespace ns (uninstall): RoleBinding
|
|
102
|
+
# deleted with the admin context.
|
|
103
|
+
account_remove() {
|
|
105
104
|
local ctx="$1" ns="$2"
|
|
106
|
-
|
|
105
|
+
account_admin "$ctx" -n "$ns" delete rolebinding "$ACCOUNT_SA" \
|
|
107
106
|
--ignore-not-found >/dev/null || return 1
|
|
108
107
|
}
|
|
109
108
|
|
|
110
|
-
#
|
|
111
|
-
|
|
109
|
+
# Creates and labels namespace ns as administrator, then allows the account.
|
|
110
|
+
account_namespace() {
|
|
112
111
|
local ctx="$1" ns="$2"
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
112
|
+
account_admin "$ctx" create namespace "$ns" --dry-run=client -o yaml |
|
|
113
|
+
account_admin "$ctx" apply -f - >/dev/null || return 1
|
|
114
|
+
account_admin "$ctx" label namespace "$ns" "$CLUSTER_LABEL" --overwrite >/dev/null || return 1
|
|
115
|
+
account_allow "$ctx" "$ns" || return 1
|
|
117
116
|
}
|
|
118
117
|
|
|
119
|
-
#
|
|
120
|
-
#
|
|
121
|
-
#
|
|
122
|
-
|
|
123
|
-
local ctx="$1" ns
|
|
118
|
+
# Catches up the existing devzone namespaces: RoleBinding set in each namespace
|
|
119
|
+
# labelled CLUSTER_LABEL (idempotent), for the installations prior to the
|
|
120
|
+
# limited account.
|
|
121
|
+
account_catch_up() {
|
|
122
|
+
local ctx="$1" ns label="${CLUSTER_LABEL:-app.kubernetes.io/managed-by=devzone}"
|
|
124
123
|
while IFS= read -r ns; do
|
|
125
124
|
[ -n "$ns" ] || continue
|
|
126
125
|
ns="${ns#namespace/}"
|
|
127
|
-
|
|
128
|
-
--clusterrole=edit --serviceaccount="$
|
|
129
|
-
--dry-run=client -o yaml |
|
|
130
|
-
done < <(
|
|
126
|
+
account_admin "$ctx" -n "$ns" create rolebinding "$ACCOUNT_SA" \
|
|
127
|
+
--clusterrole=edit --serviceaccount="$ACCOUNT_NS:$ACCOUNT_SA" \
|
|
128
|
+
--dry-run=client -o yaml | account_admin "$ctx" apply -f - >/dev/null || return 1
|
|
129
|
+
done < <(account_admin "$ctx" get namespaces -l "$label" -o name 2>/dev/null || true)
|
|
131
130
|
}
|
|
132
131
|
|
|
133
|
-
#
|
|
134
|
-
#
|
|
135
|
-
#
|
|
136
|
-
#
|
|
137
|
-
|
|
138
|
-
local ctx="$1" conf
|
|
139
|
-
local
|
|
140
|
-
conf="$(
|
|
141
|
-
|
|
142
|
-
--duration="$
|
|
143
|
-
if [ -z "$
|
|
144
|
-
echo "devzone :
|
|
132
|
+
# Renews the account's token (24 h TokenRequest) and writes it into the devzone
|
|
133
|
+
# context of ~/.kube/config: user devzone-agent, same cluster as the admin
|
|
134
|
+
# context (cluster entry copied: server, certificate authority and
|
|
135
|
+
# tls-server-name of the host context).
|
|
136
|
+
account_token() {
|
|
137
|
+
local ctx="$1" conf token cluster server tls ca_data ca_file
|
|
138
|
+
local entry=()
|
|
139
|
+
conf="$(account_admin_config "$ctx")"
|
|
140
|
+
token="$(account_admin "$ctx" create token "$ACCOUNT_SA" -n "$ACCOUNT_NS" \
|
|
141
|
+
--duration="$ACCOUNT_DURATION")" || return 1
|
|
142
|
+
if [ -z "$token" ]; then
|
|
143
|
+
echo "devzone : limited account token is empty" >&2
|
|
145
144
|
return 1
|
|
146
145
|
fi
|
|
147
146
|
cluster="$(KUBECONFIG="$conf" kubectl config view \
|
|
148
147
|
-o jsonpath="{.contexts[?(@.name==\"$ctx\")].context.cluster}" 2>/dev/null || true)"
|
|
149
148
|
if [ -z "$cluster" ]; then
|
|
150
|
-
echo "devzone : cluster
|
|
149
|
+
echo "devzone : cluster of context $ctx not found in $conf" >&2
|
|
151
150
|
return 1
|
|
152
151
|
fi
|
|
153
|
-
|
|
152
|
+
server="$(KUBECONFIG="$conf" kubectl config view \
|
|
154
153
|
-o jsonpath="{.clusters[?(@.name==\"$cluster\")].cluster.server}" 2>/dev/null || true)"
|
|
155
|
-
if [ -z "$
|
|
156
|
-
echo "devzone :
|
|
154
|
+
if [ -z "$server" ]; then
|
|
155
|
+
echo "devzone : server of cluster $cluster not found in $conf" >&2
|
|
157
156
|
return 1
|
|
158
157
|
fi
|
|
159
|
-
|
|
158
|
+
ca_data="$(KUBECONFIG="$conf" kubectl config view \
|
|
160
159
|
-o jsonpath="{.clusters[?(@.name==\"$cluster\")].cluster.certificate-authority-data}" 2>/dev/null || true)"
|
|
161
|
-
|
|
160
|
+
ca_file="$(KUBECONFIG="$conf" kubectl config view \
|
|
162
161
|
-o jsonpath="{.clusters[?(@.name==\"$cluster\")].cluster.certificate-authority}" 2>/dev/null || true)"
|
|
163
|
-
|
|
164
|
-
if [ -n "$
|
|
165
|
-
|
|
166
|
-
elif [ -n "$
|
|
167
|
-
|
|
162
|
+
entry=(--server="$server")
|
|
163
|
+
if [ -n "$ca_data" ]; then
|
|
164
|
+
entry+=(--certificate-authority-data="$ca_data")
|
|
165
|
+
elif [ -n "$ca_file" ]; then
|
|
166
|
+
entry+=(--certificate-authority="$ca_file" --embed-certs=true)
|
|
168
167
|
fi
|
|
169
168
|
tls="$(KUBECONFIG="$conf" kubectl config view \
|
|
170
169
|
-o jsonpath="{.clusters[?(@.name==\"$cluster\")].cluster.tls-server-name}" 2>/dev/null || true)"
|
|
171
170
|
if [ -n "$tls" ]; then
|
|
172
|
-
|
|
171
|
+
entry+=(--tls-server-name="$tls")
|
|
173
172
|
fi
|
|
174
|
-
KUBECONFIG="$
|
|
175
|
-
${
|
|
176
|
-
KUBECONFIG="$
|
|
177
|
-
--token="$
|
|
178
|
-
KUBECONFIG="$
|
|
179
|
-
--cluster="$cluster" --user="$
|
|
173
|
+
KUBECONFIG="$ACCOUNT_CONFIG" kubectl config set-cluster "$cluster" \
|
|
174
|
+
${entry[@]+"${entry[@]}"} >/dev/null
|
|
175
|
+
KUBECONFIG="$ACCOUNT_CONFIG" kubectl config set-credentials "$ACCOUNT_SA" \
|
|
176
|
+
--token="$token" >/dev/null
|
|
177
|
+
KUBECONFIG="$ACCOUNT_CONFIG" kubectl config set-context devzone \
|
|
178
|
+
--cluster="$cluster" --user="$ACCOUNT_SA" >/dev/null
|
|
180
179
|
}
|
|
181
180
|
|
|
182
|
-
#
|
|
183
|
-
#
|
|
184
|
-
#
|
|
181
|
+
# Direct execution: account token renewed at startup (startup.sh) and by
|
|
182
|
+
# « devzone repair ». Without a chosen services cluster: nothing to do.
|
|
183
|
+
# When the file is sourced, $0 differs from BASH_SOURCE: nothing runs.
|
|
185
184
|
if [[ "${BASH_SOURCE[0]}" == "$0" ]]; then
|
|
186
185
|
if [ "${1:-}" != jeton ]; then
|
|
187
|
-
echo "devzone : kube-
|
|
186
|
+
echo "devzone : kube-account : jeton" >&2
|
|
188
187
|
exit 1
|
|
189
188
|
fi
|
|
190
189
|
ICI="$(cd "$(dirname "$0")" && pwd)"
|
|
191
|
-
RACINE="${
|
|
192
|
-
ETAT="${
|
|
190
|
+
RACINE="${DEVZONE_ROOT:-$(dirname "$ICI")}"
|
|
191
|
+
ETAT="${DEVZONE_STATE:-$RACINE/.devzone.modules}"
|
|
193
192
|
ctx="$(grep -E '^cluster=' "$ETAT" 2>/dev/null | tail -1 | cut -d= -f2- || true)"
|
|
194
193
|
if [ -z "$ctx" ]; then
|
|
195
194
|
exit 0
|
|
196
195
|
fi
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
196
|
+
account_setup "$ctx" || exit 1
|
|
197
|
+
account_catch_up "$ctx" || exit 1
|
|
198
|
+
account_token "$ctx" || exit 1
|
|
200
199
|
fi
|
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
#!/usr/bin/env bash
|
|
2
|
-
#
|
|
3
|
-
#
|
|
4
|
-
# - ~/.kube/hote.config
|
|
5
|
-
# 127.0.0.1/localhost
|
|
6
|
-
# tls-server-name
|
|
7
|
-
# - ~/.kube/config
|
|
8
|
-
# KUBECONFIG (devcontainer.json)
|
|
9
|
-
#
|
|
10
|
-
#
|
|
11
|
-
#
|
|
2
|
+
# Kubernetes clusters of the container, at each startup (the port of the host
|
|
3
|
+
# cluster can change):
|
|
4
|
+
# - ~/.kube/hote.config: copy of the host's ~/.kube (mounted read-only) where
|
|
5
|
+
# 127.0.0.1/localhost become host.docker.internal, the host seen from the container;
|
|
6
|
+
# tls-server-name keeps the name expected by the certificate
|
|
7
|
+
# - ~/.kube/config: kind clusters of the container, never touched here
|
|
8
|
+
# KUBECONFIG (devcontainer.json) combines the two.
|
|
9
|
+
# kubernetes module (devzone enable kubernetes): connection to the host cluster
|
|
10
|
+
# and metrics-server only if it is enabled; the kind contexts are always restored
|
|
11
|
+
# (a cluster created by hand stays usable).
|
|
12
12
|
set -euo pipefail
|
|
13
13
|
|
|
14
14
|
ICI="$(dirname "$0")"
|
|
@@ -17,63 +17,62 @@ ICI="$(dirname "$0")"
|
|
|
17
17
|
module=off
|
|
18
18
|
bash "$ICI/devzone" is-enabled kubernetes && module=on
|
|
19
19
|
|
|
20
|
-
# DEVZONE_KUBE_SOURCE
|
|
20
|
+
# DEVZONE_KUBE_SOURCE: functional tests (never the host cluster)
|
|
21
21
|
SOURCE="${DEVZONE_KUBE_SOURCE:-$HOME/.kube-host/config}"
|
|
22
|
-
|
|
22
|
+
HOST_CONFIG="$HOME/.kube/hote.config"
|
|
23
23
|
|
|
24
24
|
mkdir -p "$HOME/.kube"
|
|
25
|
-
rm -f "$
|
|
26
|
-
#
|
|
25
|
+
rm -f "$HOST_CONFIG"
|
|
26
|
+
# Must exist: otherwise kind writes into hote.config, erased at the next startup
|
|
27
27
|
[ -f "$HOME/.kube/config" ] || install -m 600 /dev/null "$HOME/.kube/config"
|
|
28
28
|
|
|
29
29
|
if [ "$module" = on ] && [ -f "$SOURCE" ]; then
|
|
30
|
-
install -m 600 "$SOURCE" "$
|
|
31
|
-
|
|
32
|
-
|
|
30
|
+
install -m 600 "$SOURCE" "$HOST_CONFIG"
|
|
31
|
+
kube_reachable_from_container "$HOST_CONFIG"
|
|
32
|
+
devzone_context_set
|
|
33
33
|
fi
|
|
34
34
|
|
|
35
|
-
#
|
|
36
|
-
#
|
|
37
|
-
|
|
38
|
-
kube_joignable_depuis_conteneur "$HOME/.kube/config"
|
|
35
|
+
# Rewrite 127.0.0.1/localhost → host.docker.internal for the kind clusters, whose
|
|
36
|
+
# API server is at 127.0.0.1:<port> but unreachable from the container. Idempotent.
|
|
37
|
+
kube_reachable_from_container "$HOME/.kube/config"
|
|
39
38
|
|
|
40
|
-
#
|
|
41
|
-
# (
|
|
39
|
+
# kind clusters that survived the restart: context restored in ~/.kube/config
|
|
40
|
+
# (the internal Docker may take a few seconds to start)
|
|
42
41
|
for _ in 1 2 3 4 5 6 7 8 9 10; do docker info >/dev/null 2>&1 && break; sleep 1; done
|
|
43
|
-
|
|
42
|
+
choice="$(KUBECONFIG="$HOME/.kube/config" kubectl config current-context 2>/dev/null || true)"
|
|
44
43
|
for cluster in $(kind get clusters 2>/dev/null); do
|
|
45
44
|
kind export kubeconfig --name "$cluster" --kubeconfig "$HOME/.kube/config" >/dev/null 2>&1 || true
|
|
46
45
|
done
|
|
47
|
-
#
|
|
48
|
-
#
|
|
49
|
-
|
|
46
|
+
# The kubeconfigs exported by kind carry server: https://127.0.0.1:<port>;
|
|
47
|
+
# make them reachable from the container.
|
|
48
|
+
kube_reachable_from_container "$HOME/.kube/config"
|
|
50
49
|
|
|
51
|
-
#
|
|
52
|
-
#
|
|
53
|
-
export KUBECONFIG="$HOME/.kube/config:$
|
|
54
|
-
if [ -n "$
|
|
50
|
+
# Active cluster: the one chosen before (kubectl config use-context), otherwise
|
|
51
|
+
# the host's if it has one (current-context of hote.config), otherwise kind
|
|
52
|
+
export KUBECONFIG="$HOME/.kube/config:$HOST_CONFIG"
|
|
53
|
+
if [ -n "$choice" ] && kubectl config use-context "$choice" >/dev/null 2>&1; then
|
|
55
54
|
:
|
|
56
|
-
elif [ -f "$
|
|
55
|
+
elif [ -f "$HOST_CONFIG" ] && [ -n "$(KUBECONFIG="$HOST_CONFIG" kubectl config current-context 2>/dev/null)" ]; then
|
|
57
56
|
KUBECONFIG="$HOME/.kube/config" kubectl config unset current-context >/dev/null
|
|
58
57
|
fi
|
|
59
58
|
|
|
60
|
-
#
|
|
61
|
-
|
|
62
|
-
for
|
|
63
|
-
if kubectl --context "$
|
|
64
|
-
echo "kube-config : cluster
|
|
65
|
-
|
|
66
|
-
elif [[ "$
|
|
67
|
-
echo "kube-config :
|
|
68
|
-
|
|
59
|
+
# Reachable clusters, among those of the host and those of kind
|
|
60
|
+
reachable=0
|
|
61
|
+
for context in $(kubectl config get-contexts -o name 2>/dev/null); do
|
|
62
|
+
if kubectl --context "$context" --request-timeout=3s get --raw /readyz >/dev/null 2>&1; then
|
|
63
|
+
echo "kube-config : cluster reachable : $context"
|
|
64
|
+
reachable=$((reachable + 1))
|
|
65
|
+
elif [[ "$context" == kind-* ]]; then
|
|
66
|
+
echo "kube-config : kind cluster starting: $context"
|
|
67
|
+
reachable=$((reachable + 1))
|
|
69
68
|
fi
|
|
70
69
|
done
|
|
71
|
-
# Module
|
|
70
|
+
# Module disabled: the devzone summary reports it
|
|
72
71
|
[ "$module" = on ] || exit 0
|
|
73
|
-
echo "kube-config : cluster
|
|
74
|
-
if [ "$
|
|
75
|
-
echo "kube-config :
|
|
72
|
+
echo "kube-config : active cluster: $(kubectl config current-context 2>/dev/null || echo none)"
|
|
73
|
+
if [ "$reachable" -eq 0 ]; then
|
|
74
|
+
echo "kube-config : no reachable cluster; create one in the container: kind create cluster"
|
|
76
75
|
fi
|
|
77
76
|
|
|
78
|
-
# CPU/RAM
|
|
77
|
+
# CPU/RAM in k9s: metrics-server on the reachable clusters that do not have it
|
|
79
78
|
bash "$ICI/metrics-server.sh" || true
|