Skip to content

Commit

Permalink
Add vlan_id and hw_addr to patched cmdline:
Browse files Browse the repository at this point in the history
These are needed for proper VLAN interface creation.

Signed-off-by: Jacob Weinstock <[email protected]>
  • Loading branch information
jacobweinstock committed Nov 23, 2024
1 parent ea85fe0 commit 60225de
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 7 deletions.
9 changes: 8 additions & 1 deletion internal/iso/iso.go
Original file line number Diff line number Diff line change
Expand Up @@ -257,9 +257,16 @@ func (h *Handler) constructPatch(console, mac string, d *data.DHCP) string {
grpcAuthority := fmt.Sprintf("grpc_authority=%s", h.TinkServerGRPCAddr)
tinkerbellTLS := fmt.Sprintf("tinkerbell_tls=%v", h.TinkServerTLS)
workerID := fmt.Sprintf("worker_id=%s", mac)
vlanID := func() string {
if d != nil {
return fmt.Sprintf("vlan_id=%s", d.VLANID)
}
return ""
}()
hwAddr := fmt.Sprintf("hw_addr=%s", mac)
ipam := parseIPAM(d)

return strings.Join([]string{strings.Join(h.ExtraKernelParams, " "), console, syslogHost, grpcAuthority, tinkerbellTLS, workerID, ipam}, " ")
return strings.Join([]string{strings.Join(h.ExtraKernelParams, " "), console, vlanID, hwAddr, syslogHost, grpcAuthority, tinkerbellTLS, workerID, ipam}, " ")
}

func getMAC(urlPath string) (net.HardwareAddr, error) {
Expand Down
14 changes: 8 additions & 6 deletions internal/iso/iso_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,13 +110,13 @@ func TestPatching(t *testing.T) {
// patch the ISO file
// mount the ISO file and check if the magic string was patched

// If anything changes here the space padding will be different. Be sure to update it accordingly.
wantGrubCfg := `set timeout=0
set gfxpayload=text
menuentry 'LinuxKit ISO Image' {
linuxefi /kernel facility=test console=ttyAMA0 console=ttyS0 console=tty0 console=tty1 console=ttyS1 syslog_host=127.0.0.1:514 grpc_authority=127.0.0.1:42113 tinkerbell_tls=false worker_id=de:ed:be:ef:fe:ed text
linuxefi /kernel facility=test console=ttyAMA0 console=ttyS0 console=tty0 console=tty1 console=ttyS1 hw_addr=de:ed:be:ef:fe:ed syslog_host=127.0.0.1:514 grpc_authority=127.0.0.1:42113 tinkerbell_tls=false worker_id=de:ed:be:ef:fe:ed text
initrdefi /initrd.img
}
`
}`
// This expects that testdata/output.iso exists. Run the TestCreateISO test to create it.

// serve it with a http server
Expand All @@ -141,6 +141,8 @@ menuentry 'LinuxKit ISO Image' {
parsedURL: parsedURL,
MagicString: magicString,
}
// for debugging enable a logger
// h.Logger = logr.FromSlogHandler(slog.NewTextHandler(os.Stdout, &slog.HandlerOptions{AddSource: true}))

rurl := hs.URL + "/iso/de:ed:be:ef:fe:ed/output.iso"
purl, _ := url.Parse(rurl)
Expand All @@ -164,14 +166,14 @@ menuentry 'LinuxKit ISO Image' {
t.Fatal(err)
}

idx := bytes.Index(isoContents, []byte(wantGrubCfg))
idx := bytes.Index(isoContents, []byte(`set timeout=0`))
if idx == -1 {
t.Fatalf("could not find grub.cfg in the ISO")
t.Fatalf("could not find the expected grub.cfg contents in the ISO")
}
contents := isoContents[idx : idx+len(wantGrubCfg)]

if diff := cmp.Diff(wantGrubCfg, string(contents)); diff != "" {
t.Fatalf("unexpected grub.cfg file: %s", diff)
t.Fatalf("patched grub.cfg contents don't match expected: %v", diff)
}
}

Expand Down

0 comments on commit 60225de

Please sign in to comment.