@@ -11,6 +11,7 @@ import (
11
11
"net/http"
12
12
"path"
13
13
"path/filepath"
14
+ "sort"
14
15
"strings"
15
16
"text/template"
16
17
@@ -64,6 +65,36 @@ func RunBootServer(ipxeServerAddr string, ipxeServiceURL string, k8sClient clien
64
65
}
65
66
}
66
67
68
+ if len (ipxeBootConfigList .Items ) == 0 {
69
+ // Fuzzy segment-based match
70
+ requestSegments := normalizeAndSortUUIDSegments (uuid )
71
+
72
+ allConfigs := & bootv1alpha1.IPXEBootConfigList {}
73
+ if err := k8sClient .List (r .Context (), allConfigs ); err != nil {
74
+ http .Error (w , "Internal Server Error" , http .StatusInternalServerError )
75
+ log .Info ("Failed to list IPXEBootConfigs for fuzzy match" , "error" , err .Error ())
76
+ return
77
+ }
78
+
79
+ for _ , cfg := range allConfigs .Items {
80
+ cfgSegments := normalizeAndSortUUIDSegments (cfg .Spec .SystemUUID )
81
+ if len (cfgSegments ) != len (requestSegments ) {
82
+ continue
83
+ }
84
+ matched := true
85
+ for i := range cfgSegments {
86
+ if cfgSegments [i ] != requestSegments [i ] {
87
+ matched = false
88
+ break
89
+ }
90
+ }
91
+ if matched {
92
+ ipxeBootConfigList .Items = append (ipxeBootConfigList .Items , cfg )
93
+ break
94
+ }
95
+ }
96
+ }
97
+
67
98
if len (ipxeBootConfigList .Items ) == 0 {
68
99
log .Info ("No IPXEBootConfig found with given UUID. Trying HTTPBootConfig" )
69
100
handleIgnitionHTTPBoot (w , r , k8sClient , log , uuid )
@@ -98,6 +129,36 @@ func handleIPXE(w http.ResponseWriter, r *http.Request, k8sClient client.Client,
98
129
return
99
130
}
100
131
132
+ if len (ipxeBootConfigList .Items ) == 0 {
133
+ // Fuzzy segment-based match
134
+ requestSegments := normalizeAndSortUUIDSegments (uuid )
135
+
136
+ allConfigs := & bootv1alpha1.IPXEBootConfigList {}
137
+ if err := k8sClient .List (ctx , allConfigs ); err != nil {
138
+ http .Error (w , "Internal Server Error" , http .StatusInternalServerError )
139
+ log .Info ("Failed to list IPXEBootConfigs for fuzzy match" , "error" , err .Error ())
140
+ return
141
+ }
142
+
143
+ for _ , cfg := range allConfigs .Items {
144
+ cfgSegments := normalizeAndSortUUIDSegments (cfg .Spec .SystemUUID )
145
+ if len (cfgSegments ) != len (requestSegments ) {
146
+ continue
147
+ }
148
+ matched := true
149
+ for i := range cfgSegments {
150
+ if cfgSegments [i ] != requestSegments [i ] {
151
+ matched = false
152
+ break
153
+ }
154
+ }
155
+ if matched {
156
+ ipxeBootConfigList .Items = append (ipxeBootConfigList .Items , cfg )
157
+ break
158
+ }
159
+ }
160
+ }
161
+
101
162
if len (ipxeBootConfigList .Items ) == 0 {
102
163
log .Info ("No IPXEBootConfig found for the given UUID" )
103
164
http .Error (w , "Resource Not Found" , http .StatusNotFound )
@@ -136,6 +197,19 @@ func handleIPXE(w http.ResponseWriter, r *http.Request, k8sClient client.Client,
136
197
})
137
198
}
138
199
200
+ // TODO: Remove later
201
+ // Utility: normalize and sort each segment of UUID
202
+ func normalizeAndSortUUIDSegments (uuid string ) []string {
203
+ segments := strings .Split (strings .ToLower (uuid ), "-" )
204
+ sortedSegments := make ([]string , len (segments ))
205
+ for i , segment := range segments {
206
+ chars := strings .Split (segment , "" )
207
+ sort .Strings (chars )
208
+ sortedSegments [i ] = strings .Join (chars , "" )
209
+ }
210
+ return sortedSegments
211
+ }
212
+
139
213
func handleIgnitionIPXEBoot (w http.ResponseWriter , r * http.Request , k8sClient client.Client , log logr.Logger , uuid string ) {
140
214
log .Info ("Processing Ignition request" , "method" , r .Method , "path" , r .URL .Path , "clientIP" , r .RemoteAddr )
141
215
ctx := r .Context ()
@@ -165,6 +239,36 @@ func handleIgnitionIPXEBoot(w http.ResponseWriter, r *http.Request, k8sClient cl
165
239
}
166
240
}
167
241
242
+ if len (ipxeBootConfigList .Items ) == 0 {
243
+ // Fuzzy segment-based match
244
+ requestSegments := normalizeAndSortUUIDSegments (uuid )
245
+
246
+ allConfigs := & bootv1alpha1.IPXEBootConfigList {}
247
+ if err := k8sClient .List (ctx , allConfigs ); err != nil {
248
+ http .Error (w , "Internal Server Error" , http .StatusInternalServerError )
249
+ log .Info ("Failed to list IPXEBootConfigs for fuzzy match" , "error" , err .Error ())
250
+ return
251
+ }
252
+
253
+ for _ , cfg := range allConfigs .Items {
254
+ cfgSegments := normalizeAndSortUUIDSegments (cfg .Spec .SystemUUID )
255
+ if len (cfgSegments ) != len (requestSegments ) {
256
+ continue
257
+ }
258
+ matched := true
259
+ for i := range cfgSegments {
260
+ if cfgSegments [i ] != requestSegments [i ] {
261
+ matched = false
262
+ break
263
+ }
264
+ }
265
+ if matched {
266
+ ipxeBootConfigList .Items = append (ipxeBootConfigList .Items , cfg )
267
+ break
268
+ }
269
+ }
270
+ }
271
+
168
272
if len (ipxeBootConfigList .Items ) == 0 {
169
273
http .Error (w , "Resource Not Found" , http .StatusNotFound )
170
274
log .Info ("No IPXEBootConfig found with given UUID" )
0 commit comments