Skip to content

Commit

Permalink
minor fix
Browse files Browse the repository at this point in the history
  • Loading branch information
stefanhipfel committed Oct 15, 2024
1 parent 06a11f8 commit 2731536
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 6 deletions.
3 changes: 2 additions & 1 deletion api/v1alpha1/server_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ package v1alpha1

import (
v1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/api/resource"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

Expand Down Expand Up @@ -218,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 string `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
5 changes: 4 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.

6 changes: 5 additions & 1 deletion config/crd/bases/metal.ironcore.dev_servers.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -406,9 +406,13 @@ spec:
description: Storage defines the details of one storage device
properties:
capacity:
anyOf:
- type: integer
- type: string
description: SizeBytes specifies the size of the storage device
in bytes.
type: string
pattern: ^(\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))(([KMGTPE]i)|[numkMGTPE]|([eE](\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))))?$
x-kubernetes-int-or-string: true
model:
description: Model specifies the model of the storage device.
type: string
Expand Down
4 changes: 2 additions & 2 deletions internal/controller/server_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -394,11 +394,11 @@ func (r *ServerReconciler) updateServerStatus(ctx context.Context, log logr.Logg
serverBase := server.DeepCopy()
server.Status.Storages = nil
for _, storage := range storages {
q := resource.NewQuantity(storage.SizeBytes, resource.DecimalSI)
q := resource.NewQuantity(storage.SizeBytes, resource.BinarySI)
server.Status.Storages = append(server.Status.Storages, metalv1alpha1.Storage{
Name: storage.Name,
Model: storage.Model,
Capacity: q.String(),
Capacity: *q,
Type: string(storage.Type),
Vendor: storage.Vendor,
State: metalv1alpha1.StorageState(storage.State),
Expand Down
3 changes: 2 additions & 1 deletion internal/controller/server_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"time"

apierrors "k8s.io/apimachinery/pkg/api/errors"
"k8s.io/apimachinery/pkg/api/resource"

metalv1alpha1 "github.com/ironcore-dev/metal-operator/api/v1alpha1"
"github.com/ironcore-dev/metal-operator/internal/controller/testdata"
Expand Down Expand Up @@ -90,7 +91,7 @@ var _ = Describe("Server Controller", func() {
HaveField("Status.Storages", ContainElement(metalv1alpha1.Storage{
Name: "SATA Bay 1",
Rotational: false,
Capacity: "8T",
Capacity: *resource.NewQuantity(8000000000000, resource.BinarySI),
Vendor: "Contoso",
Model: "3000GT8",
State: metalv1alpha1.StorageStateEnabled,
Expand Down

0 comments on commit 2731536

Please sign in to comment.