Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update to u-root 0.12.0 and more cleanups #115

Merged
merged 13 commits into from
Jan 19, 2024
Merged
Show file tree
Hide file tree
Changes from 10 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 20 additions & 12 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,19 +1,28 @@
# FIXME this points to the last go-1.20 image of the builder,
# go-1.21 cant be used actually because bookworm mangled libsystemd-dev which breaks the build
# and go-1.21 is not available with bullseye.
# maybe we should switch away from depending on the builder image
FROM metalstack/builder@sha256:d2050a3bef9bbd9d9ea769a71a4a70b9ff4b24c537d29d5870b83fc652bb67f8 as builder
FROM golang:1.21-alpine as builder

RUN apk add \
binutils \
coreutils \
curl \
gcc \
git \
make \
musl-dev \
libpcap-dev
WORKDIR /work
Gerrit91 marked this conversation as resolved.
Show resolved Hide resolved
COPY . .
RUN make all
# Install Intel Firmware for e800 based network cards
ENV ICE_VERSION=1.9.11
ENV ICE_PKG_VERSION=1.3.30.0
ENV ICE_VERSION=1.13.7
ENV ICE_PKG_VERSION=1.3.35.0
RUN curl -fLsS https://sourceforge.net/projects/e1000/files/ice%20stable/${ICE_VERSION}/ice-${ICE_VERSION}.tar.gz/download -o ice.tar.gz \
&& tar -xf ice.tar.gz ice-${ICE_VERSION}/ddp/ice-${ICE_PKG_VERSION}.pkg \
&& mkdir -p /lib/firmware/intel/ice/ddp/ \
&& mv ice-${ICE_VERSION}/ddp/ice-${ICE_PKG_VERSION}.pkg /work/ice.pkg

# ipmitool from bookworm is broken and returns with error on most commands
FROM golang:1.20-bullseye as initrd-builder
ENV UROOT_GIT_SHA_OR_TAG=v0.11.0
ENV UROOT_GIT_SHA_OR_TAG=v0.12.0
RUN apt-get update \
&& apt-get install -y --no-install-recommends \
ca-certificates \
Expand All @@ -40,16 +49,15 @@ RUN mkdir -p ${GOPATH}/src/github.com/u-root \
&& git clone https://github.com/u-root/u-root \
&& cd u-root \
&& git checkout ${UROOT_GIT_SHA_OR_TAG} \
&& GO111MODULE=off go install
&& go install
WORKDIR /work
RUN mkdir -p /work/etc/lvm /work/etc/ssl/certs /work/lib/firmware/intel/ice/ddp/ /work/var/run \
&& cp /usr/share/zoneinfo/Etc/UTC /work/etc/localtime
COPY lvmlocal.conf metal.key metal.key.pub passwd varrun Makefile .git /work/
COPY --from=r.metal-stack.io/metal/supermicro:2.12.0 /usr/bin/sum /work/
COPY --from=builder /common /common
COPY --from=r.metal-stack.io/metal/supermicro:2.13.0 /usr/bin/sum /work/
COPY --from=builder /work/ice.pkg /work/ice.pkg
COPY --from=builder /work/bin/metal-hammer /work/bin/
RUN COMMONDIR=/common make ramdisk
RUN make ramdisk

FROM scratch
COPY --from=builder /work/bin/metal-hammer /
Expand Down
85 changes: 63 additions & 22 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,18 +1,45 @@
.ONESHELL:
Gerrit91 marked this conversation as resolved.
Show resolved Hide resolved
SHA := $(shell git rev-parse --short=8 HEAD)
GITVERSION := $(shell git describe --long --all)
BUILDDATE := $(shell date --iso-8601=seconds)
VERSION := $(or ${VERSION},$(shell git describe --tags --exact-match 2> /dev/null || git symbolic-ref -q --short HEAD || git rev-parse --short HEAD))
GO := go
GOSRC = $(shell find . -not \( -path vendor -prune \) -type f -name '*.go')

