Skip to content

Commit

Permalink
Add systemUUID to Server CRD
Browse files Browse the repository at this point in the history
  • Loading branch information
Nuckal777 committed Dec 5, 2024
1 parent 790e54c commit d021129
Show file tree
Hide file tree
Showing 8 changed files with 70 additions and 31 deletions.
4 changes: 4 additions & 0 deletions api/v1alpha1/server_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,12 @@ type BIOSSettings struct {
// ServerSpec defines the desired state of a Server.
type ServerSpec struct {
// UUID is the unique identifier for the server.
// Deprecated in favor of systemUUID.
UUID string `json:"uuid"`

// SystemUUID is the unique identifier for the server.
SystemUUID string `json:"systemUUID,omitempty"`

// Power specifies the desired power state of the server.
Power Power `json:"power,omitempty"`

Expand Down
7 changes: 6 additions & 1 deletion config/crd/bases/metal.ironcore.dev_servers.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -271,8 +271,13 @@ spec:
type: string
type: object
x-kubernetes-map-type: atomic
systemUUID:
description: SystemUUID is the unique identifier for the server.
type: string
uuid:
description: UUID is the unique identifier for the server.
description: |-
UUID is the unique identifier for the server.
Deprecated in favor of systemUUID.
type: string
required:
- uuid
Expand Down
30 changes: 27 additions & 3 deletions docs/api-reference/api.md
Original file line number Diff line number Diff line change
Expand Up @@ -1215,7 +1215,19 @@ string
</em>
</td>
<td>
<p>UUID is the unique identifier for the server.</p>
<p>UUID is the unique identifier for the server.
Deprecated in favor of systemUUID.</p>
</td>
</tr>
<tr>
<td>
<code>systemUUID</code><br/>
<em>
string
</em>
</td>
<td>
<p>SystemUUID is the unique identifier for the server.</p>
</td>
</tr>
<tr>
Expand Down Expand Up @@ -1851,7 +1863,19 @@ string
</em>
</td>
<td>
<p>UUID is the unique identifier for the server.</p>
<p>UUID is the unique identifier for the server.
Deprecated in favor of systemUUID.</p>
</td>
</tr>
<tr>
<td>
<code>systemUUID</code><br/>
<em>
string
</em>
</td>
<td>
<p>SystemUUID is the unique identifier for the server.</p>
</td>
</tr>
<tr>
Expand Down Expand Up @@ -2119,7 +2143,7 @@ k8s.io/apimachinery/pkg/api/resource.Quantity
</em>
</td>
<td>
<p>TotalSystemMemoryBytes is the total amount of memory in bytes available on the server.</p>
<p>TotalSystemMemory is the total amount of memory in bytes available on the server.</p>
</td>
</tr>
<tr>
Expand Down
5 changes: 3 additions & 2 deletions internal/controller/bmc_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -169,8 +169,9 @@ func (r *BMCReconciler) discoverServers(ctx context.Context, log logr.Logger, bm
Name: GetServerNameFromBMCandIndex(i, bmcObj),
},
Spec: metalv1alpha1.ServerSpec{
UUID: strings.ToLower(s.UUID), // always use lower-case uuids
BMCRef: &v1.LocalObjectReference{Name: bmcObj.Name},
UUID: strings.ToLower(s.UUID), // always use lower-case uuids
SystemUUID: strings.ToLower(s.UUID), // always use lower-case uuids
BMCRef: &v1.LocalObjectReference{Name: bmcObj.Name},
},
}

Expand Down
2 changes: 2 additions & 0 deletions internal/controller/bmc_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ var _ = Describe("BMC Controller", func() {
BlockOwnerDeletion: ptr.To(true),
})),
HaveField("Spec.UUID", "38947555-7742-3448-3784-823347823834"),
HaveField("Spec.SystemUUID", "38947555-7742-3448-3784-823347823834"),
HaveField("Spec.BMCRef.Name", endpoint.Name),
))
})
Expand Down Expand Up @@ -150,6 +151,7 @@ var _ = Describe("BMC Controller", func() {
BlockOwnerDeletion: ptr.To(true),
})),
HaveField("Spec.UUID", "38947555-7742-3448-3784-823347823834"),
HaveField("Spec.SystemUUID", "38947555-7742-3448-3784-823347823834"),
HaveField("Spec.BMCRef.Name", bmc.Name),
))
})
Expand Down
38 changes: 19 additions & 19 deletions internal/controller/server_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@ func (r *ServerReconciler) handleDiscoveryState(ctx context.Context, log logr.Lo
if err != nil {
return false, fmt.Errorf("failed to create BMC client: %w", err)
}
storages, err := bmcClient.GetStorages(ctx, server.Spec.UUID)
storages, err := bmcClient.GetStorages(ctx, server.Spec.SystemUUID)
if err != nil {
return false, fmt.Errorf("failed to get storages for Server: %w", err)
}
Expand Down Expand Up @@ -422,7 +422,7 @@ func (r *ServerReconciler) updateServerStatus(ctx context.Context, log logr.Logg
}
defer bmcClient.Logout()

systemInfo, err := bmcClient.GetSystemInfo(ctx, server.Spec.UUID)
systemInfo, err := bmcClient.GetSystemInfo(ctx, server.Spec.SystemUUID)
if err != nil {
return fmt.Errorf("failed to get system info for Server: %w", err)
}
Expand All @@ -436,7 +436,7 @@ func (r *ServerReconciler) updateServerStatus(ctx context.Context, log logr.Logg
server.Status.IndicatorLED = metalv1alpha1.IndicatorLED(systemInfo.IndicatorLED)
server.Status.TotalSystemMemory = &systemInfo.TotalSystemMemory

currentBiosVersion, err := bmcClient.GetBiosVersion(ctx, server.Spec.UUID)
currentBiosVersion, err := bmcClient.GetBiosVersion(ctx, server.Spec.SystemUUID)
if err != nil {
return fmt.Errorf("failed to load bios version: %w", err)
}
Expand All @@ -448,7 +448,7 @@ func (r *ServerReconciler) updateServerStatus(ctx context.Context, log logr.Logg
for k := range bios.Settings {
keys = append(keys, k)
}
attributes, err := bmcClient.GetBiosAttributeValues(ctx, server.Spec.UUID, keys)
attributes, err := bmcClient.GetBiosAttributeValues(ctx, server.Spec.SystemUUID, keys)
if err != nil {
return fmt.Errorf("failed load bios settings: %w", err)
}
Expand Down Expand Up @@ -507,7 +507,7 @@ func (r *ServerReconciler) applyBootConfigurationAndIgnitionForDiscovery(ctx con
}

func (r *ServerReconciler) applyDefaultIgnitionForServer(ctx context.Context, log logr.Logger, server *metalv1alpha1.Server, bootConfig *metalv1alpha1.ServerBootConfiguration, registryURL string) error {
probeFlags := fmt.Sprintf("--registry-url=%s --server-uuid=%s", registryURL, server.Spec.UUID)
probeFlags := fmt.Sprintf("--registry-url=%s --server-uuid=%s", registryURL, server.Spec.SystemUUID)
ignitionData, err := r.generateDefaultIgnitionDataForServer(probeFlags)
if err != nil {
return fmt.Errorf("failed to generate default ignitionSecret data: %w", err)
Expand Down Expand Up @@ -625,14 +625,14 @@ func (r *ServerReconciler) pxeBootServer(ctx context.Context, log logr.Logger, s
if err != nil {
return fmt.Errorf("failed to get BMC client: %w", err)
}
if err := bmcClient.SetPXEBootOnce(ctx, server.Spec.UUID); err != nil {
if err := bmcClient.SetPXEBootOnce(ctx, server.Spec.SystemUUID); err != nil {
return fmt.Errorf("failed to set PXE boot one for server: %w", err)
}
return nil
}

func (r *ServerReconciler) extractServerDetailsFromRegistry(ctx context.Context, log logr.Logger, server *metalv1alpha1.Server) (bool, error) {
resp, err := http.Get(fmt.Sprintf("%s/systems/%s", r.RegistryURL, server.Spec.UUID))
resp, err := http.Get(fmt.Sprintf("%s/systems/%s", r.RegistryURL, server.Spec.SystemUUID))
if resp != nil && resp.StatusCode == http.StatusNotFound {
log.V(1).Info("Did not find server information in registry")
return false, nil
Expand Down Expand Up @@ -718,29 +718,29 @@ func (r *ServerReconciler) ensureServerPowerState(ctx context.Context, log logr.

switch powerOp {
case powerOpOn:
if err := bmcClient.PowerOn(ctx, server.Spec.UUID); err != nil {
if err := bmcClient.PowerOn(ctx, server.Spec.SystemUUID); err != nil {
return fmt.Errorf("failed to power on server: %w", err)
}
if err := bmcClient.WaitForServerPowerState(
ctx, server.Spec.UUID,
ctx, server.Spec.SystemUUID,
redfish.OnPowerState,
); err != nil {
return fmt.Errorf("failed to wait for server power on server: %w", err)
}
case powerOpOff:
powerOffType := bmcClient.PowerOff

if err := powerOffType(ctx, server.Spec.UUID); err != nil {
if err := powerOffType(ctx, server.Spec.SystemUUID); err != nil {
return fmt.Errorf("failed to power off server: %w", err)
}
if err := bmcClient.WaitForServerPowerState(ctx, server.Spec.UUID, redfish.OffPowerState); err != nil {
if err := bmcClient.WaitForServerPowerState(ctx, server.Spec.SystemUUID, redfish.OffPowerState); err != nil {
if r.EnforcePowerOff {
log.V(1).Info("Failed to wait for server graceful shutdown, retrying with force power off")
powerOffType = bmcClient.ForcePowerOff
if err := powerOffType(ctx, server.Spec.UUID); err != nil {
if err := powerOffType(ctx, server.Spec.SystemUUID); err != nil {
return fmt.Errorf("failed to power off server: %w", err)
}
if err := bmcClient.WaitForServerPowerState(ctx, server.Spec.UUID, redfish.OffPowerState); err != nil {
if err := bmcClient.WaitForServerPowerState(ctx, server.Spec.SystemUUID, redfish.OffPowerState); err != nil {
return fmt.Errorf("failed to wait for server force power off: %w", err)
}
} else {
Expand Down Expand Up @@ -787,7 +787,7 @@ func (r *ServerReconciler) ensureInitialBootConfigurationIsDeleted(ctx context.C
}

func (r *ServerReconciler) invalidateRegistryEntryForServer(log logr.Logger, server *metalv1alpha1.Server) error {
url := fmt.Sprintf("%s/delete/%s", r.RegistryURL, server.Spec.UUID)
url := fmt.Sprintf("%s/delete/%s", r.RegistryURL, server.Spec.SystemUUID)

c := &http.Client{}

Expand Down Expand Up @@ -822,7 +822,7 @@ func (r *ServerReconciler) applyBootOrder(ctx context.Context, log logr.Logger,
}
defer bmcClient.Logout()

order, err := bmcClient.GetBootOrder(ctx, server.Spec.UUID)
order, err := bmcClient.GetBootOrder(ctx, server.Spec.SystemUUID)
if err != nil {
return fmt.Errorf("failed to create BMC client: %w", err)
}
Expand All @@ -839,7 +839,7 @@ func (r *ServerReconciler) applyBootOrder(ctx context.Context, log logr.Logger,
}
}
if change {
return bmcClient.SetBootOrder(ctx, server.Spec.UUID, newOrder)
return bmcClient.SetBootOrder(ctx, server.Spec.SystemUUID, newOrder)
}
return nil
}
Expand All @@ -856,7 +856,7 @@ func (r *ServerReconciler) applyBiosSettings(ctx context.Context, log logr.Logge
}
defer bmcClient.Logout()

version, err := bmcClient.GetBiosVersion(ctx, server.Spec.UUID)
version, err := bmcClient.GetBiosVersion(ctx, server.Spec.SystemUUID)
if err != nil {
return fmt.Errorf("failed to create BMC client: %w", err)
}
Expand All @@ -873,7 +873,7 @@ func (r *ServerReconciler) applyBiosSettings(ctx context.Context, log logr.Logge
}
}
}
reset, err := bmcClient.SetBiosAttributes(ctx, server.Spec.UUID, diff)
reset, err := bmcClient.SetBiosAttributes(ctx, server.Spec.SystemUUID, diff)
if err != nil {
return err
}
Expand Down Expand Up @@ -908,7 +908,7 @@ func (r *ServerReconciler) handleAnnotionOperations(ctx context.Context, log log
}
defer bmcClient.Logout()
log.V(1).Info("Handling operation", "Operation", operation)
if err := bmcClient.Reset(ctx, server.Spec.UUID, redfish.ResetType(operation)); err != nil {
if err := bmcClient.Reset(ctx, server.Spec.SystemUUID, redfish.ResetType(operation)); err != nil {
return false, fmt.Errorf("failed to reset server: %w", err)
}
log.V(1).Info("Operation completed", "Operation", operation)
Expand Down
12 changes: 7 additions & 5 deletions internal/controller/server_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ var _ = Describe("Server Controller", func() {
BlockOwnerDeletion: ptr.To(true),
})),
HaveField("Spec.UUID", "38947555-7742-3448-3784-823347823834"),
HaveField("Spec.SystemUUID", "38947555-7742-3448-3784-823347823834"),
HaveField("Spec.Power", metalv1alpha1.PowerOff),
HaveField("Spec.IndicatorLED", metalv1alpha1.IndicatorLED("")),
HaveField("Spec.ServerClaimRef", BeNil()),
Expand Down Expand Up @@ -150,7 +151,7 @@ var _ = Describe("Server Controller", func() {
))

By("Starting the probe agent")
probeAgent := probe.NewAgent(server.Spec.UUID, registryURL, 100*time.Millisecond)
probeAgent := probe.NewAgent(server.Spec.SystemUUID, registryURL, 100*time.Millisecond)
go func() {
defer GinkgoRecover()
Expect(probeAgent.Start(ctx)).To(Succeed(), "failed to start probe agent")
Expand All @@ -168,7 +169,7 @@ var _ = Describe("Server Controller", func() {
Consistently(Get(bootConfig)).Should(Satisfy(apierrors.IsNotFound))

By("Ensuring that the server is removed from the registry")
response, err := http.Get(registryURL + "/systems/" + server.Spec.UUID)
response, err := http.Get(registryURL + "/systems/" + server.Spec.SystemUUID)
Expect(err).NotTo(HaveOccurred())
Expect(response.StatusCode).To(Equal(http.StatusNotFound))
})
Expand All @@ -193,7 +194,8 @@ var _ = Describe("Server Controller", func() {
GenerateName: "server-",
},
Spec: metalv1alpha1.ServerSpec{
UUID: "38947555-7742-3448-3784-823347823834",
UUID: "38947555-7742-3448-3784-823347823834",
SystemUUID: "38947555-7742-3448-3784-823347823834",
BMC: &metalv1alpha1.BMCAccess{
Protocol: metalv1alpha1.Protocol{
Name: metalv1alpha1.ProtocolRedfishLocal,
Expand Down Expand Up @@ -275,7 +277,7 @@ var _ = Describe("Server Controller", func() {
))

By("Starting the probe agent")
probeAgent := probe.NewAgent(server.Spec.UUID, registryURL, 50*time.Millisecond)
probeAgent := probe.NewAgent(server.Spec.SystemUUID, registryURL, 50*time.Millisecond)
go func() {
defer GinkgoRecover()
Expect(probeAgent.Start(ctx)).To(Succeed(), "failed to start probe agent")
Expand Down Expand Up @@ -327,7 +329,7 @@ var _ = Describe("Server Controller", func() {
Consistently(Get(bootConfig)).Should(Satisfy(apierrors.IsNotFound))

By("Ensuring that the server is removed from the registry")
response, err := http.Get(registryURL + "/systems/" + server.Spec.UUID)
response, err := http.Get(registryURL + "/systems/" + server.Spec.SystemUUID)
Expect(err).NotTo(HaveOccurred())
Expect(response.StatusCode).To(Equal(http.StatusNotFound))
})
Expand Down
3 changes: 2 additions & 1 deletion internal/controller/serverclaim_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@ var _ = Describe("ServerClaim Controller", func() {
GenerateName: "test-",
},
Spec: metalv1alpha1.ServerSpec{
UUID: "38947555-7742-3448-3784-823347823834",
UUID: "38947555-7742-3448-3784-823347823834",
SystemUUID: "38947555-7742-3448-3784-823347823834",
BMC: &metalv1alpha1.BMCAccess{
Protocol: metalv1alpha1.Protocol{
Name: metalv1alpha1.ProtocolRedfishLocal,
Expand Down

0 comments on commit d021129

Please sign in to comment.