From a17c89d387eaa95120b57e3172532cbd019f90df Mon Sep 17 00:00:00 2001 From: Hardik Dodiya Date: Wed, 20 Aug 2025 10:54:50 +0200 Subject: [PATCH] Add support fuzzy UUID match for ignition --- server/bootserver.go | 104 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 104 insertions(+) diff --git a/server/bootserver.go b/server/bootserver.go index 0439277..3dd4aa1 100644 --- a/server/bootserver.go +++ b/server/bootserver.go @@ -11,6 +11,7 @@ import ( "net/http" "path" "path/filepath" + "sort" "strings" "text/template" @@ -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) @@ -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) @@ -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() @@ -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")