devzone 0.58.0 → 0.59.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/README.md +1 -1
- package/manage/scripts/create-cluster.sh +107 -0
- package/manage/scripts/create-mode.sh +10 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -133,7 +133,7 @@ devzone mon-devzone
|
|
|
133
133
|
d'avoir un cluster, puis tu relances
|
|
134
134
|
```
|
|
135
135
|
|
|
136
|
-
Sans cluster, devzone s'arrête et affiche des commandes à copier (il ne les exécute jamais, et aucun identifiant cloud ne passe par lui) : un cluster distant (`aws eks update-kubeconfig`, `gcloud container clusters get-credentials`, `az aks get-credentials`, qui le déclarent dans ton kubeconfig ; fais-en le contexte courant de kubectl), ou un cluster local (Docker Desktop : *Settings → Kubernetes → Enable Kubernetes*, ou `minikube start -p devzone`). `devzone mon-devzone --docker` crée encore le poste Docker, **déprécié** : il sera retiré, et `devzone workspace migrate` le fait passer dans le cluster. Détails dans [manage/docs/reference.md](manage/docs/reference.md#création-directe-dans-le-cluster).
|
|
136
|
+
Sans cluster, dans un terminal, devzone propose de choisir un cluster distant (un contexte de ton kubeconfig, dont tu retapes le nom pour confirmer) ou de créer un minikube ; sans terminal, il s'arrête et affiche des commandes à copier (il ne les exécute jamais, et aucun identifiant cloud ne passe par lui) : un cluster distant (`aws eks update-kubeconfig`, `gcloud container clusters get-credentials`, `az aks get-credentials`, qui le déclarent dans ton kubeconfig ; fais-en le contexte courant de kubectl), ou un cluster local (Docker Desktop : *Settings → Kubernetes → Enable Kubernetes*, ou `minikube start -p devzone`). `devzone mon-devzone --docker` crée encore le poste Docker, **déprécié** : il sera retiré, et `devzone workspace migrate` le fait passer dans le cluster. Détails dans [manage/docs/reference.md](manage/docs/reference.md#création-directe-dans-le-cluster).
|
|
137
137
|
|
|
138
138
|
### Vérifier que tout fonctionne
|
|
139
139
|
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
#!/usr/bin/env bash
|
|
2
|
+
# Way out of "no cluster" at creation (#653), sourced by create-mode.sh.
|
|
3
|
+
# In a terminal, a menu: a remote cluster (a context of the kubeconfig, its name
|
|
4
|
+
# typed back to confirm, #326) or a local minikube cluster (profile devzone).
|
|
5
|
+
# Without a terminal nothing is asked: the caller prints the failure (no silent
|
|
6
|
+
# fallback). devzone never runs a cloud command and never installs minikube: it
|
|
7
|
+
# only displays the official command. DEVZONE_TERMINAL=1 forces the terminal
|
|
8
|
+
# mode, the answers then come from stdin (tests). Sourced only. Bash 3.2.
|
|
9
|
+
|
|
10
|
+
# True in a terminal (or forced for the tests).
|
|
11
|
+
create_cluster_terminal() {
|
|
12
|
+
[ -n "${DEVZONE_TERMINAL:-}" ] || [ -t 0 ]
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
# True when the context is a local cluster: never offered as a remote one.
|
|
16
|
+
create_cluster_is_local() {
|
|
17
|
+
local ctx="$1" server
|
|
18
|
+
case "$ctx" in
|
|
19
|
+
docker-desktop | desktop-* | minikube | devzone | rancher-desktop | orbstack | colima | kind-* | k3d-*) return 0 ;;
|
|
20
|
+
esac
|
|
21
|
+
server="$(kubectl config view --minify --context "$ctx" -o 'jsonpath={.clusters[0].cluster.server}' 2>/dev/null || true)"
|
|
22
|
+
case "$server" in
|
|
23
|
+
*//127.0.0.1* | *//localhost* | *//\[::1\]*) return 0 ;;
|
|
24
|
+
esac
|
|
25
|
+
return 1
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
# Remote contexts of the kubeconfig, one per line.
|
|
29
|
+
create_cluster_remote_contexts() {
|
|
30
|
+
local ctx
|
|
31
|
+
kubectl config get-contexts -o name 2>/dev/null | while IFS= read -r ctx; do
|
|
32
|
+
[ -n "$ctx" ] || continue
|
|
33
|
+
create_cluster_is_local "$ctx" || printf '%s\n' "$ctx"
|
|
34
|
+
done
|
|
35
|
+
return 0
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
# Remote cluster: pick a context, type its name back, make it the current one.
|
|
39
|
+
create_cluster_remote() {
|
|
40
|
+
local list answer ctx i=0
|
|
41
|
+
list="$(create_cluster_remote_contexts)"
|
|
42
|
+
if [ -z "$list" ]; then
|
|
43
|
+
echo "✖ no remote context in your kubeconfig: add one with the command of your provider (aws, gcloud, az), then run the same command again" >&2
|
|
44
|
+
return 1
|
|
45
|
+
fi
|
|
46
|
+
echo "Remote contexts of your kubeconfig:"
|
|
47
|
+
while IFS= read -r ctx; do
|
|
48
|
+
i=$((i + 1))
|
|
49
|
+
printf ' %s) %s (remote)\n' "$i" "$ctx"
|
|
50
|
+
done <<<"$list"
|
|
51
|
+
printf 'Number of the cluster (empty to cancel): '
|
|
52
|
+
read -r answer || answer=""
|
|
53
|
+
case "$answer" in
|
|
54
|
+
'' | *[!0-9]*) echo "✖ cancelled" >&2; return 1 ;;
|
|
55
|
+
esac
|
|
56
|
+
ctx="$(printf '%s\n' "$list" | sed -n "${answer}p")"
|
|
57
|
+
[ -n "$ctx" ] || { echo "✖ no such cluster: $answer" >&2; return 1; }
|
|
58
|
+
echo "remote cluster: $ctx. devzone will install a pod, a volume and the namespace devzone-workspace in it: it needs enough rights and may cost."
|
|
59
|
+
printf 'Type its name to confirm: '
|
|
60
|
+
read -r answer || answer=""
|
|
61
|
+
[ "$answer" = "$ctx" ] || { echo "✖ name not typed back: nothing done" >&2; return 1; }
|
|
62
|
+
kubectl config use-context "$ctx" >/dev/null 2>&1 || { echo "✖ cannot select the context $ctx" >&2; return 1; }
|
|
63
|
+
echo "✔ current kubectl context: $ctx"
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
# minikube: displays the official install command when it is missing (never
|
|
67
|
+
# runs it); otherwise creates the profile devzone after a confirmation.
|
|
68
|
+
create_cluster_minikube() {
|
|
69
|
+
local answer
|
|
70
|
+
if ! command -v minikube >/dev/null 2>&1; then
|
|
71
|
+
echo "minikube is not installed. Official command (devzone does not run it):"
|
|
72
|
+
case "$(uname -s)" in
|
|
73
|
+
Darwin) echo " brew install minikube" ;;
|
|
74
|
+
Linux) echo " curl -LO https://storage.googleapis.com/minikube/releases/latest/minikube-linux-amd64 && sudo install minikube-linux-amd64 /usr/local/bin/minikube" ;;
|
|
75
|
+
*) echo " winget install Kubernetes.minikube" ;;
|
|
76
|
+
esac
|
|
77
|
+
echo "Then run the same command again."
|
|
78
|
+
return 1
|
|
79
|
+
fi
|
|
80
|
+
echo "minikube: devzone will run: minikube start -p devzone (profile devzone, driver chosen by minikube)."
|
|
81
|
+
printf 'Create it now? [y/N] '
|
|
82
|
+
read -r answer || answer=""
|
|
83
|
+
case "$answer" in
|
|
84
|
+
y | Y | yes | o | O | oui) ;;
|
|
85
|
+
*) echo "✖ cancelled" >&2; return 1 ;;
|
|
86
|
+
esac
|
|
87
|
+
minikube start -p devzone || { echo "✖ minikube start failed: nothing else done" >&2; return 1; }
|
|
88
|
+
kubectl config use-context devzone >/dev/null 2>&1 || true
|
|
89
|
+
echo "✔ minikube cluster devzone started"
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
# Offers the choice in a terminal. Returns 0 when a cluster was selected or
|
|
93
|
+
# created (the caller checks that it answers), 1 otherwise or without a terminal.
|
|
94
|
+
create_cluster_offer() {
|
|
95
|
+
local choice
|
|
96
|
+
create_cluster_terminal || return 1
|
|
97
|
+
echo "No Kubernetes cluster answers. Pick one:"
|
|
98
|
+
echo " 1) a remote cluster (AWS, GCP, Azure, other: a context of your kubeconfig)"
|
|
99
|
+
echo " 2) a local minikube cluster (profile devzone)"
|
|
100
|
+
printf 'Your choice (empty to cancel): '
|
|
101
|
+
read -r choice || choice=""
|
|
102
|
+
case "$choice" in
|
|
103
|
+
1) create_cluster_remote ;;
|
|
104
|
+
2) create_cluster_minikube ;;
|
|
105
|
+
*) echo "✖ cancelled" >&2; return 1 ;;
|
|
106
|
+
esac
|
|
107
|
+
}
|
|
@@ -9,6 +9,8 @@
|
|
|
9
9
|
# shellcheck disable=SC2034 # CREATE_MODE is read by manage/devzone (creer)
|
|
10
10
|
# shellcheck source=manage/scripts/kube-ready.sh
|
|
11
11
|
. "$(dirname "${BASH_SOURCE[0]}")/kube-ready.sh"
|
|
12
|
+
# shellcheck source=manage/scripts/create-cluster.sh
|
|
13
|
+
. "$(dirname "${BASH_SOURCE[0]}")/create-cluster.sh"
|
|
12
14
|
|
|
13
15
|
# Context shown to the user: devzone if declared, otherwise the current one.
|
|
14
16
|
kube_context() {
|
|
@@ -53,6 +55,14 @@ create_mode_choose() {
|
|
|
53
55
|
create_mode_existing
|
|
54
56
|
return 0
|
|
55
57
|
fi
|
|
58
|
+
# No option, in a terminal: a menu (remote cluster, minikube) instead of a
|
|
59
|
+
# failure (#653); the choice is accepted only if the cluster then answers.
|
|
60
|
+
if [ -z "$option" ] && create_cluster_offer && reason="$(kube_ready_reason)"; then
|
|
61
|
+
CREATE_MODE=kubernetes
|
|
62
|
+
echo "✔ Kubernetes ready ($(kube_context)): workspace in the cluster"
|
|
63
|
+
create_mode_existing
|
|
64
|
+
return 0
|
|
65
|
+
fi
|
|
56
66
|
create_mode_no_cluster "$reason"
|
|
57
67
|
return 1
|
|
58
68
|
}
|