Skip to content

Commit

Permalink
Add TotalSystemMemory to Server status (#173)
Browse files Browse the repository at this point in the history
* adds TotalSystemMemory to server status

* uses resource quantity for memory

* renames TotalSystemMemoryBytes to TotalSystemMemory
  • Loading branch information
stefanhipfel authored Nov 19, 2024
1 parent 57bec93 commit fe41bd7
Show file tree
Hide file tree
Showing 7 changed files with 47 additions and 8 deletions.
3 changes: 3 additions & 0 deletions api/v1alpha1/server_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,9 @@ type ServerStatus struct {
// NetworkInterfaces is a list of network interfaces associated with the server.
NetworkInterfaces []NetworkInterface `json:"networkInterfaces,omitempty"`

// TotalSystemMemory is the total amount of memory in bytes available on the server.
TotalSystemMemory *resource.Quantity `json:"totalSystemMemory,omitempty"`

// Storages is a list of storages associated with the server.
Storages []Storage `json:"storages,omitempty"`

Expand Down
5 changes: 5 additions & 0 deletions api/v1alpha1/zz_generated.deepcopy.go

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

2 changes: 2 additions & 0 deletions 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,6 +195,7 @@ type SystemInfo struct {
PowerState redfish.PowerState
NetworkInterfaces []NetworkInterface
Processors []Processor
TotalSystemMemory resource.Quantity
SystemUUID string
SerialNumber string
SKU string
Expand Down
23 changes: 15 additions & 8 deletions 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,16 +181,22 @@ 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,
Model: system.Model,
Status: system.Status,
PowerState: system.PowerState,
SerialNumber: system.SerialNumber,
SKU: system.SKU,
IndicatorLED: string(system.IndicatorLED),
SystemUUID: system.UUID,
Manufacturer: system.Manufacturer,
Model: system.Model,
Status: system.Status,
PowerState: system.PowerState,
SerialNumber: system.SerialNumber,
SKU: system.SKU,
IndicatorLED: string(system.IndicatorLED),
TotalSystemMemory: quantity,
}, nil
}

Expand Down
8 changes: 8 additions & 0 deletions config/crd/bases/metal.ironcore.dev_servers.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -483,6 +483,14 @@ spec:
type: array
type: object
type: array
totalSystemMemory:
anyOf:
- type: integer
- type: string
description: TotalSystemMemory is the total amount of memory in bytes
available on the server.
pattern: ^(\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))(([KMGTPE]i)|[numkMGTPE]|([eE](\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))))?$
x-kubernetes-int-or-string: true
type: object
type: object
served: true
Expand Down
13 changes: 13 additions & 0 deletions docs/api-reference/api.md
Original file line number Diff line number Diff line change
Expand Up @@ -2111,6 +2111,19 @@ ServerState
</tr>
<tr>
<td>
<code>totalSystemMemory</code><br/>
<em>
<a href="https://pkg.go.dev/k8s.io/apimachinery/pkg/api/resource#Quantity">
k8s.io/apimachinery/pkg/api/resource.Quantity
</a>
</em>
</td>
<td>
<p>TotalSystemMemoryBytes is the total amount of memory in bytes available on the server.</p>
</td>
</tr>
<tr>
<td>
<code>storages</code><br/>
<em>
<a href="#metal.ironcore.dev/v1alpha1.Storage">
Expand Down
1 change: 1 addition & 0 deletions internal/controller/server_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -436,6 +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 = &systemInfo.TotalSystemMemory

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

0 comments on commit fe41bd7

Please sign in to comment.