-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
213 lines (179 loc) · 6.18 KB
/
Makefile
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
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
all: none
# Define the list of node IPs or hostnames (space-separated)
NODE_LIST:= hpworker03.turkey.local hpworker06.turkey.local hpworker05.turkey.local
STSLESS_LIST := hpworker05.turkey.local hpworker06.turkey.local
none:
echo "try 'make tailscale'"
help:
head -30 README.md
install:
kubectl create ns cozy-system
kubectl apply -f configs/cozystack-config.yaml
# remote:# kubectl apply -f https://github.com/aenix-io/cozystack/raw/v0.24.0/manifests/cozystack-installer.yaml
# local:# kubectl apply -f cozystack-installer.yaml
tailscale:
talosctl patch mc -p @configs/tailscale-config.yaml -n 10.17.13.138 -e 10.17.13.87
storage:
kubectl create -f configs/storage/
metallb:
kubectl create -f configs/metallb-config.yaml
init:
talm init --preset cozystack
template:
mkdir -p nodes
talm template -e 10.17.13.87 -n 10.17.13.87 -t templates/controlplane.yaml -i > nodes/hpworker03.yaml
talm template -e 10.17.13.102 -n 10.17.13.102 -t templates/controlplane.yaml -i > nodes/hpworker05.yaml
talm template -e 10.17.13.138 -n 10.17.13.138 -t templates/controlplane.yaml -i > nodes/hpworker06.yaml
patch-nodes:
@echo "Merging patches into nodes/* : ..."
@bash -c ' \
NODES="$(NODE_LIST)"; \
PATCHES="caching-proxy-patch no-kexec-patch domainname-patch"; \
for node in $$NODES; do \
short_name=$$(echo $$node | cut -d. -f1); \
for patch in $$PATCHES; do \
echo "nodes/$$short_name.yaml (configs/patches/$$patch.yaml)"; \
yq -i ea ". as \$$item ireduce ({}; . * \$$item )" nodes/$${short_name}.yaml configs/patches/$${patch}.yaml; \
done; \
done \
'
apply: apply-hpworker03 apply-hpworker06 apply-hpworker05
apply-hpworker03:
talm apply -f nodes/hpworker03.yaml -i
apply-hpworker06:
talm apply -f nodes/hpworker06.yaml -i
apply-hpworker05:
talm apply -f nodes/hpworker05.yaml -i
bootstrap:
talm bootstrap -f nodes/hpworker03.yaml
dashboard:
talm dashboard -f nodes/hpworker03.yaml -f nodes/hpworker06.yaml -f nodes/hpworker05.yaml
kubeconfig:
talm kubeconfig kubeconfig -f nodes/hpworker03.yaml
clean: clean-kubeconfig clean-talosconfig clean-secrets
mrproper: clean clean-template
clean-kubeconfig:
rm -f kubeconfig
rm -f *-kubeconfig.yaml
clean-talosconfig:
rm -f talosconfig
clean-secrets:
rm secrets.yaml
preserve-secrets:
mkdir -p preserved
mv -i secrets.yaml talosconfig kubeconfig preserved/
restore-secrets:
mv -i preserved/* ./
rmdir preserved
clean-template:
rm -rf charts Chart.yaml values.yaml templates
clean-nodes:
rm -r nodes
nuke-all-nodes:
@echo "Be sure you know what you are doing!!"
@echo "====================================="
@echo "\\ \n\
talm reset -f nodes/hpworker03.yaml --reboot \\ \n\
--wipe-mode all --user-disks-to-wipe /dev/sda --graceful=false; \\ \n\
talm reset -f nodes/hpworker05.yaml --reboot \\ \n\
--wipe-mode all --graceful=false; \\ \n\
talm reset -f nodes/hpworker06.yaml --reboot \\ \n\
--wipe-mode all --graceful=false"
@echo "====================================="
@echo "Don't say you weren't warned! Danger!"
nuke-all-nodes-fast:
@echo "Be sure you know what you are doing!!"
@echo "====================================="
@echo "\\ \n\
talm reset -f nodes/hpworker03.yaml --reboot \\ \n\
--wipe-mode all --user-disks-to-wipe /dev/sda --graceful=false& \\ \n\
talm reset -f nodes/hpworker05.yaml --reboot \\ \n\
--wipe-mode all --graceful=false& \\ \n\
talm reset -f nodes/hpworker06.yaml --reboot \\ \n\
--wipe-mode all --graceful=false"
@echo "====================================="
@echo "Don't say you weren't warned! Danger!"
nuke-only-storage:
@echo "Be sure you know what you are doing!!"
@echo "====================================="
@echo "\\ \n\
talm reset -f nodes/hpworker03.yaml --reboot \\ \n\
--wipe-mode user-disks --user-disks-to-wipe /dev/sda --graceful=false"
@echo "====================================="
@echo "Don't say you weren't warned! Danger!"
nuke-stateless:
@echo "Be sure you know what you are doing!!"
@echo "====================================="
@echo "\\ \n\
talm reset -f nodes/hpworker06.yaml --reboot \\ \n\
--wipe-mode all --graceful=false; \\ \n\
talm reset -f nodes/hpworker05.yaml --reboot \\ \n\
--wipe-mode all --graceful=false"
@echo "====================================="
@echo "Don't say you weren't warned! Danger!"
## Credit to the below goes to ChatGPT
# Define timeout values
DOWN_TIMEOUT := 900 # Time in seconds to wait for all nodes to go down
# Path to mock scripts
MOCK_PING := ./hack/mock_ping.sh
MOCK_REBOOT := ./hack/mock_reboot.sh
.PHONY: monitor-nodes-reboot force-reboot-all-nodes
monitor-nodes-reboot:
@echo "Monitoring node reboot process for nodes: $(NODE_LIST)..."
@bash -c ' \
NODES="$(NODE_LIST)"; \
DOWN_TIMEOUT=$(DOWN_TIMEOUT); \
declare -A STATUS; \
declare -A FAILURE_COUNT; \
for node in $$NODES; do \
STATUS[$$node]="up"; \
FAILURE_COUNT[$$node]=0; \
done; \
function monitor_nodes { \
for i in `seq 1 $$DOWN_TIMEOUT`; do \
for node in $$NODES; do \
short_name=$$(echo $$node | cut -d. -f1); \
if ping -t 1 -c 1 $$node &> /dev/null; then \
FAILURE_COUNT[$$node]=0; \
if [[ $${STATUS[$$node]} == "down" ]]; then \
STATUS[$$node]="down-up"; \
echo "Node $$short_name is back up."; \
fi; \
else \
FAILURE_COUNT[$$node]=$$((FAILURE_COUNT[$$node] + 1)); \
if [[ $${FAILURE_COUNT[$$node]} -ge 3 ]]; then \
if [[ $${STATUS[$$node]} == "up" ]]; then \
STATUS[$$node]="down"; \
echo "Node $$short_name is down."; \
fi; \
fi; \
fi; \
done; \
sleep 1; \
local all_done=true; \
for node in $$NODES; do \
if [[ $${STATUS[$$node]} != "down-up" ]]; then \
all_done=false; \
break; \
fi; \
done; \
if $$all_done; then \
echo "All nodes have rebooted successfully."; \
return 0; \
fi; \
done; \
echo "Error: Timeout waiting for all nodes to reboot."; \
return 1; \
}; \
monitor_nodes \
'
force-reboot-all-nodes:
@echo "Forcing reboot for all nodes..."
@bash -c ' \
NODES="$(NODE_LIST)"; \
for node in $$NODES; do \
short_name=$$(echo $$node | cut -d. -f1); \
echo "Rebooting node: $$short_name"; \
talm reboot --wait=false -f nodes/$$short_name.yaml; \
done \
'