-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathcluster-addnodes
More file actions
executable file
·166 lines (132 loc) · 5.03 KB
/
Copy pathcluster-addnodes
File metadata and controls
executable file
·166 lines (132 loc) · 5.03 KB
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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
#!/bin/bash
INVENTORY_FILE=$1
SERVER_WAIT=90s
REMOTE_USER=root
export ANSIBLE_DISPLAY_SKIPPED_HOSTS=false
export ANSIBLE_CONFIG=./ansible.cfg
function desktop_deploy () {
echo "Not yet implemented"
echo
}
function proxmox_deploy () {
echo "Creating the Proxmox VMs and configuring the network for static IP assignment..."
ansible-playbook -i $INVENTORY_FILE ansible/proxmox-create-vms.yml --extra-vars "cluster_pkg_folder='${CLUSTER_PKG_FOLDER}' cluster_type=${CLUSTER_TYPE}"
if [ $? -ne 0 ]; then
echo "There was a problem creating the VM cluster nodes in Proxmox VE"
exit 1
fi
echo "Adding the cluster node(s) from hosts_add..."
ansible-playbook -i $INVENTORY_FILE ansible/proxmox-addnodes.yml --extra-vars="cluster_pkg_folder=${CLUSTER_PKG_FOLDER} cluster_type=${CLUSTER_TYPE}"
if [ $? -ne 0 ]; then
echo "FAIL: ${CLUSTER_TYPE_NAME} Node creation failed!"
exit 1
fi
if [ -f clusters/$CLUSTER_PKG_FOLDER/test-cluster ]; then
bash clusters/$CLUSTER_PKG_FOLDER/test-cluster
fi
echo -e "${TC}------------------------------------------------------------${NC}"
echo "${EMOJI}SUCCESS: ${CLUSTER_TYPE_NAME} Nodes Created!"
}
function cluster_info_display() {
echo
echo -e "${TC}-----------------------------------------------------------------------------------${NC}"
echo -e "${EMOJI}Cluster Builder - Add Node(s)"
echo -e "${TC}-----------------------------------------------------------------------------------${NC}"
echo -e " Name : ${TC}${CLUSTER_NAME}${NC}"
echo -e " Spec Folder : ${TC}${CLUSTER_PKG_FOLDER}${NC}"
echo -e " Type : ${TC}${CLUSTER_TYPE} - ${CLUSTER_TYPE_NAME}${NC}"
if [[ $DEPLOY_TARGET != "proxmox" ]]; then
echo -e " OVA Template : ${TC}${OVA_TEMPLATE_FILE}${NC}"
fi
echo -e " Target : ${TC}${DEPLOY_TARGET}${NC}"
echo -e "${TC}-----------------------------------------------------------------------------------${NC}"
echo
}
PLATFORM=`uname -ra`
VIRT_APP="VMware Workstation"
if [[ $PLATFORM == *"Microsoft"* ]]; then
VIRT_APP="VMware Fusion"
export ANSIBLE_CONFIG=$PWD/ansible.cfg
elif [[ $PLATFORM == *"Darwin"* ]]; then
VIRT_APP="VMware Fusion"
fi
if [ -z "${INVENTORY_FILE}" ]; then
read -s "Enter the target cluster folder: " INVENTORY_FILE
fi
INVENTORY_FILE=./clusters/$INVENTORY_FILE/hosts_add
if [ ! -f $INVENTORY_FILE ]; then
echo
echo "Unable to find special add nodes inventory file @: ${INVENTORY_FILE}"
exit 1
fi
CLUSTER_TYPE=`sed -n '/^cluster_type=/ {s///p;q;}' $INVENTORY_FILE | tr -d '\n' | tr -d '\r'`
BUILD_TEMPLATE=`sed -n '/^build_template=/ {s///p;q;}' $INVENTORY_FILE | tr -d '\n' | tr -d '\r'`
DEPLOY_TARGET=`sed -n '/^deploy_target=/ {s///p;q;}' $INVENTORY_FILE | tr -d '\n' | tr -d '\r'`
CLUSTER_NAME=`sed -n '/^cluster_name=/ {s///p;q;}' $INVENTORY_FILE | tr -d '\n' | tr -d '\r'`
REMOTE_USER=`sed -n '/^remote_user=/ {s///p;q;}' $INVENTORY_FILE | tr -d '\n' | tr -d '\r'`
CLUSTER_PROTECTED=`sed -n '/^protected=/ {s///p;q;}' $INVENTORY_FILE | tr -d '\n' | tr -d '\r'`
INSTALL_DASHBOARD=`sed -n '/^install_package_dashboard=/ {s///p;q;}' $INVENTORY_FILE | tr -d '\n' | tr -d '\r'`
if [ "$CLUSTER_PROTECTED" == "true" ]; then
echo
echo -e "${TC}Deployment Blocked!${NC}"
echo "The cluster has been marked protected=true"
echo
echo "To redeploy the cluster ${CLUSTER_NAME} (destroying any existing instance), "
echo "remove this flag from the ${CLUSTER_PKG_FOLDER}/hosts file."
echo
exit 1
fi
CLUSTER_PKG_PATH=`dirname $INVENTORY_FILE`
CLUSTER_PKG_FOLDER=${CLUSTER_PKG_PATH//.\/clusters\//}
if [ -f clusters/$CLUSTER_PKG_FOLDER/.passwords ]; then
source clusters/$CLUSTER_PKG_FOLDER/.passwords
fi
TEMP_SCRIPT_PATH=./tmp/$CLUSTER_PKG_FOLDER
if [ "$DEPLOY_TARGET" == "proxmox" ]; then
CLUSTER_TYPE_NAME='Proxmox VE Ubuntu 24.04 Kubernetes'
else
OVA_TEMPLATE_FILE=node-packer/output_ovas/cluster-node-x86_64.ova
CLUSTER_TYPE_NAME='Rocky 9.4 Kubernetes'
fi
TC=''
NC=''
EMOJI=''
EMOJIPRE=''
if [ "$TERM" == "xterm-256color" ]; then
TC='\033[1;34m'
NC='\033[0m' # No Color
EMOJI='👷 '
EMOJIPRE=' '
fi
cluster_info_display
START_TIME=$SECONDS
if [ "$DEPLOY_TARGET" != "proxmox" ]; then
if [ ! -f $OVA_TEMPLATE_FILE ]; then
echo "Unable to locate template file @: ${OVA_TEMPLATE_FILE}"
echo "Attempting to build: ${OVA_BUILD_TYPE}"
cd node-packer
bash build
cd ..
fi
if [ ! -f $OVA_TEMPLATE_FILE ]; then
echo "Unable to build template ova: ${OVA_BUILD_TYPE}"
exit 1
fi
desktop_deploy
else
proxmox_deploy
fi
ELAPSED_TIME=$(($SECONDS - $START_TIME))
echo "${EMOJIPRE}Deployed in: $(($ELAPSED_TIME/60)) min $(($ELAPSED_TIME%60)) sec"
echo -e "${TC}------------------------------------------------------------${NC}"
echo
echo -e "On a MASTER NODE, execute the following:"
echo
echo -e "${TC}kubeadm token create --print-join-command${NC}"
echo
echo -e "Then on the NEW WORKER NODE, execute the JOIN COMMAND from above."
echo
echo -e "Enjoy your new ${TC}${CLUSTER_TYPE_NAME}${NC} nodes!"
echo
echo -e "${TC}------------------------------------------------------------${NC}"
echo