-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathsetup.sh
executable file
·108 lines (88 loc) · 2.63 KB
/
setup.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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
#!/bin/bash
# strict mode - based on http://redsymbol.net/articles/unofficial-bash-strict-mode/
set -euo pipefail
IFS=$'\n\t'
CONFIGS_PATH="./configs"
#region SETUP ENV
setup() {
PORTAINER_BASE=$1
for f in $(find -name kind.yaml.template); do
sed "s#_PORTAINER_PATH_#$PORTAINER_BASE#g" $f > "$(dirname $f)"/kind.yaml;
done
}
#endregion
#region CLUSTER MANAGEMENT
create() {
CONTEXT=$1
kind create cluster --config=$CONFIGS_PATH/$1/kind.yaml --name $CONTEXT
kubectl --context kind-$CONTEXT apply -f $CONFIGS_PATH/common/portainer-ns.yaml
kubectl --context kind-$CONTEXT apply -f $CONFIGS_PATH/common/cluster-admin.yaml
}
portainer() {
kubectl --context kind-$1 replace --force -f $CONFIGS_PATH/$1/portainer.yaml
}
delete() {
kind delete clusters $1
}
recreate() {
delete $1
create $1
}
#endregion
#region APP MANAGEMENT
deploy() {
kubectl --context kind-$1 apply -f $2
}
redeploy() {
kubectl --context kind-$1 replace --force -f $2
}
remove() {
kubectl --context kind-$1 delete --force -f $2
}
#endregion
usage() {
echo """
Usage: ./setup.sh ACTION CONTEXT [CONFIG_FILE]
with: - ACTION one of
setup
create | delete | recreate | portainer
deploy | redeploy | remove
help | usage | *
- CONTEXT the name of a folder in ./configs/
- CONFIG_FILE any .yaml config to deploy
ACTIONS:
- ./setup.sh setup PORTAINER_BASE
* will create kind files where the base path is set to PORTAINER_BASE
- ./setup.sh [ create | delete | recreate | portainer ] CONTEXT
* create: create a new cluster defined by configs/CONTEXT/kind.yaml
* delete: delete cluster defined by configs/CONTEXT/kind.yaml
* recreate: alias for delete + create
* portainer: redeploy portainer inside CONTEXT cluster using configs/CONTEXT/portainer.yaml (kubectl replace --force)
- ./setup.sh [ deploy | redeploy | remove ] CONTEXT CONFIG_FILE
* deploy: deploy the items defined by CONFIG_FILE inside CONTEXT cluster (kubectl apply)
* redeploy: redeploy the items defined by CONFIG_FILE inside CONTEXT cluster (kubectl replace --force)
* delete: delete the items defined by CONFIG_FILE inside CONTEXT cluster (kubectl delete --force)
- ./setup.sh [ usage | help | * ]
show this usage
"""
}
command=${1:-}
case $command in
create | recreate | portainer | delete | setup)
if [[ $# == 2 ]]; then
$1 $2
else
usage
fi
;;
deploy | redeploy | remove)
if [[ $# == 3 ]]; then
$1 $2 $3
else
usage
fi
;;
help | usage | *)
usage
;;
esac