Skip to content

Commit 45de808

Browse files
feat(logging): Enables syslog logging for iPXE and IPA
1 parent 09a45cf commit 45de808

12 files changed

Lines changed: 188 additions & 3 deletions

File tree

‎.github/workflows/build-ironic-images.yaml‎

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,12 +73,19 @@ jobs:
7373
path: ironic-images/artifacts/
7474

7575
build-tenant-images:
76-
runs-on: ubuntu-latest
76+
# Pinned to 24.04 because newer runner images ship sudo-rs, which ignores
77+
# `sudo -E`. diskimage-builder's package-installs element relies on -E to
78+
# pass ARCH through, so builds that use arch-specific packages (e.g. grub2
79+
# in the ubuntu images) fail with KeyError: 'ARCH'.
80+
runs-on: ubuntu-24.04
7781
needs: [discover, build-esp-image]
7882
defaults:
7983
run:
8084
working-directory: ironic-images
8185
strategy:
86+
# Each image is independent and can fail for its own reasons, so don't
87+
# cancel the remaining matrix builds when one fails.
88+
fail-fast: false
8289
matrix:
8390
yaml-file: ${{ fromJson(needs.discover.outputs.yaml-files) }}
8491

@@ -147,6 +154,8 @@ jobs:
147154
if: ${{ github.ref == 'refs/heads/main' || github.event_name == 'workflow_dispatch' }}
148155

149156
cleanup:
157+
# run even if some image builds failed so the shared artifact is removed
158+
if: ${{ always() }}
150159
runs-on: ubuntu-latest
151160
needs: build-tenant-images
152161

‎.github/workflows/build-ironic-ipxe.yaml‎

Lines changed: 48 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,11 @@ on:
1111
tags:
1212
- "ironic-ipxe/v*"
1313
pull_request:
14+
types:
15+
- opened
16+
- synchronize
17+
- reopened
18+
- closed
1419
paths:
1520
- "containers/ironic-ipxe/**"
1621
- ".github/workflows/build-ironic-ipxe.yaml"
@@ -21,6 +26,7 @@ concurrency:
2126

2227
jobs:
2328
build:
29+
if: github.event_name != 'pull_request' || github.event.action != 'closed'
2430
runs-on: ubuntu-latest
2531

2632
permissions:
@@ -53,6 +59,7 @@ jobs:
5359
type=raw,value=${{ steps.version.outputs.tag }},enable=${{ startsWith(github.ref, 'refs/tags/ironic-ipxe/') }}
5460
type=raw,value=latest,enable={{is_default_branch}}
5561
type=raw,value=latest,enable=${{ github.event_name == 'workflow_dispatch' }}
62+
type=ref,event=pr
5663
env:
5764
DOCKER_METADATA_ANNOTATIONS_LEVELS: manifest,index
5865

@@ -64,7 +71,47 @@ jobs:
6471
context: containers/ironic-ipxe
6572
file: containers/ironic-ipxe/Dockerfile
6673
pull: true
67-
push: ${{ startsWith(github.ref, 'refs/tags/ironic-ipxe/') }}
74+
push: ${{ startsWith(github.ref, 'refs/tags/ironic-ipxe/') || github.event_name == 'pull_request' }}
6875
tags: ${{ steps.meta.outputs.tags }}
6976
labels: ${{ steps.meta.outputs.labels }}
7077
annotations: ${{ steps.meta.outputs.annotations }}
78+
79+
clean:
80+
if: github.event_name == 'pull_request' && github.event.action == 'closed'
81+
runs-on: ubuntu-latest
82+
83+
permissions:
84+
packages: write
85+
86+
steps:
87+
- name: clean up PR container
88+
uses: actions/github-script@3a2844b7e9c422d3c10d287c895573f7108da1b3 # v9
89+
with:
90+
script: |
91+
const container_name = `${context.repo.repo}/ironic-ipxe`;
92+
const response = await github.rest.packages.getAllPackageVersionsForPackageOwnedByOrg({
93+
package_type: "container",
94+
package_name: container_name,
95+
org: context.repo.owner,
96+
});
97+
98+
const target_tag = `pr-${context.payload.pull_request.number}`;
99+
console.log(`Looking for tag ${target_tag} for container ${container_name}`);
100+
101+
const versions = response.data || [];
102+
const matchingVersion = versions.find(version =>
103+
version.metadata.container.tags.includes(target_tag)
104+
);
105+
106+
if (matchingVersion) {
107+
console.log(`Found tag to delete "${target_tag}":`, matchingVersion.html_url);
108+
await github.rest.packages.deletePackageVersionForOrg({
109+
package_type: "container",
110+
package_name: container_name,
111+
org: context.repo.owner,
112+
package_version_id: matchingVersion.id,
113+
});
114+
console.log("Tag deleted");
115+
} else {
116+
console.log(`No package version found with the tag "${target_tag}".`);
117+
}

