Skip to content

Commit

Permalink
Add shared option to NnfSystemStorage (#417)
Browse files Browse the repository at this point in the history
* Add shared option to NnfSystemStorage

The shared option determines whether to create a single allocation per Rabbit
that is shared between all the computes on the Rabbit, or one allocation per
compute node.

Signed-off-by: Matt Richerson <[email protected]>

* default to shared=true for v1alpha2 and v1alpha3

Signed-off-by: Matt Richerson <[email protected]>

---------

Signed-off-by: Matt Richerson <[email protected]>
  • Loading branch information
matthew-richerson authored Nov 20, 2024
1 parent 17ac743 commit 5bf3a0e
Show file tree
Hide file tree
Showing 10 changed files with 119 additions and 29 deletions.
2 changes: 2 additions & 0 deletions api/v1alpha1/conversion.go
Original file line number Diff line number Diff line change
Expand Up @@ -494,8 +494,10 @@ func (src *NnfSystemStorage) ConvertTo(dstRaw conversion.Hub) error {
// Otherwise, you may comment out UnmarshalData() until it's needed.
if hasAnno {
dst.Spec.ExcludeDisabledRabbits = restored.Spec.ExcludeDisabledRabbits
dst.Spec.Shared = restored.Spec.Shared
} else {
dst.Spec.ExcludeDisabledRabbits = false
dst.Spec.Shared = true
}

return nil
Expand Down
1 change: 1 addition & 0 deletions api/v1alpha1/zz_generated.conversion.go

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

13 changes: 12 additions & 1 deletion api/v1alpha2/conversion.go
Original file line number Diff line number Diff line change
Expand Up @@ -484,13 +484,20 @@ func (src *NnfSystemStorage) ConvertTo(dstRaw conversion.Hub) error {

// Manually restore data.
restored := &nnfv1alpha4.NnfSystemStorage{}
if ok, err := utilconversion.UnmarshalData(src, restored); err != nil || !ok {
hasAnno, err := utilconversion.UnmarshalData(src, restored)
if err != nil {
return err
}
// EDIT THIS FUNCTION! If the annotation is holding anything that is
// hub-specific then copy it into 'dst' from 'restored'.
// Otherwise, you may comment out UnmarshalData() until it's needed.

if hasAnno {
dst.Spec.Shared = restored.Spec.Shared
} else {
dst.Spec.Shared = true
}

return nil
}

Expand Down Expand Up @@ -637,3 +644,7 @@ func Convert_v1alpha4_NnfStorageProfileCmdLines_To_v1alpha2_NnfStorageProfileCmd
func Convert_v1alpha4_NnfStorageProfileLustreCmdLines_To_v1alpha2_NnfStorageProfileLustreCmdLines(in *nnfv1alpha4.NnfStorageProfileLustreCmdLines, out *NnfStorageProfileLustreCmdLines, s apiconversion.Scope) error {
return autoConvert_v1alpha4_NnfStorageProfileLustreCmdLines_To_v1alpha2_NnfStorageProfileLustreCmdLines(in, out, s)
}

func Convert_v1alpha4_NnfSystemStorageSpec_To_v1alpha2_NnfSystemStorageSpec(in *nnfv1alpha4.NnfSystemStorageSpec, out *NnfSystemStorageSpec, s apiconversion.Scope) error {
return autoConvert_v1alpha4_NnfSystemStorageSpec_To_v1alpha2_NnfSystemStorageSpec(in, out, s)
}
40 changes: 28 additions & 12 deletions api/v1alpha2/zz_generated.conversion.go

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

13 changes: 12 additions & 1 deletion api/v1alpha3/conversion.go
Original file line number Diff line number Diff line change
Expand Up @@ -491,13 +491,20 @@ func (src *NnfSystemStorage) ConvertTo(dstRaw conversion.Hub) error {

// Manually restore data.
restored := &nnfv1alpha4.NnfSystemStorage{}
if ok, err := utilconversion.UnmarshalData(src, restored); err != nil || !ok {
hasAnno, err := utilconversion.UnmarshalData(src, restored)
if err != nil {
return err
}
// EDIT THIS FUNCTION! If the annotation is holding anything that is
// hub-specific then copy it into 'dst' from 'restored'.
// Otherwise, you may comment out UnmarshalData() until it's needed.

if hasAnno {
dst.Spec.Shared = restored.Spec.Shared
} else {
dst.Spec.Shared = true
}

return nil
}

Expand Down Expand Up @@ -651,3 +658,7 @@ func Convert_v1alpha4_NnfStorageProfileCmdLines_To_v1alpha3_NnfStorageProfileCmd
func Convert_v1alpha4_NnfStorageProfileLustreCmdLines_To_v1alpha3_NnfStorageProfileLustreCmdLines(in *nnfv1alpha4.NnfStorageProfileLustreCmdLines, out *NnfStorageProfileLustreCmdLines, s apiconversion.Scope) error {
return autoConvert_v1alpha4_NnfStorageProfileLustreCmdLines_To_v1alpha3_NnfStorageProfileLustreCmdLines(in, out, s)
}

func Convert_v1alpha4_NnfSystemStorageSpec_To_v1alpha3_NnfSystemStorageSpec(in *nnfv1alpha4.NnfSystemStorageSpec, out *NnfSystemStorageSpec, s apiconversion.Scope) error {
return autoConvert_v1alpha4_NnfSystemStorageSpec_To_v1alpha3_NnfSystemStorageSpec(in, out, s)
}
40 changes: 28 additions & 12 deletions api/v1alpha3/zz_generated.conversion.go

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

5 changes: 5 additions & 0 deletions api/v1alpha4/nnfsystemstorage_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,11 @@ type NnfSystemStorageSpec struct {
// +kubebuilder:default:=raw
Type string `json:"type,omitempty"`

// Shared will create one allocation per Rabbit rather than one allocation
// per compute node.
// +kubebuilder:default:=true
Shared bool `json:"shared"`

// StorageProfile is an object reference to the storage profile to use
StorageProfile corev1.ObjectReference `json:"storageProfile"`

Expand Down
7 changes: 7 additions & 0 deletions config/crd/bases/nnf.cray.hpe.com_nnfsystemstorages.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -819,6 +819,12 @@ spec:
MakeClientMounts specifies whether to make ClientMount resources or just
make the devices available to the client
type: boolean
shared:
default: true
description: |-
Shared will create one allocation per Rabbit rather than one allocation
per compute node.
type: boolean
storageProfile:
description: StorageProfile is an object reference to the storage
profile to use
Expand Down Expand Up @@ -921,6 +927,7 @@ spec:
required:
- capacity
- makeClientMounts
- shared
- storageProfile
type: object
status:
Expand Down
23 changes: 20 additions & 3 deletions internal/controller/nnfsystemstorage_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,19 @@ func (r *NnfSystemStorageReconciler) createServers(ctx context.Context, nnfSyste
rabbitList = tempRabbitList
}

allocationCount := 1
if nnfSystemStorage.Spec.Shared == false {
switch nnfSystemStorage.Spec.ComputesTarget {
case nnfv1alpha4.ComputesTargetAll:
allocationCount = 16
case nnfv1alpha4.ComputesTargetEven, nnfv1alpha4.ComputesTargetOdd:
allocationCount = 8
case nnfv1alpha4.ComputesTargetPattern:
allocationCount = len(nnfSystemStorage.Spec.ComputesPattern)
default:
return dwsv1alpha2.NewResourceError("unexpected ComputesTarget type '%s'", nnfSystemStorage.Spec.ComputesTarget).WithFatal()
}
}
// Use the Rabbit list to fill in the servers resource with one allocation per Rabbit
servers := &dwsv1alpha2.Servers{
ObjectMeta: metav1.ObjectMeta{
Expand All @@ -312,7 +325,7 @@ func (r *NnfSystemStorageReconciler) createServers(ctx context.Context, nnfSyste
servers.Spec.AllocationSets[0].Storage = []dwsv1alpha2.ServersSpecStorage{}

for _, rabbitName := range rabbitList {
servers.Spec.AllocationSets[0].Storage = append(servers.Spec.AllocationSets[0].Storage, dwsv1alpha2.ServersSpecStorage{Name: rabbitName, AllocationCount: 1})
servers.Spec.AllocationSets[0].Storage = append(servers.Spec.AllocationSets[0].Storage, dwsv1alpha2.ServersSpecStorage{Name: rabbitName, AllocationCount: allocationCount})
}

return ctrl.SetControllerReference(nnfSystemStorage, servers, r.Scheme)
Expand Down Expand Up @@ -384,7 +397,7 @@ func (r *NnfSystemStorageReconciler) createComputes(ctx context.Context, nnfSyst
case nnfv1alpha4.ComputesTargetPattern:
indexList = append([]int(nil), nnfSystemStorage.Spec.ComputesPattern...)
default:
return dwsv1alpha2.NewResourceError("undexpected ComputesTarget type '%s'", nnfSystemStorage.Spec.ComputesTarget).WithFatal()
return dwsv1alpha2.NewResourceError("unexpected ComputesTarget type '%s'", nnfSystemStorage.Spec.ComputesTarget).WithFatal()
}

indexMap := map[int]bool{}
Expand Down Expand Up @@ -592,7 +605,11 @@ func (r *NnfSystemStorageReconciler) createNnfAccess(ctx context.Context, nnfSys
nnfAccess.Spec.DesiredState = "mounted"
nnfAccess.Spec.UserID = 0
nnfAccess.Spec.GroupID = 0
nnfAccess.Spec.Target = "shared"
if nnfSystemStorage.Spec.Shared {
nnfAccess.Spec.Target = "shared"
} else {
nnfAccess.Spec.Target = "single"
}
nnfAccess.Spec.MakeClientMounts = nnfSystemStorage.Spec.MakeClientMounts
nnfAccess.Spec.MountPath = nnfSystemStorage.Spec.ClientMountPath
nnfAccess.Spec.ClientReference = corev1.ObjectReference{
Expand Down
4 changes: 4 additions & 0 deletions internal/controller/nnfsystemstorage_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,7 @@ var _ = Describe("NnfSystemStorage Controller Test", func() {
Type: "raw",
ComputesTarget: nnfv1alpha4.ComputesTargetAll,
MakeClientMounts: false,
Shared: true,
Capacity: 1073741824,
StorageProfile: corev1.ObjectReference{
Name: storageProfile.GetName(),
Expand Down Expand Up @@ -363,6 +364,7 @@ var _ = Describe("NnfSystemStorage Controller Test", func() {
Type: "raw",
ComputesTarget: nnfv1alpha4.ComputesTargetEven,
MakeClientMounts: false,
Shared: true,
Capacity: 1073741824,
StorageProfile: corev1.ObjectReference{
Name: storageProfile.GetName(),
Expand Down Expand Up @@ -423,6 +425,7 @@ var _ = Describe("NnfSystemStorage Controller Test", func() {
ComputesTarget: nnfv1alpha4.ComputesTargetPattern,
ComputesPattern: []int{0, 1, 2, 3, 4},
MakeClientMounts: false,
Shared: true,
Capacity: 1073741824,
StorageProfile: corev1.ObjectReference{
Name: storageProfile.GetName(),
Expand Down Expand Up @@ -484,6 +487,7 @@ var _ = Describe("NnfSystemStorage Controller Test", func() {
ExcludeRabbits: []string{nodeNames[0]},
ExcludeComputes: []string{"1-4", "1-5", "1-6"},
MakeClientMounts: false,
Shared: true,
Capacity: 1073741824,
StorageProfile: corev1.ObjectReference{
Name: storageProfile.GetName(),
Expand Down

0 comments on commit 5bf3a0e

Please sign in to comment.