BINARY := metal-hammer
INITRD := ${BINARY}-initrd.img
COMPRESSOR := lz4
COMPRESSOR_ARGS := -f -l
INITRD_COMPRESSED := ${INITRD}.${COMPRESSOR}
MAINMODULE := .
COMMONDIR := $(or ${COMMONDIR},../builder)
CGO_ENABLED := 1
# export CGO_LDFLAGS := "-lsystemd" "-lpcap" "-ldbus-1"

in-docker: gofmt test all;

include $(COMMONDIR)/Makefile.inc
.PHONY: all
all:: bin/$(BINARY);

in-docker: all;

LINKMODE := -linkmode external -extldflags '-static -s -w' \
-X 'github.com/metal-stack/v.Version=$(VERSION)' \
-X 'github.com/metal-stack/v.Revision=$(GITVERSION)' \
-X 'github.com/metal-stack/v.GitSHA1=$(SHA)' \
-X 'github.com/metal-stack/v.BuildDate=$(BUILDDATE)'

release:: gofmt test all ;
bin/$(BINARY): test $(GOSRC)
$(info CGO_ENABLED="$(CGO_ENABLED)")
$(GO) build \
-tags netgo \
-ldflags \
"$(LINKMODE)" \
-o bin/$(BINARY) \
$(MAINMODULE)
strip bin/$(BINARY)

.PHONY: test
test:
CGO_ENABLED=1 $(GO) test -cover ./...

.PHONY: clean
clean::
Expand All @@ -26,39 +53,40 @@ ${INITRD_COMPRESSED}:
initrd: ${INITRD_COMPRESSED}

# place all binaries in the same directory (/sbin) which is in the PATH of root.
# keep them alphabetically sorted
.PHONY: ramdisk
ramdisk:
GO111MODULE=off u-root \
-format=cpio -build=bb \
-defaultsh=/bin/bash \
-files="bin/metal-hammer:bbin/uinit" \
-files="/etc/ssl/certs/ca-certificates.crt:etc/ssl/certs/ca-certificates.crt" \
-files="/etc/localtime:etc/localtime" \
-files="/bin/bash:bin/bash" \
-files="/bin/netstat:bin/netstat" \
-files="/etc/localtime:etc/localtime" \
-files="/etc/lvm/lvm.conf:etc/lvm/lvm.conf" \
-files="/etc/ssl/certs/ca-certificates.crt:etc/ssl/certs/ca-certificates.crt" \
-files="/lib/x86_64-linux-gnu/libnss_files-2.31.so:lib/x86_64-linux-gnu/libnss_files-2.31.so" \
-files="/lib/x86_64-linux-gnu/libnss_files.so.2:lib/x86_64-linux-gnu/libnss_files.so.2" \
-files="/sbin/blkid:sbin/blkid" \
-files="/sbin/ethtool:sbin/ethtool" \
-files="/usr/bin/lspci:bin/lspci" \
-files="/usr/bin/strace:bin/strace" \
-files="/usr/share/misc/pci.ids:usr/share/misc/pci.ids" \
-files="/bin/netstat:bin/netstat" \
-files="/sbin/hdparm:sbin/hdparm" \
-files="/usr/bin/ipmitool:usr/bin/ipmitool" \
-files="/sbin/mkfs.vfat:sbin/mkfs.vfat" \
-files="/sbin/mkfs.ext3:sbin/mkfs.ext3" \
-files="/sbin/mkfs.ext4:sbin/mkfs.ext4" \
-files="/sbin/mke2fs:sbin/mke2fs" \
-files="/sbin/mkswap:sbin/mkswap" \
-files="/sbin/mkfs.fat:sbin/mkfs.fat" \
-files="/usr/sbin/nvme:sbin/nvme" \
-files="/sbin/lvm:sbin/lvm" \
-files="/etc/lvm/lvm.conf:etc/lvm/lvm.conf" \
-files="lvmlocal.conf:etc/lvm/lvmlocal.conf" \
-files="/sbin/mdadm:sbin/mdadm" \
-files="/sbin/mdmon:sbin/mdmon" \
-files="/sbin/mke2fs:sbin/mke2fs" \
-files="/sbin/mkfs.ext3:sbin/mkfs.ext3" \
-files="/sbin/mkfs.ext4:sbin/mkfs.ext4" \
-files="/sbin/mkfs.fat:sbin/mkfs.fat" \
-files="/sbin/mkfs.vfat:sbin/mkfs.vfat" \
-files="/sbin/mkswap:sbin/mkswap" \
-files="/sbin/sgdisk:sbin/sgdisk" \
-files="/sbin/wipefs:sbin/wipefs" \
-files="/lib/x86_64-linux-gnu/libnss_files-2.31.so:lib/x86_64-linux-gnu/libnss_files-2.31.so" \
-files="/lib/x86_64-linux-gnu/libnss_files.so.2:lib/x86_64-linux-gnu/libnss_files.so.2" \
-files="/usr/bin/ipmitool:usr/bin/ipmitool" \
-files="/usr/bin/lspci:bin/lspci" \
-files="/usr/bin/strace:bin/strace" \
-files="/usr/sbin/nvme:sbin/nvme" \
-files="/usr/share/misc/pci.ids:usr/share/misc/pci.ids" \
-files="lvmlocal.conf:etc/lvm/lvmlocal.conf" \
-files="passwd:etc/passwd" \
-files="varrun:var/run/keep" \
-files="ice.pkg:lib/firmware/intel/ice/ddp/ice.pkg" \
Expand Down Expand Up @@ -94,3 +122,16 @@ qemu-up:
BGP=1" \
-kernel metal-kernel \
-initrd metal-hammer-initrd.img.lz4

