Skip to content

Commit

Permalink
fix: wait for link up in iPXE script
Browse files Browse the repository at this point in the history
This avoids a hard failure to do `dhcp` on a downed interface.

Also refactor things and replace old boot script (used when not embedded
into the iPXE binary) to be same as new script to have less maintenance.

Signed-off-by: Andrey Smirnov <andrey.smirnov@talos-systems.com>
  • Loading branch information
smira committed Dec 13, 2021
1 parent 9a27861 commit 189793e
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 14 deletions.
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ TEST_PKGS ?= ./...
TALOS_RELEASE ?= v0.14.0-alpha.2
DEFAULT_K8S_VERSION ?= v1.22.3

TOOLS ?= ghcr.io/talos-systems/tools:v0.8.0
PKGS ?= v0.8.0
TOOLS ?= ghcr.io/talos-systems/tools:v0.9.0
PKGS ?= v0.10.0-alpha.0-1-gb22723d

SFYRA_CLUSTERCTL_CONFIG ?= $(HOME)/.cluster-api/clusterctl.sfyra.yaml

Expand Down
2 changes: 1 addition & 1 deletion app/sidero-controller-manager/internal/api/api.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion app/sidero-controller-manager/internal/api/api_grpc.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 6 additions & 10 deletions app/sidero-controller-manager/internal/ipxe/ipxe_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,8 @@ import (

var ErrBootFromDisk = errors.New("boot from disk")

// bootFile is used when iPXE is booted without embedded script via iPXE request http://endpoint:8081/boot.ipxe.
const bootFile = `#!ipxe
chain ipxe?uuid=${uuid}&mac=${mac:hexhyp}&domain=${domain}&hostname=${hostname}&serial=${serial}&arch=${buildarch}
`

// BootTemplate is embedded into iPXE binary when that binary is sent to the node.
var BootTemplate = template.Must(template.New("iPXE embedded").Parse(`
var BootTemplate = template.Must(template.New("iPXE embedded").Parse(`#!ipxe
prompt --key 0x02 --timeout 2000 Press Ctrl-B for the iPXE command line... && shell ||
# print interfaces
Expand All @@ -56,10 +51,11 @@ set x:int32 0
set idx:int32 0
:loop
# try DHCP on each available interface
# try DHCP on each interface
isset ${net${idx}/mac} || goto exhausted
ifclose
iflinkwait --timeout 5000 net${idx} || goto next_iface
dhcp net${idx} && goto boot
:next_iface
Expand Down Expand Up @@ -128,7 +124,7 @@ var (
)

func bootFileHandler(w http.ResponseWriter, r *http.Request) {
fmt.Fprint(w, bootFile)
fmt.Fprint(w, embeddedScriptBuf.Bytes())
}

//nolint:unparam
Expand Down Expand Up @@ -231,15 +227,15 @@ func ipxeHandler(w http.ResponseWriter, r *http.Request) {
}
}

var embeddedScriptBuf bytes.Buffer

func RegisterIPXE(mux *http.ServeMux, endpoint string, port int, args string, bootMethod BootFromDisk, iPXEPort int, mgrClient client.Client) error {
apiEndpoint = endpoint
apiPort = port
extraAgentKernelArgs = args
defaultBootFromDiskMethod = bootMethod
c = mgrClient

var embeddedScriptBuf bytes.Buffer

if err := BootTemplate.Execute(&embeddedScriptBuf, map[string]string{
"Endpoint": apiEndpoint,
"Port": strconv.Itoa(iPXEPort),
Expand Down

0 comments on commit 189793e

Please sign in to comment.