forked from EOEPCA/eoepca
-
Notifications
You must be signed in to change notification settings - Fork 0
/
create-cluster-config.sh
executable file
·116 lines (100 loc) · 2.35 KB
/
create-cluster-config.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
109
110
111
112
113
114
115
116
#!/usr/bin/env bash
ORIG_DIR="$(pwd)"
cd "$(dirname "$0")"
BIN_DIR="$(pwd)"
trap "cd '${ORIG_DIR}'" EXIT
CLUSTER_NAME="${1}"
CLUSTER_YML_FILE="${2:-cluster.yml}"
KUBERNETES_VERSION="v1.22.11-rancher1-1"
if test -z "$CLUSTER_NAME"
then
echo "ERROR: must provide <cluster-name> as command argument"
echo "For example, $(basename "$0") staging"
exit 1
fi
function master_nodes() {
master_nodes=$(terraform output -state=../creodias/terraform.tfstate -json | jq -r '.k8s_master_ips.value[]' 2>/dev/null) || unset master_nodes
for node in $master_nodes
do
cat - <<EOF
- address: $node
user: eouser
role:
- controlplane
- etcd
EOF
done
}
function worker_nodes() {
worker_nodes=$(terraform output -state=../creodias/terraform.tfstate -json | jq -r '.k8s_node_ips.value[]' 2>/dev/null) || unset worker_nodes
for node in $worker_nodes
do
cat - <<EOF
- address: $node
user: eouser
role:
- worker
EOF
done
}
function worker_nodes_hm() {
worker_nodes_hm=$(terraform output -state=../creodias/terraform.tfstate -json | jq -r '.k8s_node_hm_ips.value[]' 2>/dev/null) || unset worker_nodes_hm
for node in $worker_nodes_hm
do
cat - <<EOF
- address: $node
user: eouser
role:
- worker
EOF
done
}
function worker_nodes_ws() {
worker_nodes_ws=$(terraform output -state=../creodias/terraform.tfstate -json | jq -r '.k8s_node_ws_ips.value[]' 2>/dev/null) || unset worker_nodes_ws
for node in $worker_nodes_ws
do
cat - <<EOF
- address: $node
user: eouser
role:
- worker
EOF
done
}
function bastion_host() {
bastion=$(terraform output -state=../creodias/terraform.tfstate -json | jq -r '.bastion_fips.value[]' 2>/dev/null) || unset bastion
cat - <<EOF
bastion_host:
address: $bastion
user: eouser
EOF
}
function docker_registry() {
if test -n "$DOCKER_USER" -a -n "$DOCKER_PASSWORD"; then
cat - <<EOF
private_registries:
- user: ${DOCKER_USER}
password: ${DOCKER_PASSWORD}
EOF
fi
}
function cluster_yml() {
cat - <<EOF
cluster_name: ${CLUSTER_NAME}
kubernetes_version: "${KUBERNETES_VERSION}"
nodes:
$(master_nodes)
$(worker_nodes)
$(worker_nodes_hm)
$(worker_nodes_ws)
ingress:
provider: none
$(bastion_host)
$(docker_registry)
EOF
}
function main() {
cluster_yml | tee "${CLUSTER_YML_FILE}"
echo -e "---\nOutput written to file: ${CLUSTER_YML_FILE}"
}
main