Skip to content

Commit ad8e4bf

Browse files
committed
address review comments
1 parent 5f1ed3f commit ad8e4bf

File tree

2 files changed

+17
-4
lines changed

2 files changed

+17
-4
lines changed

internal/controller/server_controller.go

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -937,7 +937,9 @@ func (r *ServerReconciler) patchServerURI(ctx context.Context, bmcClient bmc.BMC
937937
}
938938

939939
// Try to find system by UUID if one is provided
940-
if len(server.Spec.SystemUUID) > 0 {
940+
uuidProvided := len(server.Spec.SystemUUID) > 0
941+
uuidMatched := false
942+
if uuidProvided {
941943
for _, system := range systems {
942944
if strings.EqualFold(system.UUID, server.Spec.SystemUUID) {
943945
serverBase := server.DeepCopy()
@@ -948,11 +950,22 @@ func (r *ServerReconciler) patchServerURI(ctx context.Context, bmcClient bmc.BMC
948950
return true, nil
949951
}
950952
}
953+
// UUID was provided but didn't match any system
954+
uuidMatched = false
951955
}
952956

953957
// If no system found by UUID or UUID is empty, and we only have one system, use it
954958
// This handles cases where the Redfish implementation doesn't provide System.UUID
955959
if len(systems) == 1 {
960+
// If a UUID was provided but didn't match the only available system, report an error
961+
if uuidProvided && !uuidMatched {
962+
system := systems[0]
963+
log.V(1).Info("Provided SystemUUID does not match the only available system",
964+
"requestedUUID", server.Spec.SystemUUID, "systemUUID", system.UUID, "systemSerialNumber", system.SerialNumber)
965+
return false, fmt.Errorf("provided SystemUUID %q does not match the only available system (UUID: %q, SerialNumber: %q); check your configuration",
966+
server.Spec.SystemUUID, system.UUID, system.SerialNumber)
967+
}
968+
956969
system := systems[0]
957970
serverBase := server.DeepCopy()
958971
server.Spec.SystemURI = system.URI

internal/controller/server_controller_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -977,7 +977,7 @@ var _ = Describe("generatePseudoUUID", func() {
977977
}
978978
})
979979

980-
It("Should generate deterministic UUIDs", func() {
980+
It("Should generate UUIDs that are deterministic", func() {
981981
serial := "TEST-SERIAL-12345"
982982
uuid1 := generatePseudoUUID(serial)
983983
uuid2 := generatePseudoUUID(serial)
@@ -986,7 +986,7 @@ var _ = Describe("generatePseudoUUID", func() {
986986
"Same serial should always produce same UUID")
987987
})
988988

989-
It("Should generate unique UUIDs for different inputs", func() {
989+
It("Should generate UUIDs that are unique for different inputs", func() {
990990
serials := []string{"SN001", "SN002", "SN003", "SN004", "SN005"}
991991
uuids := make(map[string]bool)
992992

@@ -1000,7 +1000,7 @@ var _ = Describe("generatePseudoUUID", func() {
10001000
Expect(uuids).To(HaveLen(len(serials)))
10011001
})
10021002

1003-
It("Should handle varying lengths and complexity", func() {
1003+
It("Should generate UUIDs that handle serials of varying length and complexity", func() {
10041004
testCases := []string{
10051005
"X", // minimal
10061006
"SHORT", // short

0 commit comments

Comments
 (0)