-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathcluster.sh
executable file
·75 lines (66 loc) · 1.5 KB
/
cluster.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
#!/usr/bin/env bash
set -euo pipefail
create-cluster() {
echo "Creating the cluster..."
# This pretends to create a kubernetes cluster
# by generating a dummy kubeconfig file
mkdir -p /home/nonroot/.kube
cat <<EOF >> /home/nonroot/.kube/config
apiVersion: v1
clusters:
- cluster:
certificate-authority-data: abc123==
server: https://127.0.0.1:8443
name: minikube
contexts:
- context:
cluster: minikube
user: minikube
name: minikube
current-context: minikube
kind: Config
preferences: {}
users:
- name: minikube
user:
client-certificate-data: abc123=
client-key-data: abc123==
EOF
}
ensure-config() {
if [ ! -f "/home/nonroot/.kube/config" ]; then
echo "kubeconfig not found"
exit 1
fi
}
ensure-users() {
if [ ! -f "/cnab/app/users.json" ]; then
echo "users.json not found"
exit 1
fi
}
generate-users() {
ensure-config
echo '{"users": ["sally"]}' > users.json
cat users.json
}
add-user() {
ensure-config
ensure-users
# Do this in two steps because jq doesn't have overwrite functionality
cat users.json | jq ".users += [\"$1\"]" > users.json.tmp
# Using cp instead of mv because if the bundle is executed with Kubernetes
# you can't move a file that was volume mounted in k8s. That only works with Docker.
cp users.json.tmp users.json
}
dump-users() {
ensure-config
ensure-users
cat users.json
}
uninstall() {
ensure-config
echo 'Uninstalling Cluster...'
}
# Call the requested function and pass the arguments as-is
"$@"