@@ -11,6 +11,7 @@ import (
1111 "net/http"
1212 "path"
1313 "path/filepath"
14+ "sort"
1415 "strings"
1516 "text/template"
1617
@@ -98,6 +99,36 @@ func handleIPXE(w http.ResponseWriter, r *http.Request, k8sClient client.Client,
9899 return
99100 }
100101
102+ if len (ipxeBootConfigList .Items ) == 0 {
103+ // Fuzzy segment-based match
104+ requestSegments := normalizeAndSortUUIDSegments (uuid )
105+
106+ allConfigs := & bootv1alpha1.IPXEBootConfigList {}
107+ if err := k8sClient .List (ctx , allConfigs ); err != nil {
108+ http .Error (w , "Internal Server Error" , http .StatusInternalServerError )
109+ log .Info ("Failed to list IPXEBootConfigs for fuzzy match" , "error" , err .Error ())
110+ return
111+ }
112+
113+ for _ , cfg := range allConfigs .Items {
114+ cfgSegments := normalizeAndSortUUIDSegments (cfg .Spec .SystemUUID )
115+ if len (cfgSegments ) != len (requestSegments ) {
116+ continue
117+ }
118+ matched := true
119+ for i := range cfgSegments {
120+ if cfgSegments [i ] != requestSegments [i ] {
121+ matched = false
122+ break
123+ }
124+ }
125+ if matched {
126+ ipxeBootConfigList .Items = append (ipxeBootConfigList .Items , cfg )
127+ break
128+ }
129+ }
130+ }
131+
101132 if len (ipxeBootConfigList .Items ) == 0 {
102133 log .Info ("No IPXEBootConfig found for the given UUID" )
103134 http .Error (w , "Resource Not Found" , http .StatusNotFound )
@@ -136,6 +167,19 @@ func handleIPXE(w http.ResponseWriter, r *http.Request, k8sClient client.Client,
136167 })
137168}
138169
170+ // TODO: Remove later
171+ // Utility: normalize and sort each segment of UUID
172+ func normalizeAndSortUUIDSegments (uuid string ) []string {
173+ segments := strings .Split (strings .ToLower (uuid ), "-" )
174+ sortedSegments := make ([]string , len (segments ))
175+ for i , segment := range segments {
176+ chars := strings .Split (segment , "" )
177+ sort .Strings (chars )
178+ sortedSegments [i ] = strings .Join (chars , "" )
179+ }
180+ return sortedSegments
181+ }
182+
139183func handleIgnitionIPXEBoot (w http.ResponseWriter , r * http.Request , k8sClient client.Client , log logr.Logger , uuid string ) {
140184 log .Info ("Processing Ignition request" , "method" , r .Method , "path" , r .URL .Path , "clientIP" , r .RemoteAddr )
141185 ctx := r .Context ()
@@ -165,6 +209,36 @@ func handleIgnitionIPXEBoot(w http.ResponseWriter, r *http.Request, k8sClient cl
165209 }
166210 }
167211
212+ if len (ipxeBootConfigList .Items ) == 0 {
213+ // Fuzzy segment-based match
214+ requestSegments := normalizeAndSortUUIDSegments (uuid )
215+
216+ allConfigs := & bootv1alpha1.IPXEBootConfigList {}
217+ if err := k8sClient .List (ctx , allConfigs ); err != nil {
218+ http .Error (w , "Internal Server Error" , http .StatusInternalServerError )
219+ log .Info ("Failed to list IPXEBootConfigs for fuzzy match" , "error" , err .Error ())
220+ return
221+ }
222+
223+ for _ , cfg := range allConfigs .Items {
224+ cfgSegments := normalizeAndSortUUIDSegments (cfg .Spec .SystemUUID )
225+ if len (cfgSegments ) != len (requestSegments ) {
226+ continue
227+ }
228+ matched := true
229+ for i := range cfgSegments {
230+ if cfgSegments [i ] != requestSegments [i ] {
231+ matched = false
232+ break
233+ }
234+ }
235+ if matched {
236+ ipxeBootConfigList .Items = append (ipxeBootConfigList .Items , cfg )
237+ break
238+ }
239+ }
240+ }
241+
168242 if len (ipxeBootConfigList .Items ) == 0 {
169243 http .Error (w , "Resource Not Found" , http .StatusNotFound )
170244 log .Info ("No IPXEBootConfig found with given UUID" )
0 commit comments