start:
# sudo setcap cap_net_admin+ep ~/bin/cloud-hypervisor
# /usr/src/linux-headers-6.5.0-9/scripts/extract-vmlinux metal-kernel-6.6.2 > vmlinux
cloud-hypervisor \
--kernel ./vmlinux \
--console off \
--serial tty \
--initramfs=metal-hammer-initrd.img.lz4 \
--cmdline "console=ttyS0" \
--cpus boot=4 \
--memory size=1024M \
--net "tap=,mac=,ip=,mask="
6 changes: 3 additions & 3 deletions cmd/bios.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@ func (h *Hammer) ConfigureBIOS() error {
if err != nil {
return err
}
h.log.Infow("bios", "message", "successfully configured BIOS")
h.log.Info("bios", "message", "successfully configured BIOS")

if reboot {
msg := "BIOS configuration requires a reboot"
h.EventEmitter.Emit(event.ProvisioningEventPlannedReboot, msg)
h.log.Infow("bios", msg, "reboot in 1 sec")
h.log.Info("bios", msg, "reboot in 1 sec")
time.Sleep(1 * time.Second)
err = kernel.Reboot()
if err != nil {
Expand All @@ -45,7 +45,7 @@ func (h *Hammer) EnsureBootOrder(bootloaderID string) error {
if err != nil {
return err
}
h.log.Infow("bios", "message", "successfully ensured boot order")
h.log.Info("bios", "message", "successfully ensured boot order")

return nil
}
12 changes: 6 additions & 6 deletions cmd/event/event.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ package event
import (
"context"
"fmt"
"log/slog"
"time"

v1 "github.com/metal-stack/metal-api/pkg/api/v1"
"go.uber.org/zap"
"google.golang.org/protobuf/types/known/timestamppb"
)

Expand All @@ -30,12 +30,12 @@ const (
)

type EventEmitter struct {
log *zap.SugaredLogger
log *slog.Logger
eventClient v1.EventServiceClient
machineID string
}

func NewEventEmitter(log *zap.SugaredLogger, eventClient v1.EventServiceClient, machineID string) *EventEmitter {
func NewEventEmitter(log *slog.Logger, eventClient v1.EventServiceClient, machineID string) *EventEmitter {
emitter := &EventEmitter{
eventClient: eventClient,
machineID: machineID,
Expand All @@ -53,7 +53,7 @@ func NewEventEmitter(log *zap.SugaredLogger, eventClient v1.EventServiceClient,

func (e *EventEmitter) Emit(eventType ProvisioningEventType, message string) {
eventString := string(eventType)
e.log.Infow("event", "event", eventString, "message", message)
e.log.Info("event", "event", eventString, "message", message)
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
defer cancel()
s, err := e.eventClient.Send(ctx, &v1.EventServiceSendRequest{
Expand All @@ -66,9 +66,9 @@ func (e *EventEmitter) Emit(eventType ProvisioningEventType, message string) {
},
})
if err != nil {
e.log.Errorw("event", "cannot send event", eventType, "error", err)
e.log.Error("event", "cannot send event", eventType, "error", err)
}
if s != nil {
e.log.Infow("event", "send", s.Events, "failed", s.Failed)
e.log.Info("event", "send", s.Events, "failed", s.Failed)
}
}
17 changes: 8 additions & 9 deletions cmd/firmware/firmware.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@ package firmware

import (
"fmt"
"log/slog"
"os/exec"

"go.uber.org/zap"
)

// updater check if a firmware update is required and updates
Expand All @@ -19,11 +18,11 @@ type updater interface {
// Firmware take care of firmware management
type Firmware struct {
updaters []updater
log *zap.SugaredLogger
log *slog.Logger
}

// New create a new Firmware manager with all Updaters.
func New(log *zap.SugaredLogger) *Firmware {
func New(log *slog.Logger) *Firmware {

_ = raidcontroller{
name: "lsi3108",
Expand All @@ -46,31 +45,31 @@ func (f *Firmware) Update() {
for _, u := range f.updaters {
cv, err := u.current()
if err != nil {
f.log.Errorw("firmware", "unable to get current version", err)
f.log.Error("firmware", "unable to get current version", err)
continue
}
dv := u.desired()
f.log.Infow("firmware", "name", u, "current", cv, "desired", dv, "update required", u.updateRequired())
f.log.Info("firmware", "name", u, "current", cv, "desired", dv, "update required", u.updateRequired())
if !u.updateRequired() {
continue
}
err = u.update()
if err != nil {
f.log.Errorw("firmware", "unable to update", err)
f.log.Error("firmware", "unable to update", err)
continue
}
}
}

// Run execute a comand with arguments, returns output and error
func run(log *zap.SugaredLogger, command string, args ...string) (string, error) {
func run(log *slog.Logger, command string, args ...string) (string, error) {
path, err := exec.LookPath(command)
if err != nil {
return "", fmt.Errorf("unable to locate program:%s in path %w", command, err)
}
cmd := exec.Command(path, args...)
output, err := cmd.Output()

log.Debugw("run", "command", command, "args", args, "output", string(output), "error", err)
log.Debug("run", "command", command, "args", args, "output", string(output), "error", err)
return string(output), err
}
11 changes: 5 additions & 6 deletions cmd/firmware/intel.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,13 @@ package firmware

import (
"fmt"

"go.uber.org/zap"
"log/slog"
)

type intel struct {
name string
desiredVersion string
log *zap.SugaredLogger
log *slog.Logger
}

func (r intel) String() string {
Expand All @@ -23,12 +22,12 @@ func (r intel) update() error {
if err != nil {
return fmt.Errorf("unable to update intel firmware %w", err)
}
r.log.Infow("intel", "updated firware output", output)
r.log.Info("intel", "updated firware output", output)
return nil
}

func (r intel) current() (string, error) {
r.log.Infow("not implemented")
r.log.Info("not implemented")
return "", nil
}

Expand All @@ -37,6 +36,6 @@ func (r intel) desired() string {
}

func (r intel) updateRequired() bool {
r.log.Infow("not implemented")
r.log.Info("not implemented")
return true
}
6 changes: 2 additions & 4 deletions cmd/firmware/raid.go
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
package firmware

import (
"go.uber.org/zap"
)
import "log/slog"

type raidcontroller struct {
name string
desiredVersion string
log *zap.SugaredLogger
log *slog.Logger
}

func (r raidcontroller) String() string {
Expand Down
Loading
Loading