Skip to content

Commit

Permalink
uses resource quantity for memory
Browse files Browse the repository at this point in the history
  • Loading branch information
stefanhipfel committed Nov 11, 2024
1 parent 80f7dbc commit 0e4ec6d
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 3 deletions.
3 changes: 2 additions & 1 deletion bmc/bmc.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ package bmc
import (
"github.com/stmcginnis/gofish/common"
"github.com/stmcginnis/gofish/redfish"
"k8s.io/apimachinery/pkg/api/resource"
)

// BMC defines an interface for interacting with a Baseboard Management Controller.
Expand Down Expand Up @@ -194,7 +195,7 @@ type SystemInfo struct {
PowerState redfish.PowerState
NetworkInterfaces []NetworkInterface
Processors []Processor
TotalSystemMemoryBytes int64
TotalSystemMemoryBytes resource.Quantity
SystemUUID string
SerialNumber string
SKU string
Expand Down
8 changes: 7 additions & 1 deletion bmc/redfish.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (

"github.com/stmcginnis/gofish"
"github.com/stmcginnis/gofish/redfish"
"k8s.io/apimachinery/pkg/api/resource"
)

var _ BMC = (*RedfishBMC)(nil)
Expand Down Expand Up @@ -180,7 +181,12 @@ func (r *RedfishBMC) GetSystemInfo(systemUUID string) (SystemInfo, error) {
if err != nil {
return SystemInfo{}, fmt.Errorf("failed to get systems: %w", err)
}
memoryString := fmt.Sprintf("%.fGi", system.MemorySummary.TotalSystemMemoryGiB)
quantity, err := resource.ParseQuantity(memoryString)

if err != nil {
return SystemInfo{}, fmt.Errorf("failed to parse memory quantity: %w", err)
}
return SystemInfo{
SystemUUID: system.UUID,
Manufacturer: system.Manufacturer,
Expand All @@ -190,7 +196,7 @@ func (r *RedfishBMC) GetSystemInfo(systemUUID string) (SystemInfo, error) {
SerialNumber: system.SerialNumber,
SKU: system.SKU,
IndicatorLED: string(system.IndicatorLED),
TotalSystemMemoryBytes: int64(system.MemorySummary.TotalSystemMemoryGiB) * 1024 * 1024 * 1024,
TotalSystemMemoryBytes: quantity,
}, nil
}

Expand Down
2 changes: 1 addition & 1 deletion internal/controller/server_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -436,7 +436,7 @@ func (r *ServerReconciler) updateServerStatus(ctx context.Context, log logr.Logg
server.Status.Manufacturer = systemInfo.Manufacturer
server.Status.Model = systemInfo.Model
server.Status.IndicatorLED = metalv1alpha1.IndicatorLED(systemInfo.IndicatorLED)
server.Status.TotalSystemMemory = resource.NewQuantity(systemInfo.TotalSystemMemoryBytes, resource.BinarySI)
server.Status.TotalSystemMemory = &systemInfo.TotalSystemMemoryBytes

currentBiosVersion, err := bmcClient.GetBiosVersion(server.Spec.UUID)
if err != nil {
Expand Down

0 comments on commit 0e4ec6d

Please sign in to comment.