Skip to content

Commit 1537aa2

Browse files
committed
Add support fuzzy UUID match for ignition
1 parent 68a4cc0 commit 1537aa2

File tree

1 file changed

+74
-0
lines changed

1 file changed

+74
-0
lines changed

server/bootserver.go

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import (
1111
"net/http"
1212
"path"
1313
"path/filepath"
14+
"sort"
1415
"strings"
1516
"text/template"
1617

@@ -104,6 +105,36 @@ func handleIPXE(w http.ResponseWriter, r *http.Request, k8sClient client.Client,
104105
return
105106
}
106107

108+
if len(ipxeBootConfigList.Items) == 0 {
109+
// Fuzzy segment-based match
110+
requestSegments := normalizeAndSortUUIDSegments(uuid)
111+
112+
allConfigs := &bootv1alpha1.IPXEBootConfigList{}
113+
if err := k8sClient.List(ctx, allConfigs); err != nil {
114+
http.Error(w, "Internal Server Error", http.StatusInternalServerError)
115+
log.Info("Failed to list IPXEBootConfigs for fuzzy match", "error", err.Error())
116+
return
117+
}
118+
119+
for _, cfg := range allConfigs.Items {
120+
cfgSegments := normalizeAndSortUUIDSegments(cfg.Spec.SystemUUID)
121+
if len(cfgSegments) != len(requestSegments) {
122+
continue
123+
}
124+
matched := true
125+
for i := range cfgSegments {
126+
if cfgSegments[i] != requestSegments[i] {
127+
matched = false
128+
break
129+
}
130+
}
131+
if matched {
132+
ipxeBootConfigList.Items = append(ipxeBootConfigList.Items, cfg)
133+
break
134+
}
135+
}
136+
}
137+
107138
config := ipxeBootConfigList.Items[0]
108139
if config.Spec.IPXEScriptSecretRef != nil {
109140
secret := &corev1.Secret{}
@@ -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+
139183
func 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

Comments
 (0)