Skip to content

Commit 1ec2003

Browse files
committed
Bootstrap process based on initial data
- Bootstrap process based on initial data - Core manifest with core set Signed-off-by: Anton Kremenetsky <anton.kremenetsky@gmail.com>
1 parent 8b71b19 commit 1ec2003

File tree

21 files changed

+744
-217
lines changed

21 files changed

+744
-217
lines changed

etc/90-genesis-dummy-config.yaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
network:
2+
version: 2
3+
renderer: networkd
4+
allmatch:
5+
en*:
6+
dhcp4: false

etc/90-genesis-net-base-config.yaml

Lines changed: 0 additions & 17 deletions
This file was deleted.

etc/90-genesis-net-config.yaml.j2

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
network:
2+
version: 2
3+
renderer: networkd
4+
ethernets:
5+
if-eth0:
6+
match:
7+
macaddress: "{{ main_mac }}"
8+
dhcp4: false
9+
addresses:
10+
- "{{ main_ip_with_mask }}"
11+
routes:
12+
- to: default
13+
via: "{{ default_gw }}"
14+
nameservers:
15+
addresses: [1.1.1.1, 8.8.8.8, 8.8.4.4]
16+
if-eth1:
17+
match:
18+
macaddress: "{{ boot_mac }}"
19+
dhcp4: false
20+
addresses:
21+
- "{{ boot_ip_with_mask }}"
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
-- disable security status polling via DNS
22
setSecurityPollSuffix("")
33

4-
setLocal("10.20.0.2:53")
4+
setLocal("{{ main_ip }}:53")
55

66
--Private DNS
77
newServer({address="127.0.0.1:5300", pool="privatedns", healthCheckMode="up"})
Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,15 +29,15 @@ bind_host = 0.0.0.0
2929
bind_port = 11012
3030

3131
[boot_api]
32-
bind_host = 10.30.0.2
32+
bind_host = {{ boot_ip }}
3333
bind_port = 11013
34-
gc_boot_api = http://10.30.0.2:11013
35-
initrd = http://10.30.0.2:8080/bios/initrd.img
36-
kernel = http://10.30.0.2:8080/bios/vmlinuz
34+
gc_boot_api = http://{{ boot_ip }}:11013
35+
initrd = http://{{ boot_ip }}:8080/bios/initrd.img
36+
kernel = http://{{ boot_ip }}:8080/bios/vmlinuz
3737

3838

3939
[events]
40-
# enable = False
40+
enabled = False
4141
# client_type = async
4242
# event_type_mapping_filepath = event_type_mapping.yaml
4343
# genesis_notification_endpoint = http://127.0.0.1:8080/

etc/genesis_universal_agent/genesis_universal_agent.conf renamed to etc/genesis_universal_agent/genesis_universal_agent.conf.j2

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,22 @@ connection_pool_size = 2
99

1010

1111
[universal_agent]
12-
orch_endpoint = http://localhost:11011
13-
status_endpoint = http://localhost:11012
14-
caps_drivers = RestCoreCapabilityDriver,PasswordCapabilityDriver,CoreDNSCertificateCapabilityDriver,LBAgentCapabilityDriver
12+
orch_secure_communication = False
13+
orch_endpoint = http://{{ boot_ip }}:11013
14+
status_endpoint = http://{{ boot_ip }}:11013
15+
caps_drivers =
16+
RestCoreCapabilityDriver,
17+
PasswordCapabilityDriver,
18+
CoreDNSCertificateCapabilityDriver,
19+
LBAgentCapabilityDriver
1520

1621

1722
[universal_agent_scheduler]
18-
capabilities = em_*,password,certificate,paas_lb_agent
23+
capabilities =
24+
em_*,
25+
password,
26+
certificate,
27+
paas_lb_agent
1928

2029

2130
[CoreDNSCertificateCapabilityDriver]

