-
Notifications
You must be signed in to change notification settings - Fork 84
/
manage_nodes
executable file
·54 lines (43 loc) · 1.27 KB
/
manage_nodes
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
#!/bin/bash
# "System extensions are only activated during the installation or upgrade of Talos Linux.
# With system extensions installed, the Talos root filesystem is still immutable and read-only."
# https://www.talos.dev/v1.5/talos-guides/configuration/system-extensions/
upgrade_node(){
for node in $(echo $1 | sed "s/,/ /g"); do
until kubectl get node $node --kubeconfig $tmp_dir/kubeconfig > /dev/null 2>&1 ; do
echo "Waiting for node..."
sleep 5
done
talosctl upgrade \
--nodes $node \
--preserve=true \
--wait
sleep 30
done
}
# Ensure that a node is also removed from the cluster when Terraform destroys it.
# https://www.talos.dev/v1.5/talos-guides/howto/scaling-down/
remove_node(){
talosctl reset --nodes $1
talosctl shutdown --nodes $1
kubectl delete node $1
}
main(){
tmp_dir=$(mktemp -d)
command=$1
nodes=$2
terraform output -raw kubeconfig > $tmp_dir/kubeconfig
terraform output -raw talosconfig > $tmp_dir/talosconfig
export KUBECONFIG=$tmp_dir/kubeconfig
export TALOSCONFIG=$tmp_dir/talosconfig
if [ "$command" = "upgrade" ]; then
upgrade_node "$nodes"
elif [ "$command" = "remove" ]; then
remove_node "$nodes"
else
echo "No command given"
exit 1
fi
rm -rf $tmp_dir
}
main "$@"