‎containers/ironic-ipxe/Dockerfile‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ RUN git checkout ${IPXE_GIT_REF}
1616
# Copy config files
1717
COPY ipxe-general.h /src/ipxe/src/config/local/general.h
1818
COPY ipxe-branding.h /src/ipxe/src/config/local/branding.h
19+
COPY ipxe-console.h /src/ipxe/src/config/local/console.h
1920

2021
WORKDIR /src/ipxe/src
2122
RUN make bin-x86_64-efi/snponly.efi ${IPXE_FLAGS}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// overrides for
2+
// https://github.com/ipxe/ipxe/blob/master/src/config/console.h
3+
4+
/*
5+
* Send iPXE console output to a remote syslog server.
6+
*
7+
* iPXE populates its `syslog` setting from DHCP option 7 (log-server) when
8+
* present, so the destination is controlled by dnsmasq rather than compiled in.
9+
* This only covers the window while iPXE itself is running (chainload + boot
10+
* script execution), which is exactly the boot/cleaning/deploy phase we want
11+
* visibility into.
12+
*/
13+
#define CONSOLE_SYSLOG

‎containers/ironic/Dockerfile‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,8 @@ RUN \
4545
COPY containers/ironic/ironic-console-pod.yaml.template /var/lib/openstack/lib/python3.14/site-packages/ironic/console/container/
4646

4747
# renovate: datasource=docker depName=ghcr.io/rackerlabs/understack/ironic-ipxe versioning=semver
48-
FROM ghcr.io/rackerlabs/understack/ironic-ipxe:1.0.0 AS ipxe
48+
# FROM ghcr.io/rackerlabs/understack/ironic-ipxe:1.0.0 AS ipxe
49+
FROM ghcr.io/rackerlabs/understack/ironic-ipxe:pr-2527 AS ipxe
4950

5051
FROM quay.io/airshipit/ironic:${OPENSTACK_VERSION}-ubuntu_resolute AS final
5152

