Skip to content

Commit

Permalink
add debug scripts, cleanup funcs, remove two-node env hack
Browse files Browse the repository at this point in the history
Signed-off-by: Tyler Gillson <[email protected]>
  • Loading branch information
TylerGillson committed Nov 6, 2023
1 parent bd04d7b commit b2d8e72
Show file tree
Hide file tree
Showing 6 changed files with 82 additions and 4 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@ config.yaml
content-*/*
*.arg
.idea
hack/*.img
16 changes: 16 additions & 0 deletions hack/Earthfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
VERSION 0.6

ARG OSBUILDER_VERSION=v0.7.11
ARG OSBUILDER_IMAGE=quay.io/kairos/osbuilder-tools:$OSBUILDER_VERSION
ARG ISO_NAME=debug

# replace with your CanvOS provider image
ARG PROVIDER_IMAGE=oci:tylergillson/ubuntu:k3s-1.26.4-v4.0.4-071c2c23

build:
FROM $OSBUILDER_IMAGE
WORKDIR /build
COPY . ./

RUN /entrypoint.sh --name $ISO_NAME --debug build-iso --squash-no-compression --date=false $PROVIDER_IMAGE --output /build/
SAVE ARTIFACT /build/$ISO_NAME.iso kairos.iso AS LOCAL build/$ISO_NAME.iso
17 changes: 17 additions & 0 deletions hack/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Debugging Kairos

If you're facing hard-to-diagnose issues with your custom provider image, you can use the scripts in this directory to obtain verbose Kairos output.

## Steps
1. Use earthly to generate an ISO from your CanvOS provider image:
```
earthly +build --PROVIDER_IMAGE=<your_provider_image> # e.g., oci:tylergillson/ubuntu:k3s-1.26.4-v4.0.4-071c2c23
```
If successful, `build/debug.iso` will be created.
2. Launch a local VM based on the debug ISO using QEMU and pipe all output to a log file:
```
./launch-qemu.sh build/debug.iso | tee out.log
```
3. Once the VM boots, use `reboot` to return to the GRUB menu, then select your desired entry and hit `x` to edit it. Add `rd.debug rd.immucore.debug` to the end of the `linux` line for your selected GRUB menu entry, then hit `CTRL+x` to boot with your edits. You should see verbose Kairos debug logs and they will be persisted to `out.log`.
Empty file added hack/build/.keep
Empty file.
25 changes: 25 additions & 0 deletions hack/launch-qemu.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#!/bin/bash

# Screenshot capability:
# https://unix.stackexchange.com/a/476617

if [ ! -e disk.img ]; then
qemu-img create -f qcow2 disk.img 60g
fi

# -nic bridge,br=br0,model=virtio-net-pci \
qemu-system-x86_64 \
-enable-kvm \
-cpu "${CPU:=host}" \
-nographic \
-spice port=9000,addr=127.0.0.1,disable-ticketing=yes \
-m ${MEMORY:=10096} \
-smp ${CORES:=5} \
-monitor unix:/tmp/qemu-monitor.sock,server=on,wait=off \
-serial mon:stdio \
-rtc base=utc,clock=rt \
-chardev socket,path=qga.sock,server=on,wait=off,id=qga0 \
-device virtio-serial \
-device virtserialport,chardev=qga0,name=org.qemu.guest_agent.0 \
-drive if=virtio,media=disk,file=disk.img \
-drive if=ide,media=cdrom,file="${1}"
27 changes: 23 additions & 4 deletions test/test-two-node.sh
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,8 @@ function create_userdata() {
cat <<EOF > build/user-data
#cloud-config
cluster:
env:
two-node: "true"
providerConfig:
cluster-init: "no"
stylus:
site:
edgeHostToken: "$EDGE_REGISTRATION_TOKEN"
Expand Down Expand Up @@ -127,8 +127,9 @@ function upload_userdata_isos() {
}

function upload_stylus_iso() {
echo Uploading installer ISO...
govc datastore.upload --ds=$GOVC_DATASTORE --dc=$GOVC_DATACENTER build/palette-edge-installer-stylus-${STYLUS_HASH}-k3s-${PROVIDER_K3S_HASH}.iso $STYLUS_ISO
iso=palette-edge-installer-stylus-${STYLUS_HASH}-k3s-${PROVIDER_K3S_HASH}.iso
echo Uploading installer ISO $iso...
govc datastore.upload --ds=$GOVC_DATASTORE --dc=$GOVC_DATACENTER build/$iso $STYLUS_ISO
}

function create_vms() {
Expand Down Expand Up @@ -303,6 +304,14 @@ function create_cluster_profile() {
echo "Cluster Profile $CLUSTER_PROFILE_UID created"
}

function destroy_cluster_profile() {
curl -s -X DELETE https://$DOMAIN/v1/clusterprofiles/$CLUSTER_PROFILE_UID \
-H "ApiKey: $API_KEY" \
-H "Content-Type: application/json" \
-H "ProjectUid: $PROJECT_UID"
echo "Cluster Profile $CLUSTER_PROFILE_UID deleted"
}

function prepare_cluster() {
if [ -z "${STYLUS_HASH}" ]; then
echo STYLUS_HASH is unset. Please execute build_all and retry.
Expand Down Expand Up @@ -418,6 +427,16 @@ function build_all() {
) || ( build_canvos )
}

function clean_all() {
docker images | grep $OCI_REGISTRY | awk '{print $3;}' | xargs docker rmi --force
docker images | grep palette-installer | awk '{print $3;}' | xargs docker rmi --force
docker kill earthly-buildkitd
docker container prune --force
docker volume rm earthly-cache
docker volume prune --force
docker system prune --force
}

function main() {

# build all required edge artifacts
Expand Down

0 comments on commit b2d8e72

Please sign in to comment.