Skip to content
This repository has been archived by the owner on Jan 18, 2024. It is now read-only.

Commit

Permalink
Allow for customization of iPXE script URL: (#55)
Browse files Browse the repository at this point in the history
## Description


This allows consumers the ability to customize the iPXE script URL based on information in the DHCP packet. This flexibility will allow users to do things like host the iPXE script at dynamic URL path endpoints. for example /<mac address>/script.ipxe

## Why is this needed



Fixes: #

## How Has This Been Tested?





## How are existing users impacted? What migration steps/scripts do we need?





## Checklist:

I have:

- [ ] updated the documentation and/or roadmap (if required)
- [ ] added unit or e2e tests
- [ ] provided instructions on how to upgrade
  • Loading branch information
mergify[bot] authored Nov 2, 2023
2 parents aa8d083 + f4e77be commit 28d9c2f
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 8 deletions.
7 changes: 5 additions & 2 deletions example/fileBackend/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
"github.com/equinix-labs/otel-init-go/otelinit"
"github.com/go-logr/logr"
"github.com/go-logr/stdr"
"github.com/insomniacslk/dhcp/dhcpv4"
"github.com/insomniacslk/dhcp/dhcpv4/server4"
"github.com/tinkerbell/dhcp"
"github.com/tinkerbell/dhcp/backend/file"
Expand Down Expand Up @@ -43,8 +44,10 @@ func main() {
Netboot: reservation.Netboot{
IPXEBinServerTFTP: netip.MustParseAddrPort("192.168.1.34:69"),
IPXEBinServerHTTP: &url.URL{Scheme: "http", Host: "192.168.1.34:8080"},
IPXEScriptURL: &url.URL{Scheme: "https", Host: "boot.netboot.xyz"},
Enabled: true,
IPXEScriptURL: func(*dhcpv4.DHCPv4) *url.URL {
return &url.URL{Scheme: "https", Host: "boot.netboot.xyz"}
},
Enabled: true,
},
OTELEnabled: true,
Backend: backend,
Expand Down
7 changes: 5 additions & 2 deletions example/kubeBackend/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (

"github.com/equinix-labs/otel-init-go/otelinit"
"github.com/go-logr/stdr"
"github.com/insomniacslk/dhcp/dhcpv4"
"github.com/insomniacslk/dhcp/dhcpv4/server4"
"github.com/tinkerbell/dhcp"
"github.com/tinkerbell/dhcp/backend/kube"
Expand Down Expand Up @@ -44,8 +45,10 @@ func main() {
Netboot: reservation.Netboot{
IPXEBinServerTFTP: netip.MustParseAddrPort("192.168.2.50:69"),
IPXEBinServerHTTP: &url.URL{Scheme: "http", Host: "192.168.2.50:8080"},
IPXEScriptURL: &url.URL{Scheme: "http", Host: "192.168.2.50", Path: "auto.ipxe"},
Enabled: true,
IPXEScriptURL: func(*dhcpv4.DHCPv4) *url.URL {
return &url.URL{Scheme: "http", Host: "192.168.2.50", Path: "auto.ipxe"}
},
Enabled: true,
},
OTELEnabled: true,
Backend: backend,
Expand Down
5 changes: 4 additions & 1 deletion handler/reservation/option.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,10 @@ func (h *Handler) setNetworkBootOpts(ctx context.Context, m *dhcpv4.DHCPv4, n *d
return
}
uClass := UserClass(string(m.GetOneOption(dhcpv4.OptionUserClassInformation)))
ipxeScript := h.Netboot.IPXEScriptURL
var ipxeScript *url.URL
if h.Netboot.IPXEScriptURL != nil {
ipxeScript = h.Netboot.IPXEScriptURL(m)
}
if n.IPXEScriptURL != nil {
ipxeScript = n.IPXEScriptURL
}
Expand Down
8 changes: 6 additions & 2 deletions handler/reservation/option_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,9 @@ func TestSetNetworkBootOpts(t *testing.T) {
want: &dhcpv4.DHCPv4{ServerIPAddr: net.IPv4(0, 0, 0, 0), BootFileName: "/netboot-not-allowed"},
},
"netboot allowed": {
server: &Handler{Log: logr.Discard(), Netboot: Netboot{IPXEScriptURL: &url.URL{Scheme: "http", Host: "localhost:8181", Path: "/01:02:03:04:05:06/auto.ipxe"}}},
server: &Handler{Log: logr.Discard(), Netboot: Netboot{IPXEScriptURL: func(*dhcpv4.DHCPv4) *url.URL {
return &url.URL{Scheme: "http", Host: "localhost:8181", Path: "/01:02:03:04:05:06/auto.ipxe"}
}}},
args: args{
in0: context.Background(),
m: &dhcpv4.DHCPv4{
Expand All @@ -293,7 +295,9 @@ func TestSetNetworkBootOpts(t *testing.T) {
)},
},
"netboot not allowed, arch unknown": {
server: &Handler{Log: logr.Discard(), Netboot: Netboot{IPXEScriptURL: &url.URL{Scheme: "http", Host: "localhost:8181", Path: "/01:02:03:04:05:06/auto.ipxe"}}},
server: &Handler{Log: logr.Discard(), Netboot: Netboot{IPXEScriptURL: func(*dhcpv4.DHCPv4) *url.URL {
return &url.URL{Scheme: "http", Host: "localhost:8181", Path: "/01:02:03:04:05:06/auto.ipxe"}
}}},
args: args{
in0: context.Background(),
m: &dhcpv4.DHCPv4{
Expand Down
3 changes: 2 additions & 1 deletion handler/reservation/reservation.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"net/url"

"github.com/go-logr/logr"
"github.com/insomniacslk/dhcp/dhcpv4"
"github.com/tinkerbell/dhcp/handler"
)

Expand Down Expand Up @@ -45,7 +46,7 @@ type Netboot struct {
IPXEBinServerHTTP *url.URL

// IPXEScriptURL is the URL to the IPXE script to use.
IPXEScriptURL *url.URL
IPXEScriptURL func(*dhcpv4.DHCPv4) *url.URL

// Enabled is whether to enable sending netboot DHCP options.
Enabled bool
Expand Down

0 comments on commit 28d9c2f

Please sign in to comment.