‎ironic-images/custom_elements/undercloud-ipa/package-installs.yaml‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,5 @@ mtr-tiny:
44
tcpdump:
55
bind9-dnsutils:
66
util-linux-extra:
7+
fdisk:
8+
multipath-tools:
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#!/bin/bash
2+
#
3+
# Enable rsyslog and the boot-time configuration unit so remote log forwarding
4+
# is wired up on every ramdisk boot. The actual destination is resolved at boot
5+
# from the kernel cmdline by undercloud-rsyslog-configure.
6+
7+
# dib-lint: disable=set setu setpipefail indent
8+
if [ "${DIB_DEBUG_TRACE:-0}" -gt 0 ]; then
9+
set -x
10+
fi
11+
set -e
12+
13+
# rsyslog's Debian package usually enables itself via systemd presets, but make
14+
# it explicit so the ramdisk always starts it.
15+
systemctl enable rsyslog.service || true
16+
systemctl enable undercloud-rsyslog-configure.service
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
rsyslog:
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
[Unit]
2+
Description=Configure rsyslog remote forwarding from kernel cmdline (undercloud)
3+
# Only reads /proc/cmdline and writes a file, so run as early as possible and
4+
# do not wait for the network. rsyslog's action queue buffers messages until the
5+
# network (DHCP) is up, and imjournal backfills everything already in the journal.
6+
DefaultDependencies=no
7+
After=local-fs.target systemd-journald.service
8+
# Generate the drop-in before rsyslog starts. Never restart rsyslog from this
9+
# unit: that deadlocks, because rsyslog is ordered after this unit.
10+
Before=rsyslog.service syslog.socket
11+
12+
[Service]
13+
Type=oneshot
14+
RemainAfterExit=yes
15+
ExecStart=/usr/local/bin/undercloud-rsyslog-configure
16+
17+
[Install]
18+
WantedBy=sysinit.target
19+
RequiredBy=rsyslog.service
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
#!/bin/bash
2+
#
3+
# Configure rsyslog to forward the IPA ramdisk's logs to a remote syslog
4+
# collector during cleaning/inspection/deploy.
5+
#
6+
# The destination is read from the kernel command line so the image stays
7+
# site-agnostic (one shared IPA image across all sites). Ironic passes it via
8+
# [redfish]kernel_append_params / [pxe]pxe_append_params in each deploy site's
9+
# ironic/values.yaml, e.g. syslog_server=10.46.100.83 (optionally with
10+
# syslog_port=514). This mirrors how the stock dynamic-login element reads
11+
# rootpwd=/sshkey= from /proc/cmdline.
12+
#
13+
# rsyslog reads the systemd journal (imjournal), so everything IPA logs to the
14+
# journal is forwarded. Forwarding is RFC3164 over TCP by default (reliable);
15+
# the OTEL syslog receiver listens on both UDP and TCP 514.
16+
17+
# dib-lint: disable=set setu setpipefail indent
18+
if [ "${DIB_DEBUG_TRACE:-0}" -gt 0 ]; then
19+
set -x
20+
fi
21+
set -e
22+
23+
CMDLINE=$(</proc/cmdline)
24+
25+
SYSLOG_SERVER=""
26+
if [[ $CMDLINE =~ syslog_server=\"?([^\"[:space:]]+)\"? ]]; then
27+
SYSLOG_SERVER="${BASH_REMATCH[1]}"
28+
fi
29+
30+
# No target configured -> leave rsyslog at its defaults (local only) and exit
31+
# cleanly so this never blocks boot.
32+
if [ -z "$SYSLOG_SERVER" ]; then
33+
echo "undercloud-rsyslog: no syslog_server= on kernel cmdline, skipping remote forwarding"
34+
exit 0
35+
fi
36+
37+
SYSLOG_PORT="514"
38+
if [[ $CMDLINE =~ syslog_port=\"?([0-9]+)\"? ]]; then
39+
SYSLOG_PORT="${BASH_REMATCH[1]}"
40+
fi
41+
42+
# Protocol: @@ = TCP (reliable), @ = UDP. Default to TCP; allow syslog_proto=udp.
43+
PREFIX="@@"
44+
if [[ $CMDLINE =~ syslog_proto=udp ]]; then
45+
PREFIX="@"
46+
fi
47+
48+
cat > /etc/rsyslog.d/99-undercloud-remote.conf <<EOF
49+
# Managed by undercloud-rsyslog element (generated at boot from kernel cmdline).
50+
# Pull from the systemd journal and forward everything to the remote collector.
51+
module(load="imjournal" StateFile="imjournal.state")
52+
53+
# rsyslog starts before DHCP finishes, so the first connection attempts fail.
54+
# The in-memory queue holds messages while the action is suspended, and a short,
55+
# capped resume interval makes forwarding start soon after the network is up.
56+
action(
57+
type="omfwd"
58+
target="${SYSLOG_SERVER}"
59+
port="${SYSLOG_PORT}"
60+
protocol="$([ "$PREFIX" = "@@" ] && echo tcp || echo udp)"
61+
action.resumeRetryCount="-1"
62+
action.resumeInterval="2"
63+
action.resumeIntervalMax="10"
64+
queue.type="linkedList"
65+
queue.saveOnShutdown="off"
66+
queue.size="50000"
67+
)
68+
EOF
69+
70+
echo "undercloud-rsyslog: forwarding journal to ${PREFIX}${SYSLOG_SERVER}:${SYSLOG_PORT}"
71+
72+
# Do NOT restart rsyslog here. This unit is ordered Before=rsyslog.service, so
73+
# rsyslog picks up the drop-in on its first start. Calling systemctl restart from
74+
# here would deadlock until the unit's start timeout.

0 commit comments

Comments
 (0)