etc/systemd/resolved.conf.j2

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
# This file is part of systemd.
2+
#
3+
# systemd is free software; you can redistribute it and/or modify it under the
4+
# terms of the GNU Lesser General Public License as published by the Free
5+
# Software Foundation; either version 2.1 of the License, or (at your option)
6+
# any later version.
7+
#
8+
# Entries in this file show the compile time defaults. Local configuration
9+
# should be created by either modifying this file (or a copy of it placed in
10+
# /etc/ if the original file is shipped in /usr/), or by creating "drop-ins" in
11+
# the /etc/systemd/resolved.conf.d/ directory. The latter is generally
12+
# recommended. Defaults can be restored by simply deleting the main
13+
# configuration file and all drop-ins located in /etc/.
14+
#
15+
# Use 'systemd-analyze cat-config systemd/resolved.conf' to display the full config.
16+
#
17+
# See resolved.conf(5) for details.
18+
19+
[Resolve]
20+
# Some examples of DNS servers which may be used for DNS= and FallbackDNS=:
21+
# Cloudflare: 1.1.1.1#cloudflare-dns.com 1.0.0.1#cloudflare-dns.com 2606:4700:4700::1111#cloudflare-dns.com 2606:4700:4700::1001#cloudflare-dns.com
22+
# Google: 8.8.8.8#dns.google 8.8.4.4#dns.google 2001:4860:4860::8888#dns.google 2001:4860:4860::8844#dns.google
23+
# Quad9: 9.9.9.9#dns.quad9.net 149.112.112.112#dns.quad9.net 2620:fe::fe#dns.quad9.net 2620:fe::9#dns.quad9.net
24+
#FallbackDNS=
25+
#Domains=
26+
#DNSSEC=no
27+
#DNSOverTLS=no
28+
#MulticastDNS=no
29+
#LLMNR=no
30+
#Cache=no-negative
31+
#CacheFromLocalhost=no
32+
#DNSStubListener=yes
33+
#DNSStubListenerExtra=
34+
#ReadEtcHosts=yes
35+
#ResolveUnicastSingleLabel=no
36+
#StaleRetentionSec=0
37+
DNS={{ main_ip }}

genesis/genesis.yaml

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,10 @@ build:
1212
- .venv
1313
- .tox
1414
- .pytest_cache
15+
- .ruff_cache
1516
- build
1617
- cover
17-
18-
# Network configuration
19-
- dst: /etc/netplan/90-genesis-net-base-config.yaml
20-
# Local path
21-
path:
22-
src: ../../genesis_core/etc/90-genesis-net-base-config.yaml
18+
- output
2319

2420
# Binary artifacts. Kernel, initrd, boot loaders.
2521
- dst: /opt/genesis_core/artifacts/undionly.kpxe
@@ -54,9 +50,10 @@ build:
5450
# List of elements in the project
5551
elements:
5652
# List of images in the element
57-
- images:
53+
- manifest: manifests/core.yaml.j2
54+
images:
5855
- name: genesis-core
59-
format: raw
56+
format: qcow2
6057

6158
# OS profile for the image
6259
profile: genesis_base
@@ -68,7 +65,6 @@ build:
6865
override:
6966
# For development purposes it's handy to have more space.
7067
disk_size: "10G"
71-
# manifest: manifests/genesis-core.yaml
7268

7369
envs:
7470
- ALLOW_USER_PASSWD

genesis/images/bootstrap.sh

Lines changed: 51 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -139,10 +139,8 @@ EOF
139139
# Reload systemd units generated from fstab so the mount can work on first run.
140140
# Example output:
141141
# [genesis-bootstrap] running: systemctl daemon-reload
142-
if command -v systemctl >/dev/null 2>&1; then
143-
log "running: systemctl daemon-reload"
144-
systemctl daemon-reload || true
145-
fi
142+
log "running: systemctl daemon-reload"
143+
systemctl daemon-reload || true
146144
else
147145
log "/etc/fstab already has the correct UUID entry for ${MOUNTPOINT}"
148146
fi
@@ -153,10 +151,8 @@ EOF
153151
# Reload systemd units generated from fstab so the mount can work on first run.
154152
# Example output:
155153
# [genesis-bootstrap] running: systemctl daemon-reload
156-
if command -v systemctl >/dev/null 2>&1; then
157-
log "running: systemctl daemon-reload"
158-
systemctl daemon-reload || true
159-
fi
154+
log "running: systemctl daemon-reload"
155+
systemctl daemon-reload || true
160156
fi
161157
else
162158
log "could not determine UUID for ${PART_DEV}; skipping fstab update"
@@ -242,20 +238,29 @@ if host_mountpoint "/var/lib/genesis/data"; then
242238
if ! grep -qs "^[[:space:]]*data_directory[[:space:]]*=[[:space:]]*'${NEW_PGDATA}'" "${PG_CONF_FILE}"; then
243239
log "configuring PostgreSQL data_directory to ${NEW_PGDATA}"
244240

245-
if command -v systemctl >/dev/null 2>&1; then
246-
systemctl stop postgresql || true
247-
fi
248-
241+
systemctl stop postgresql || true
249242
mkdir -p "${NEW_PGDATA}"
250243
chown -R postgres:postgres "/var/lib/genesis/data/postgresql" || true
251244

