Skip to content

Commit d828f14

Browse files
authored
Lots of refactors and cleanups (#124)
## Description A bunch of QoL fixes for compose and vagrant. ## Why is this needed I was having trouble following some of the things done in compose especially when comparing vagrant vs terraform. I had a hunch that somethings weren't necessary and set about to check and started unraveling some threads. ## How Has This Been Tested? Lots of: `vagrant destroy -f; vagrant up provisioner; ... wait ...; vagrant up machine1; reboot` throughout deving and at the end. ## How are existing users impacted? What migration steps/scripts do we need? Should be easier to contribute to sandbox as there's even less special-case-stuff in vagrant and in the compose dirs. The "one-off-services" directories being named after the services themselves was nice to be able to go back and forth easily without having to a mental-map-lookup. ## Checklist: I have: - [x] updated the documentation and/or roadmap (if required) - [ ] added unit or e2e tests - [ ] provided instructions on how to upgrade
2 parents a2245d4 + a99f1f1 commit d828f14

File tree

35 files changed

+527
-763
lines changed

35 files changed

+527
-763
lines changed

.github/workflows/ci-non-go.sh

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,10 @@ if ! terraform fmt -write -recursive deploy/terraform/; then
2626
failed=1
2727
fi
2828

29+
if ! rufo deploy/vagrant/Vagrantfile; then
30+
failed=1
31+
fi
32+
2933
if ! git diff | (! grep .); then
3034
failed=1
3135
fi

deploy/compose/.env

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
1-
#OSIE_DOWNLOAD_URLS="https://tinkerbell-oss.s3.amazonaws.com/osie-uploads/osie-1790-23d78ea47f794d0e5c934b604579c26e5fce97f5.tar.gz"
2-
OSIE_DOWNLOAD_URLS="https://github.com/tinkerbell/hook/releases/download/5.10.57/hook_x86_64.tar.gz,https://github.com/tinkerbell/hook/releases/download/5.10.57/hook_aarch64.tar.gz"
3-
TINKERBELL_USE_HOOK="true"
4-
TINK_CLI_IMAGE="quay.io/tinkerbell/tink-cli:sha-3743d31e"
5-
TINK_SERVER_IMAGE="quay.io/tinkerbell/tink:sha-3743d31e"
6-
BOOTS_SERVER_IMAGE="quay.io/tinkerbell/boots:sha-36f12f81"
7-
HEGEL_SERVER_IMAGE="quay.io/tinkerbell/hegel:sha-89cb9dc8"
8-
TINKERBELL_HARDWARE_MANIFEST="/manifests/hardware/hardware.json"
9-
TINKERBELL_TEMPLATE_MANIFEST="/manifests/template/ubuntu.yaml"
10-
TINKERBELL_HOST_IP=192.168.56.4
1+
OSIE_DOWNLOAD_URLS=https://github.com/tinkerbell/hook/releases/download/5.10.57/hook_x86_64.tar.gz,https://github.com/tinkerbell/hook/releases/download/5.10.57/hook_aarch64.tar.gz
2+
3+
BOOTS_SERVER_IMAGE=quay.io/tinkerbell/boots:sha-36f12f81
4+
HEGEL_SERVER_IMAGE=quay.io/tinkerbell/hegel:sha-89cb9dc8
5+
TINK_CLI_IMAGE=quay.io/tinkerbell/tink-cli:sha-e053ada6
6+
TINK_SERVER_IMAGE=quay.io/tinkerbell/tink:sha-3743d31e
7+
8+
TINKERBELL_HARDWARE_MANIFEST=/manifests/hardware/hardware.json
9+
TINKERBELL_TEMPLATE_MANIFEST=/manifests/template/ubuntu.yaml
10+
1111
TINKERBELL_CLIENT_IP=192.168.56.43
1212
TINKERBELL_CLIENT_MAC=08:00:27:9e:f5:3a
13+
TINKERBELL_HOST_IP=192.168.56.4
Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
#!/usr/bin/env bash
2+
3+
# This script is used to push (hardware) and create (template, workflow) Tink Server data/objects
4+
# This script assumes that the `tink` binary is in the PATH and
5+
# TINKERBELL_CERT_URL and TINKERBELL_GRPC_AUTHORITY environment variables are set
6+
# See https://docs.tinkerbell.org/services/tink-cli/ for more details
7+
8+
set -euxo pipefail
9+
10+
# update_hw_ip_addr the hardware json with a specified IP address
11+
update_hw_ip_addr() {
12+
local ip_address=$1
13+
local hardware_file=$2
14+
local tmp
15+
tmp=$(mktemp "${hardware_file}.XXXXXXXX")
16+
jq -S '.network.interfaces[0].dhcp.ip.address = "'"${ip_address}"'"' "${hardware_file}" | tee "${tmp}"
17+
mv "${tmp}" "${hardware_file}"
18+
}
19+
20+
# update_hw_mac_addr the hardware json with a specified MAC address
21+
update_hw_mac_addr() {
22+
local mac_address=$1
23+
local hardware_file=$2
24+
local tmp
25+
tmp=$(mktemp "${hardware_file}.XXXXXXXX")
26+
jq -S '.network.interfaces[0].dhcp.mac = "'"${mac_address}"'"' "${hardware_file}" | tee "${tmp}"
27+
mv "${tmp}" "${hardware_file}"
28+
}
29+
30+
# hardware creates a hardware record in tink from the file_loc provided
31+
hardware() {
32+
tink hardware push --file "$1" 2>/dev/null
33+
}
34+
35+
# update_template_img_ip the template yaml with a specified IP address
36+
update_template_img_ip() {
37+
local ip_address=$1
38+
local template_file=$2
39+
local tmp
40+
tmp=$(mktemp "${template_file}.XXXXXXXX")
41+
sed -E '/IMG_URL:/ s|/[^/]+:|/'"${ip_address}"':|' "${template_file}" | tee "${tmp}"
42+
mv "${tmp}" "${template_file}"
43+
}
44+
45+
# template checks if a template exists in tink and creates one from the file_loc provided if one does not exist
46+
template() {
47+
if (($(tink template get --no-headers 2>/dev/null | grep -c '^|') > 0)); then
48+
return
49+
fi
50+
51+
tink template create --file "$1" 2>/dev/null
52+
}
53+
54+
# workflow checks if a workflow record exists in tink before creating a new one
55+
workflow() {
56+
local mac_address=$1
57+
58+
local template_id
59+
template_id=$(tink template get --no-headers 2>/dev/null | grep '^|' | awk '{print $2}' | head -n1)
60+
61+
local workflow_id
62+
workflow_id=$(tink workflow get --no-headers 2>/dev/null | grep "${template_id}" | awk '{print $2}' | head -n1 || :)
63+
if [[ -n ${workflow_id:-} ]]; then
64+
echo "Workflow [${workflow_id}] already exists"
65+
return
66+
fi
67+
68+
tink workflow create --template "${template_id}" --hardware '{"device_1":"'"${mac_address}"'"}' 2>/dev/null
69+
}
70+
71+
# main runs the creation functions in order
72+
hardware_file=$1
73+
template_file=$2
74+
ip_address=$3
75+
client_ip_address=$4
76+
client_mac_address=$5
77+
78+
[[ -z ${hardware_file} ]] && echo "hardware_file arg is empty" >&2 && exit 1
79+
[[ -z ${template_file} ]] && echo "template_file arg is empty" >&2 && exit 1
80+
[[ -z ${ip_address} ]] && echo "ip_address arg is empty" >&2 && exit 1
81+
[[ -z ${client_ip_address} ]] && echo "client_ip_address arg is empty" >&2 && exit 1
82+
[[ -z ${client_mac_address} ]] && echo "client_mac_address arg is empty" >&2 && exit 1
83+
84+
t=$(mktemp hardware-XXXXXXXX)
85+
cat "$hardware_file" >"$t"
86+
hardware_file=$t
87+
88+
t=$(mktemp template-XXXXXXXX)
89+
cat "$template_file" >"$t"
90+
template_file=$t
91+
92+
trap 'rm -f "$hardware_file" "$template_file"' EXIT
93+
94+
client_mac_address=$(echo "$client_mac_address" | tr 'A-F' 'a-f')
95+
96+
if ! which jq &>/dev/null; then
97+
apk add jq
98+
fi
99+
100+
update_hw_ip_addr "${client_ip_address}" "${hardware_file}"
101+
update_hw_mac_addr "${client_mac_address}" "${hardware_file}"
102+
hardware "${hardware_file}"
103+
update_template_img_ip "${ip_address}" "${template_file}"
104+
template "${template_file}"
105+
workflow "${client_mac_address}"

deploy/compose/manifests/template/ubuntu-equinix-metal.yaml renamed to deploy/compose/create-tink-records/manifests/template/ubuntu-equinix-metal.yaml

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -80,11 +80,13 @@ tasks:
8080
DEST_PATH: /etc/netplan/config.yaml
8181
CONTENTS: |
8282
network:
83-
version: 2
84-
renderer: networkd
85-
ethernets:
86-
enp1s0f0:
87-
dhcp4: true
83+
version: 2
84+
renderer: networkd
85+
ethernets:
86+
id0:
87+
match:
88+
name: en*
89+
dhcp4: true
8890
UID: 0
8991
GID: 0
9092
MODE: 0644

deploy/compose/manifests/template/ubuntu.yaml renamed to deploy/compose/create-tink-records/manifests/template/ubuntu.yaml

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,15 @@ tasks:
1616
DEST_DISK: /dev/sda
1717
IMG_URL: "http://192.168.56.4:8080/focal-server-cloudimg-amd64.raw.gz"
1818
COMPRESSED: true
19+
- name: "grow-partition"
20+
image: cexec:v1.0.0
21+
timeout: 90
22+
environment:
23+
BLOCK_DEVICE: /dev/sda1
24+
FS_TYPE: ext4
25+
CHROOT: y
26+
DEFAULT_INTERPRETER: "/bin/sh -c"
27+
CMD_LINE: "growpart /dev/sda 1 && resize2fs /dev/sda1"
1928
- name: "install-openssl"
2029
image: cexec:v1.0.0
2130
timeout: 90
@@ -61,15 +70,13 @@ tasks:
6170
DEST_PATH: /etc/netplan/config.yaml
6271
CONTENTS: |
6372
network:
64-
version: 2
65-
renderer: networkd
66-
ethernets:
67-
enp0s3:
68-
dhcp4: true
69-
enp0s8:
70-
dhcp4: true
71-
ens33:
72-
dhcp4: true
73+
version: 2
74+
renderer: networkd
75+
ethernets:
76+
id0:
77+
match:
78+
name: en*
79+
dhcp4: true
7380
UID: 0
7481
GID: 0
7582
MODE: 0644

0 commit comments

Comments
 (0)