Skip to content
Open
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
104 changes: 104 additions & 0 deletions server/bootserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"net/http"
"path"
"path/filepath"
"sort"
"strings"
"text/template"

Expand Down Expand Up @@ -64,6 +65,36 @@ func RunBootServer(ipxeServerAddr string, ipxeServiceURL string, k8sClient clien
}
}

if len(ipxeBootConfigList.Items) == 0 {
// Fuzzy segment-based match
requestSegments := normalizeAndSortUUIDSegments(uuid)

allConfigs := &bootv1alpha1.IPXEBootConfigList{}
if err := k8sClient.List(r.Context(), allConfigs); err != nil {
http.Error(w, "Internal Server Error", http.StatusInternalServerError)
log.Info("Failed to list IPXEBootConfigs for fuzzy match", "error", err.Error())
return
}

for _, cfg := range allConfigs.Items {
cfgSegments := normalizeAndSortUUIDSegments(cfg.Spec.SystemUUID)
if len(cfgSegments) != len(requestSegments) {
continue
}
matched := true
for i := range cfgSegments {
if cfgSegments[i] != requestSegments[i] {
matched = false
break
}
}
if matched {
ipxeBootConfigList.Items = append(ipxeBootConfigList.Items, cfg)
break
}
}
}

if len(ipxeBootConfigList.Items) == 0 {
log.Info("No IPXEBootConfig found with given UUID. Trying HTTPBootConfig")
handleIgnitionHTTPBoot(w, r, k8sClient, log, uuid)
Expand Down Expand Up @@ -98,6 +129,36 @@ func handleIPXE(w http.ResponseWriter, r *http.Request, k8sClient client.Client,
return
}

if len(ipxeBootConfigList.Items) == 0 {
// Fuzzy segment-based match
requestSegments := normalizeAndSortUUIDSegments(uuid)

allConfigs := &bootv1alpha1.IPXEBootConfigList{}
if err := k8sClient.List(ctx, allConfigs); err != nil {
http.Error(w, "Internal Server Error", http.StatusInternalServerError)
log.Info("Failed to list IPXEBootConfigs for fuzzy match", "error", err.Error())
return
}

for _, cfg := range allConfigs.Items {
cfgSegments := normalizeAndSortUUIDSegments(cfg.Spec.SystemUUID)
if len(cfgSegments) != len(requestSegments) {
continue
}
matched := true
for i := range cfgSegments {
if cfgSegments[i] != requestSegments[i] {
matched = false
break
}
}
if matched {
ipxeBootConfigList.Items = append(ipxeBootConfigList.Items, cfg)
break
}
}
}

if len(ipxeBootConfigList.Items) == 0 {
log.Info("No IPXEBootConfig found for the given UUID")
http.Error(w, "Resource Not Found", http.StatusNotFound)
Expand Down Expand Up @@ -136,6 +197,19 @@ func handleIPXE(w http.ResponseWriter, r *http.Request, k8sClient client.Client,
})
}

// TODO: Remove later
// Utility: normalize and sort each segment of UUID
func normalizeAndSortUUIDSegments(uuid string) []string {
segments := strings.Split(strings.ToLower(uuid), "-")
sortedSegments := make([]string, len(segments))
for i, segment := range segments {
chars := strings.Split(segment, "")
sort.Strings(chars)
sortedSegments[i] = strings.Join(chars, "")
}
return sortedSegments
}

func handleIgnitionIPXEBoot(w http.ResponseWriter, r *http.Request, k8sClient client.Client, log logr.Logger, uuid string) {
log.Info("Processing Ignition request", "method", r.Method, "path", r.URL.Path, "clientIP", r.RemoteAddr)
ctx := r.Context()
Expand Down Expand Up @@ -165,6 +239,36 @@ func handleIgnitionIPXEBoot(w http.ResponseWriter, r *http.Request, k8sClient cl
}
}

if len(ipxeBootConfigList.Items) == 0 {
// Fuzzy segment-based match
requestSegments := normalizeAndSortUUIDSegments(uuid)

allConfigs := &bootv1alpha1.IPXEBootConfigList{}
if err := k8sClient.List(ctx, allConfigs); err != nil {
http.Error(w, "Internal Server Error", http.StatusInternalServerError)
log.Info("Failed to list IPXEBootConfigs for fuzzy match", "error", err.Error())
return
}

for _, cfg := range allConfigs.Items {
cfgSegments := normalizeAndSortUUIDSegments(cfg.Spec.SystemUUID)
if len(cfgSegments) != len(requestSegments) {
continue
}
matched := true
for i := range cfgSegments {
if cfgSegments[i] != requestSegments[i] {
matched = false
break
}
}
if matched {
ipxeBootConfigList.Items = append(ipxeBootConfigList.Items, cfg)
break
}
}
}

if len(ipxeBootConfigList.Items) == 0 {
http.Error(w, "Resource Not Found", http.StatusNotFound)
log.Info("No IPXEBootConfig found with given UUID")
Expand Down
Loading