252245
if [[ -d "${OLD_PGDATA}" && ! -f "${NEW_PGDATA}/PG_VERSION" ]]; then
253246
log "copying PostgreSQL data directory to ${NEW_PGDATA}"
254-
if command -v rsync >/dev/null 2>&1; then
255-
rsync -aHAX --numeric-ids "${OLD_PGDATA}/" "${NEW_PGDATA}/"
256-
else
257-
cp -a "${OLD_PGDATA}/." "${NEW_PGDATA}/"
258-
fi
247+
MAX_RETRIES=5
248+
RETRY_COUNT=0
249+
while [[ ${RETRY_COUNT} -lt ${MAX_RETRIES} ]]; do
250+
if rsync -aHAX --numeric-ids "${OLD_PGDATA}/" "${NEW_PGDATA}/"; then
251+
log "rsync completed successfully"
252+
break
253+
else
254+
RETRY_COUNT=$((RETRY_COUNT + 1))
255+
if [[ ${RETRY_COUNT} -lt ${MAX_RETRIES} ]]; then
256+
log "rsync failed, retrying in 0.5s (attempt ${RETRY_COUNT}/${MAX_RETRIES})"
257+
sleep 0.5
258+
else
259+
log "ERROR: rsync failed after ${MAX_RETRIES} attempts"
260+
exit 1
261+
fi
262+
fi
263+
done
259264
chown -R postgres:postgres "${NEW_PGDATA}" || true
260265
else
261266
log "PostgreSQL data directory already present under ${NEW_PGDATA}; skipping copy"
@@ -267,17 +272,13 @@ if host_mountpoint "/var/lib/genesis/data"; then
267272
printf '%s\n' "data_directory = '${NEW_PGDATA}'" >> "${PG_CONF_FILE}"
268273
fi
269274

270-
if command -v systemctl >/dev/null 2>&1; then
271-
systemctl daemon-reload || true
272-
systemctl start postgresql || true
273-
fi
275+
systemctl daemon-reload || true
276+
systemctl start postgresql || true
274277
else
275278
log "PostgreSQL is already configured to use ${NEW_PGDATA}"
276279
fi
277280

278-
if command -v systemctl >/dev/null 2>&1; then
279-
systemctl start postgresql || true
280-
fi
281+
systemctl start postgresql || true
281282
else
282283
log "PostgreSQL config not found at ${PG_CONF_FILE}; skipping PostgreSQL relocation"
283284
fi
@@ -294,6 +295,32 @@ fi
294295
# Additional PostgreSQL configuration
295296
sudo -u postgres psql -c "ALTER SYSTEM SET io_method = 'io_uring';"
296297

298+
# Mount CD-ROM if device is present.
299+
CDROM_DEV="$(lsblk -dn -o NAME,TYPE | awk '$2=="rom" {print "/dev/"$1; exit}')"
300+
CDROM_MOUNTPOINT="/mnt/cdrom"
301+
if [[ -n "${CDROM_DEV}" ]]; then
302+
log "cd-rom device detected: ${CDROM_DEV}"
303+
mkdir -p "${CDROM_MOUNTPOINT}"
304+
if mountpoint -q "${CDROM_MOUNTPOINT}"; then
305+
log "cd-rom is already mounted at ${CDROM_MOUNTPOINT}"
306+
else
307+
if mount -o ro "${CDROM_DEV}" "${CDROM_MOUNTPOINT}"; then
308+
log "cd-rom mounted at ${CDROM_MOUNTPOINT}"
309+
else
310+
log "failed to mount cd-rom ${CDROM_DEV} at ${CDROM_MOUNTPOINT}"
311+
fi
312+
fi
313+
else
314+
log "cd-rom device not detected"
315+
fi
316+
317+
# Prepare templated configuration files and apply them
318+
sudo gc-bootstrap-templates
319+
sudo netplan apply
320+
sudo systemctl restart \
321+
systemd-resolved.service \
322+
dnsdist@private.service
323+
297324
# Apply migrations
298325
source "$VENV_PATH/bin/activate"
299326
# TODO(akremenetsky): Database configuration parameters should be taken

genesis/images/install.sh

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -143,12 +143,9 @@ sudo systemctl enable nginx
143143

144144
# Install genesis core
145145
sudo mkdir -p $GC_CFG_DIR
146-
sudo cp "$GC_PATH/etc/genesis_core/genesis_core.conf" $GC_CFG_DIR/
147146
sudo cp "$GC_PATH/etc/genesis_core/core_agent.conf" $GC_CFG_DIR/
148147
sudo cp "$GC_PATH/etc/genesis_core/logging.yaml" $GC_CFG_DIR/
149148
sudo cp "$GC_PATH/etc/genesis_core/event_type_mapping.yaml" $GC_CFG_DIR/
150-
sudo cp "$GC_PATH/genesis/manifests/core.yaml" $GC_CFG_DIR/
151-
sudo cp "$GC_PATH/genesis/images/startup_cfg.yaml" $GC_CFG_DIR/
152149
sudo cp "$GC_PATH/genesis/images/bootstrap.sh" $BOOTSTRAP_PATH/0100-gc-bootstrap.sh
153150

