Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
1 change: 1 addition & 0 deletions api/v1alpha1/ipxebootconfig_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ type IPXEBootConfigSpec struct {
KernelURL string `json:"kernelURL,omitempty"`
InitrdURL string `json:"initrdURL,omitempty"`
SquashfsURL string `json:"squashfsURL,omitempty"`
IPXEServerURL string `json:"ipxeServerURL,omitempty"`
IgnitionSecretRef *corev1.LocalObjectReference `json:"ignitionSecretRef,omitempty"`
}

Expand Down
15 changes: 14 additions & 1 deletion cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ func init() {

func main() {
ctx := ctrl.LoggerInto(ctrl.SetupSignalHandler(), setupLog)
defaultIpxeTemplateData := NewDefaultIPXETemplateData()

var metricsAddr string
var enableLeaderElection bool
Expand All @@ -70,6 +71,7 @@ func main() {
var enableHTTP2 bool
var ipxeServerAddr string
var imageProxyServerAddr string

flag.StringVar(&metricsAddr, "metrics-bind-address", ":8080", "The address the metric endpoint binds to.")
flag.StringVar(&probeAddr, "health-probe-bind-address", ":8081", "The address the probe endpoint binds to.")
flag.StringVar(&ipxeServerAddr, "ipxe-server-address", ":8082", "The address the ipxe-server binds to.")
Expand Down Expand Up @@ -166,7 +168,7 @@ func main() {
}

setupLog.Info("starting ipxe-server")
go ipxeserver.RunIPXEServer(ipxeServerAddr, mgr.GetClient(), serverLog.WithName("ipxeserver"))
go ipxeserver.RunIPXEServer(ipxeServerAddr, mgr.GetClient(), serverLog.WithName("ipxeserver"), *defaultIpxeTemplateData)

setupLog.Info("starting image-proxy-server")
go ipxeserver.RunImageProxyServer(imageProxyServerAddr, mgr.GetClient(), serverLog.WithName("imageproxyserver"))
Expand Down Expand Up @@ -200,3 +202,14 @@ func IndexIPXEBootConfigBySystemIP(ctx context.Context, mgr ctrl.Manager) error
},
)
}

func NewDefaultIPXETemplateData() *ipxeserver.IPXETemplateData {
var cfg ipxeserver.IPXETemplateData
flag.StringVar(&cfg.KernelURL, "default-kernel-url", "", "Default URL for the kernel")
flag.StringVar(&cfg.InitrdURL, "default-initrd-url", "", "Default URL for the initrd")
flag.StringVar(&cfg.SquashfsURL, "default-squashfs-url", "", "Default URL for the squashfs")
flag.StringVar(&cfg.IPXEServerURL, "default-ipxe-server-url", "", "Default IPXE Server URL to while generating ipxe-script")
flag.Parse()

return &cfg
}
30 changes: 14 additions & 16 deletions server/ipxeserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,12 @@ type IPXETemplateData struct {
InitrdURL string
SquashfsURL string
RegistryURL string
IpxeServerURL string
IPXEServerURL string
}

func RunIPXEServer(ipxeServerAddr string, k8sClient client.Client, log logr.Logger) {
func RunIPXEServer(ipxeServerAddr string, k8sClient client.Client, log logr.Logger, defaultIpxeTemplateData IPXETemplateData) {
http.HandleFunc("/ipxe", func(w http.ResponseWriter, r *http.Request) {
handleIPXE(w, r, k8sClient, ipxeServerAddr, log)
handleIPXE(w, r, k8sClient, log, defaultIpxeTemplateData)
})

http.HandleFunc("/ignition/", func(w http.ResponseWriter, r *http.Request) {
Expand All @@ -41,7 +41,7 @@ func RunIPXEServer(ipxeServerAddr string, k8sClient client.Client, log logr.Logg
}
}

func handleIPXE(w http.ResponseWriter, r *http.Request, k8sClient client.Client, ipxeServerAddr string, log logr.Logger) {
func handleIPXE(w http.ResponseWriter, r *http.Request, k8sClient client.Client, log logr.Logger, defaultIpxeTemplateData IPXETemplateData) {
log.Info("Processing IPXE request", "method", r.Method, "path", r.URL.Path, "clientIP", r.RemoteAddr)
ctx := r.Context()

Expand All @@ -59,14 +59,19 @@ func handleIPXE(w http.ResponseWriter, r *http.Request, k8sClient client.Client,
return
}

data := defaultIpxeTemplateData
if len(ipxeConfigs.Items) == 0 {
log.Info("No IPXEBootConfig found for client IP", "clientIP", clientIP)
http.NotFound(w, r)
return
log.Info("No IPXEBootConfig found for client IP, delivering default script", "clientIP", clientIP)
} else {
config := ipxeConfigs.Items[0]
data = IPXETemplateData{
KernelURL: config.Spec.KernelURL,
InitrdURL: config.Spec.InitrdURL,
SquashfsURL: config.Spec.SquashfsURL,
IPXEServerURL: config.Spec.IPXEServerURL,
}
}

config := ipxeConfigs.Items[0]

tmplPath := filepath.Join("templates", "ipxe-script.tpl")
tmpl, err := template.ParseFiles(tmplPath)
if err != nil {
Expand All @@ -75,13 +80,6 @@ func handleIPXE(w http.ResponseWriter, r *http.Request, k8sClient client.Client,
return
}

data := IPXETemplateData{
KernelURL: config.Spec.KernelURL,
InitrdURL: config.Spec.InitrdURL,
SquashfsURL: config.Spec.SquashfsURL,
IpxeServerURL: ipxeServerAddr,
}

if err := tmpl.Execute(w, data); err != nil {
log.Info("Failed to execute template", "error", err)
http.Error(w, "Internal Server Error", http.StatusInternalServerError)
Expand Down
4 changes: 2 additions & 2 deletions templates/ipxe-script.tpl
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
#!ipxe

set ipxe-svc {{.IpxeServerURL}}/ignition
set ipxe-svc {{.IPXEServerURL}}
set kernel-url {{.KernelURL}}
set initrd-url {{.InitrdURL}}
set squashfs-url {{.SquashfsURL}}


kernel ${kernel-url} initrd=rootfs.initrd gl.ovl=/:tmpfs gl.url=${squashfs-url} gl.live=1 ip=dhcp6 ignition.firstboot=1 ignition.config.url=${ipxe-svc}/${uuid} ignition.platform.id=metal console=ttyS0,115200 console=tty0 earlyprintk=ttyS0,115200 consoleblank=0
kernel ${kernel-url} initrd=rootfs.initrd gl.ovl=/:tmpfs gl.url=${squashfs-url} gl.live=1 ip=dhcp6 ignition.firstboot=1 ignition.config.url=${ipxe-svc}/ignition/${uuid} ignition.platform.id=metal console=ttyS0,115200 console=tty0 earlyprintk=ttyS0,115200 consoleblank=0
initrd ${initrd-url}
boot