Skip to content

Commit

Permalink
use pointer for Capacity; load storages in discovery
Browse files Browse the repository at this point in the history
  • Loading branch information
stefanhipfel committed Oct 15, 2024
1 parent 2731536 commit 0621d37
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 27 deletions.
2 changes: 1 addition & 1 deletion api/v1alpha1/server_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ type Storage struct {
// Type specifies the type of the storage device.
Type string `json:"type,omitempty"`
// SizeBytes specifies the size of the storage device in bytes.
Capacity resource.Quantity `json:"capacity,omitempty"`
Capacity *resource.Quantity `json:"capacity,omitempty"`
// Vendor specifies the vendor of the storage device.
Vendor string `json:"vendor,omitempty"`
// Model specifies the model of the storage device.
Expand Down
6 changes: 5 additions & 1 deletion api/v1alpha1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

39 changes: 23 additions & 16 deletions internal/controller/server_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,29 @@ func (r *ServerReconciler) handleDiscoveryState(ctx context.Context, log logr.Lo
}
log.V(1).Info("Server state set to power on")

bmcClient, err := GetBMCClientForServer(ctx, r.Client, server, r.Insecure)
if err != nil {
return false, fmt.Errorf("failed to create BMC client: %w", err)
}
storages, err := bmcClient.GetStorages(server.Spec.UUID)
if err != nil {
return false, fmt.Errorf("failed to get storages for Server: %w", err)
}
server.Status.Storages = nil
for _, storage := range storages {
server.Status.Storages = append(server.Status.Storages, metalv1alpha1.Storage{
Name: storage.Name,
Model: storage.Model,
Capacity: resource.NewQuantity(storage.SizeBytes, resource.BinarySI),
Type: string(storage.Type),
Vendor: storage.Vendor,
State: metalv1alpha1.StorageState(storage.State),
})
}
if err := r.Status().Patch(ctx, server, client.MergeFrom(serverBase)); err != nil {
return false, fmt.Errorf("failed to patch Server status: %w", err)
}

if r.checkLastStatusUpdateAfter(r.DiscoveryTimeout, server) {
log.V(1).Info("Server did not post info to registry in time, back to initial state")
if modified, err := r.patchServerState(ctx, server, metalv1alpha1.ServerStateInitial); err != nil || modified {
Expand Down Expand Up @@ -387,23 +410,7 @@ func (r *ServerReconciler) updateServerStatus(ctx context.Context, log logr.Logg
return fmt.Errorf("failed to get system info for Server: %w", err)
}

storages, err := bmcClient.GetStorages(server.Spec.UUID)
if err != nil {
return fmt.Errorf("failed to get storages for Server: %w", err)
}
serverBase := server.DeepCopy()
server.Status.Storages = nil
for _, storage := range storages {
q := resource.NewQuantity(storage.SizeBytes, resource.BinarySI)
server.Status.Storages = append(server.Status.Storages, metalv1alpha1.Storage{
Name: storage.Name,
Model: storage.Model,
Capacity: *q,
Type: string(storage.Type),
Vendor: storage.Vendor,
State: metalv1alpha1.StorageState(storage.State),
})
}
server.Status.PowerState = metalv1alpha1.ServerPowerState(systemInfo.PowerState)
server.Status.SerialNumber = systemInfo.SerialNumber
server.Status.SKU = systemInfo.SKU
Expand Down
18 changes: 9 additions & 9 deletions internal/controller/server_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,15 +88,6 @@ var _ = Describe("Server Controller", func() {
HaveField("Status.IndicatorLED", metalv1alpha1.OffIndicatorLED),
HaveField("Status.State", metalv1alpha1.ServerStateDiscovery),
HaveField("Status.PowerState", metalv1alpha1.ServerOffPowerState),
HaveField("Status.Storages", ContainElement(metalv1alpha1.Storage{
Name: "SATA Bay 1",
Rotational: false,
Capacity: *resource.NewQuantity(8000000000000, resource.BinarySI),
Vendor: "Contoso",
Model: "3000GT8",
State: metalv1alpha1.StorageStateEnabled,
})),
HaveField("Status.Storages", HaveLen(4)),
))
DeferCleanup(k8sClient.Delete, server)

Expand Down Expand Up @@ -300,6 +291,15 @@ var _ = Describe("Server Controller", func() {
HaveField("Status.State", metalv1alpha1.ServerStateAvailable),
HaveField("Status.PowerState", metalv1alpha1.ServerOffPowerState),
HaveField("Status.NetworkInterfaces", Not(BeEmpty())),
HaveField("Status.Storages", ContainElement(metalv1alpha1.Storage{
Name: "SATA Bay 1",
Rotational: false,
Capacity: resource.NewQuantity(8000000000000, resource.BinarySI),
Vendor: "Contoso",
Model: "3000GT8",
State: metalv1alpha1.StorageStateEnabled,
})),
HaveField("Status.Storages", HaveLen(4)),
))

By("Ensuring that the boot configuration has been removed")
Expand Down

0 comments on commit 0621d37

Please sign in to comment.