154151
cd "$GC_PATH"
@@ -162,7 +159,7 @@ if [[ "$SDK_DEV_MODE" == "true" ]]; then
162159
fi
163160

164161
# Configuration for universal agent
165-
sudo cp -r "$GC_PATH/etc/genesis_universal_agent" /etc/
162+
sudo cp "$GC_PATH/etc/genesis_universal_agent/logging.yaml" /etc/genesis_universal_agent/
166163

167164
# Apply migrations
168165
# The migrations are applied in the bootstrap script as well.
@@ -182,13 +179,19 @@ fi
182179

183180
deactivate
184181

182+
# Misc config
183+
# Disable DHCP for the main interface, it will be configured in the bootstrap script
184+
sudo cp "$GC_PATH/etc/90-genesis-dummy-config.yaml" /etc/netplan/90-genesis-net-base-config.yaml
185+
186+
185187
# Create links to venv
186188
sudo ln -sf "$VENV_PATH/bin/gc-user-api" "/usr/bin/gc-user-api"
187189
sudo ln -sf "$VENV_PATH/bin/gc-boot-api" "/usr/bin/gc-boot-api"
188190
sudo ln -sf "$VENV_PATH/bin/gc-orch-api" "/usr/bin/gc-orch-api"
189191
sudo ln -sf "$VENV_PATH/bin/gc-status-api" "/usr/bin/gc-status-api"
190192
sudo ln -sf "$VENV_PATH/bin/gc-gservice" "/usr/bin/gc-gservice"
191193
sudo ln -sf "$VENV_PATH/bin/gc-bootstrap" "/usr/bin/gc-bootstrap"
194+
sudo ln -sf "$VENV_PATH/bin/gc-bootstrap-templates" "/usr/bin/gc-bootstrap-templates"
192195
sudo ln -sf "$VENV_PATH/bin/genesis-universal-agent" "/usr/bin/genesis-universal-agent"
193196
sudo ln -sf "$VENV_PATH/bin/genesis-universal-agent-db-back" "/usr/bin/genesis-universal-agent-db-back"
194197
sudo ln -sf "$VENV_PATH/bin/genesis-universal-scheduler" "/usr/bin/genesis-universal-scheduler"
@@ -217,19 +220,18 @@ sudo cp "$GC_PATH/etc/powerdns/genesis.conf" /etc/powerdns/pdns.d/genesis.conf
217220
sudo systemctl enable pdns
218221

219222
#dnsdist
220-
sudo cp "$GC_PATH/etc/dnsdist/dnsdist-private.conf" /etc/dnsdist/dnsdist-private.conf
221-
sudo systemctl enable dnsdist@private
222223

223224
# Optional, only for public resolving, for ex. ACME dns01 certs challenge
224225
sudo cp "$GC_PATH/etc/dnsdist/dnsdist-public.conf" /etc/dnsdist/dnsdist-public.conf
225226
sudo systemctl enable dnsdist@public
227+
sudo systemctl enable dnsdist@private
226228

227229
# Set local IP where needed
228230
# LOCAL_IP=$(cat "$GC_PATH/genesis/images/startup_cfg.yaml" | yq '.startup_entities.core_ip' -r)
229231
# Use static IP for now
230-
LOCAL_IP="10.20.0.2"
231-
echo "DNS=${LOCAL_IP}" | sudo tee -a /etc/systemd/resolved.conf > /dev/null
232-
sudo sed -i 's/setLocal("10.20.0.2:53")/setLocal("'"${LOCAL_IP}"':53")/' /etc/dnsdist/dnsdist-private.conf
232+
# LOCAL_IP="10.20.0.2"
233+
# echo "DNS=${LOCAL_IP}" | sudo tee -a /etc/systemd/resolved.conf > /dev/null
234+
# sudo sed -i 's/setLocal("10.20.0.2:53")/setLocal("'"${LOCAL_IP}"':53")/' /etc/dnsdist/dnsdist-private.conf
233235

234236

235237
cat <<EOT | sudo tee /etc/motd
@@ -243,4 +245,14 @@ Welcome to Genesis Core virtual machine!
243245
All materials can be found here:
244246
https://github.com/infraguys
245247
246-
EOT
248+
EOT
249+
250+
PASSWD="${GEN_USER_PASSWD:-ubuntu}"
251+
252+
# Set default password
253+
cat > /tmp/__passwd <<EOF
254+
ubuntu:$PASSWD
255+
EOF
256+
257+
sudo chpasswd < /tmp/__passwd
258+
rm -f /tmp/__passwd

0 commit comments

Comments
 (0)