diff --git a/api/v1alpha1/conversion.go b/api/v1alpha1/conversion.go index 72cbf1c1..7ccca516 100644 --- a/api/v1alpha1/conversion.go +++ b/api/v1alpha1/conversion.go @@ -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 diff --git a/api/v1alpha1/zz_generated.conversion.go b/api/v1alpha1/zz_generated.conversion.go index 015dc2a5..aede0f37 100644 --- a/api/v1alpha1/zz_generated.conversion.go +++ b/api/v1alpha1/zz_generated.conversion.go @@ -3200,6 +3200,7 @@ func autoConvert_v1alpha4_NnfSystemStorageSpec_To_v1alpha1_NnfSystemStorageSpec( out.ComputesPattern = *(*[]int)(unsafe.Pointer(&in.ComputesPattern)) out.Capacity = in.Capacity out.Type = in.Type + // WARNING: in.Shared requires manual conversion: does not exist in peer-type out.StorageProfile = in.StorageProfile out.MakeClientMounts = in.MakeClientMounts out.ClientMountPath = in.ClientMountPath diff --git a/api/v1alpha2/conversion.go b/api/v1alpha2/conversion.go index 4fb0531b..38e533ba 100644 --- a/api/v1alpha2/conversion.go +++ b/api/v1alpha2/conversion.go @@ -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 = false + } + return nil } @@ -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) +} diff --git a/api/v1alpha2/zz_generated.conversion.go b/api/v1alpha2/zz_generated.conversion.go index 73545eb2..c90daa08 100644 --- a/api/v1alpha2/zz_generated.conversion.go +++ b/api/v1alpha2/zz_generated.conversion.go @@ -848,11 +848,6 @@ func RegisterConversions(s *runtime.Scheme) error { }); err != nil { return err } - if err := s.AddGeneratedConversionFunc((*v1alpha4.NnfSystemStorageSpec)(nil), (*NnfSystemStorageSpec)(nil), func(a, b interface{}, scope conversion.Scope) error { - return Convert_v1alpha4_NnfSystemStorageSpec_To_v1alpha2_NnfSystemStorageSpec(a.(*v1alpha4.NnfSystemStorageSpec), b.(*NnfSystemStorageSpec), scope) - }); err != nil { - return err - } if err := s.AddGeneratedConversionFunc((*NnfSystemStorageStatus)(nil), (*v1alpha4.NnfSystemStorageStatus)(nil), func(a, b interface{}, scope conversion.Scope) error { return Convert_v1alpha2_NnfSystemStorageStatus_To_v1alpha4_NnfSystemStorageStatus(a.(*NnfSystemStorageStatus), b.(*v1alpha4.NnfSystemStorageStatus), scope) }); err != nil { @@ -873,6 +868,11 @@ func RegisterConversions(s *runtime.Scheme) error { }); err != nil { return err } + if err := s.AddConversionFunc((*v1alpha4.NnfSystemStorageSpec)(nil), (*NnfSystemStorageSpec)(nil), func(a, b interface{}, scope conversion.Scope) error { + return Convert_v1alpha4_NnfSystemStorageSpec_To_v1alpha2_NnfSystemStorageSpec(a.(*v1alpha4.NnfSystemStorageSpec), b.(*NnfSystemStorageSpec), scope) + }); err != nil { + return err + } return nil } @@ -3128,7 +3128,17 @@ func Convert_v1alpha4_NnfSystemStorage_To_v1alpha2_NnfSystemStorage(in *v1alpha4 func autoConvert_v1alpha2_NnfSystemStorageList_To_v1alpha4_NnfSystemStorageList(in *NnfSystemStorageList, out *v1alpha4.NnfSystemStorageList, s conversion.Scope) error { out.ListMeta = in.ListMeta - out.Items = *(*[]v1alpha4.NnfSystemStorage)(unsafe.Pointer(&in.Items)) + if in.Items != nil { + in, out := &in.Items, &out.Items + *out = make([]v1alpha4.NnfSystemStorage, len(*in)) + for i := range *in { + if err := Convert_v1alpha2_NnfSystemStorage_To_v1alpha4_NnfSystemStorage(&(*in)[i], &(*out)[i], s); err != nil { + return err + } + } + } else { + out.Items = nil + } return nil } @@ -3139,7 +3149,17 @@ func Convert_v1alpha2_NnfSystemStorageList_To_v1alpha4_NnfSystemStorageList(in * func autoConvert_v1alpha4_NnfSystemStorageList_To_v1alpha2_NnfSystemStorageList(in *v1alpha4.NnfSystemStorageList, out *NnfSystemStorageList, s conversion.Scope) error { out.ListMeta = in.ListMeta - out.Items = *(*[]NnfSystemStorage)(unsafe.Pointer(&in.Items)) + if in.Items != nil { + in, out := &in.Items, &out.Items + *out = make([]NnfSystemStorage, len(*in)) + for i := range *in { + if err := Convert_v1alpha4_NnfSystemStorage_To_v1alpha2_NnfSystemStorage(&(*in)[i], &(*out)[i], s); err != nil { + return err + } + } + } else { + out.Items = nil + } return nil } @@ -3181,17 +3201,13 @@ func autoConvert_v1alpha4_NnfSystemStorageSpec_To_v1alpha2_NnfSystemStorageSpec( out.ComputesPattern = *(*[]int)(unsafe.Pointer(&in.ComputesPattern)) out.Capacity = in.Capacity out.Type = in.Type + // WARNING: in.Shared requires manual conversion: does not exist in peer-type out.StorageProfile = in.StorageProfile out.MakeClientMounts = in.MakeClientMounts out.ClientMountPath = in.ClientMountPath return nil } -// Convert_v1alpha4_NnfSystemStorageSpec_To_v1alpha2_NnfSystemStorageSpec is an autogenerated conversion function. -func Convert_v1alpha4_NnfSystemStorageSpec_To_v1alpha2_NnfSystemStorageSpec(in *v1alpha4.NnfSystemStorageSpec, out *NnfSystemStorageSpec, s conversion.Scope) error { - return autoConvert_v1alpha4_NnfSystemStorageSpec_To_v1alpha2_NnfSystemStorageSpec(in, out, s) -} - func autoConvert_v1alpha2_NnfSystemStorageStatus_To_v1alpha4_NnfSystemStorageStatus(in *NnfSystemStorageStatus, out *v1alpha4.NnfSystemStorageStatus, s conversion.Scope) error { out.Ready = in.Ready out.ResourceError = in.ResourceError diff --git a/api/v1alpha3/conversion.go b/api/v1alpha3/conversion.go index 504ad723..3eec8f43 100644 --- a/api/v1alpha3/conversion.go +++ b/api/v1alpha3/conversion.go @@ -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 = false + } + return nil } @@ -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) +} diff --git a/api/v1alpha3/zz_generated.conversion.go b/api/v1alpha3/zz_generated.conversion.go index dd057153..3470fa2c 100644 --- a/api/v1alpha3/zz_generated.conversion.go +++ b/api/v1alpha3/zz_generated.conversion.go @@ -843,11 +843,6 @@ func RegisterConversions(s *runtime.Scheme) error { }); err != nil { return err } - if err := s.AddGeneratedConversionFunc((*v1alpha4.NnfSystemStorageSpec)(nil), (*NnfSystemStorageSpec)(nil), func(a, b interface{}, scope conversion.Scope) error { - return Convert_v1alpha4_NnfSystemStorageSpec_To_v1alpha3_NnfSystemStorageSpec(a.(*v1alpha4.NnfSystemStorageSpec), b.(*NnfSystemStorageSpec), scope) - }); err != nil { - return err - } if err := s.AddGeneratedConversionFunc((*NnfSystemStorageStatus)(nil), (*v1alpha4.NnfSystemStorageStatus)(nil), func(a, b interface{}, scope conversion.Scope) error { return Convert_v1alpha3_NnfSystemStorageStatus_To_v1alpha4_NnfSystemStorageStatus(a.(*NnfSystemStorageStatus), b.(*v1alpha4.NnfSystemStorageStatus), scope) }); err != nil { @@ -873,6 +868,11 @@ func RegisterConversions(s *runtime.Scheme) error { }); err != nil { return err } + if err := s.AddConversionFunc((*v1alpha4.NnfSystemStorageSpec)(nil), (*NnfSystemStorageSpec)(nil), func(a, b interface{}, scope conversion.Scope) error { + return Convert_v1alpha4_NnfSystemStorageSpec_To_v1alpha3_NnfSystemStorageSpec(a.(*v1alpha4.NnfSystemStorageSpec), b.(*NnfSystemStorageSpec), scope) + }); err != nil { + return err + } return nil } @@ -3127,7 +3127,17 @@ func Convert_v1alpha4_NnfSystemStorage_To_v1alpha3_NnfSystemStorage(in *v1alpha4 func autoConvert_v1alpha3_NnfSystemStorageList_To_v1alpha4_NnfSystemStorageList(in *NnfSystemStorageList, out *v1alpha4.NnfSystemStorageList, s conversion.Scope) error { out.ListMeta = in.ListMeta - out.Items = *(*[]v1alpha4.NnfSystemStorage)(unsafe.Pointer(&in.Items)) + if in.Items != nil { + in, out := &in.Items, &out.Items + *out = make([]v1alpha4.NnfSystemStorage, len(*in)) + for i := range *in { + if err := Convert_v1alpha3_NnfSystemStorage_To_v1alpha4_NnfSystemStorage(&(*in)[i], &(*out)[i], s); err != nil { + return err + } + } + } else { + out.Items = nil + } return nil } @@ -3138,7 +3148,17 @@ func Convert_v1alpha3_NnfSystemStorageList_To_v1alpha4_NnfSystemStorageList(in * func autoConvert_v1alpha4_NnfSystemStorageList_To_v1alpha3_NnfSystemStorageList(in *v1alpha4.NnfSystemStorageList, out *NnfSystemStorageList, s conversion.Scope) error { out.ListMeta = in.ListMeta - out.Items = *(*[]NnfSystemStorage)(unsafe.Pointer(&in.Items)) + if in.Items != nil { + in, out := &in.Items, &out.Items + *out = make([]NnfSystemStorage, len(*in)) + for i := range *in { + if err := Convert_v1alpha4_NnfSystemStorage_To_v1alpha3_NnfSystemStorage(&(*in)[i], &(*out)[i], s); err != nil { + return err + } + } + } else { + out.Items = nil + } return nil } @@ -3180,17 +3200,13 @@ func autoConvert_v1alpha4_NnfSystemStorageSpec_To_v1alpha3_NnfSystemStorageSpec( out.ComputesPattern = *(*[]int)(unsafe.Pointer(&in.ComputesPattern)) out.Capacity = in.Capacity out.Type = in.Type + // WARNING: in.Shared requires manual conversion: does not exist in peer-type out.StorageProfile = in.StorageProfile out.MakeClientMounts = in.MakeClientMounts out.ClientMountPath = in.ClientMountPath return nil } -// Convert_v1alpha4_NnfSystemStorageSpec_To_v1alpha3_NnfSystemStorageSpec is an autogenerated conversion function. -func Convert_v1alpha4_NnfSystemStorageSpec_To_v1alpha3_NnfSystemStorageSpec(in *v1alpha4.NnfSystemStorageSpec, out *NnfSystemStorageSpec, s conversion.Scope) error { - return autoConvert_v1alpha4_NnfSystemStorageSpec_To_v1alpha3_NnfSystemStorageSpec(in, out, s) -} - func autoConvert_v1alpha3_NnfSystemStorageStatus_To_v1alpha4_NnfSystemStorageStatus(in *NnfSystemStorageStatus, out *v1alpha4.NnfSystemStorageStatus, s conversion.Scope) error { out.Ready = in.Ready out.ResourceError = in.ResourceError diff --git a/api/v1alpha4/nnfsystemstorage_types.go b/api/v1alpha4/nnfsystemstorage_types.go index 7ee4ed9a..2e29de8b 100644 --- a/api/v1alpha4/nnfsystemstorage_types.go +++ b/api/v1alpha4/nnfsystemstorage_types.go @@ -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"` diff --git a/config/crd/bases/nnf.cray.hpe.com_nnfsystemstorages.yaml b/config/crd/bases/nnf.cray.hpe.com_nnfsystemstorages.yaml index 093f1dc5..4dc25e43 100644 --- a/config/crd/bases/nnf.cray.hpe.com_nnfsystemstorages.yaml +++ b/config/crd/bases/nnf.cray.hpe.com_nnfsystemstorages.yaml @@ -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 @@ -921,6 +927,7 @@ spec: required: - capacity - makeClientMounts + - shared - storageProfile type: object status: diff --git a/internal/controller/nnfsystemstorage_controller.go b/internal/controller/nnfsystemstorage_controller.go index 8587d618..30d95f4c 100644 --- a/internal/controller/nnfsystemstorage_controller.go +++ b/internal/controller/nnfsystemstorage_controller.go @@ -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{ @@ -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) @@ -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{} @@ -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{ diff --git a/internal/controller/nnfsystemstorage_controller_test.go b/internal/controller/nnfsystemstorage_controller_test.go index 65a663a1..4f145c9c 100644 --- a/internal/controller/nnfsystemstorage_controller_test.go +++ b/internal/controller/nnfsystemstorage_controller_test.go @@ -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(), @@ -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(), @@ -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(), @@ -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(),