From 1dd02a1793fcc7de6cedaba9ea981deed05bbc25 Mon Sep 17 00:00:00 2001 From: Matt Richerson Date: Mon, 25 Nov 2024 12:46:52 -0600 Subject: [PATCH] Add IgnoreOfflineComputes option to NnfAccess Signed-off-by: Matt Richerson --- api/v1alpha2/conversion.go | 15 ++++++- api/v1alpha2/zz_generated.conversion.go | 41 +++++++++++++------ api/v1alpha3/conversion.go | 15 ++++++- api/v1alpha3/zz_generated.conversion.go | 41 +++++++++++++------ api/v1alpha4/nnfaccess_types.go | 3 ++ api/v1alpha4/nnfsystemstorage_types.go | 3 ++ .../bases/nnf.cray.hpe.com_nnfaccesses.yaml | 4 ++ .../nnf.cray.hpe.com_nnfsystemstorages.yaml | 4 ++ internal/controller/nnf_access_controller.go | 28 +++++++++++++ .../controller/nnfsystemstorage_controller.go | 1 + 10 files changed, 129 insertions(+), 26 deletions(-) diff --git a/api/v1alpha2/conversion.go b/api/v1alpha2/conversion.go index 3825f60b..e3f81b29 100644 --- a/api/v1alpha2/conversion.go +++ b/api/v1alpha2/conversion.go @@ -42,13 +42,20 @@ func (src *NnfAccess) ConvertTo(dstRaw conversion.Hub) error { // Manually restore data. restored := &nnfv1alpha4.NnfAccess{} - 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.IgnoreOfflineComputes = restored.Spec.IgnoreOfflineComputes + } else { + dst.Spec.IgnoreOfflineComputes = false + } + return nil } @@ -494,8 +501,10 @@ func (src *NnfSystemStorage) ConvertTo(dstRaw conversion.Hub) error { if hasAnno { dst.Spec.Shared = restored.Spec.Shared + dst.Spec.IgnoreOfflineComputes = restored.Spec.IgnoreOfflineComputes } else { dst.Spec.Shared = true + dst.Spec.IgnoreOfflineComputes = false } return nil @@ -648,3 +657,7 @@ func Convert_v1alpha4_NnfStorageProfileLustreCmdLines_To_v1alpha2_NnfStorageProf 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) } + +func Convert_v1alpha4_NnfAccessSpec_To_v1alpha2_NnfAccessSpec(in *nnfv1alpha4.NnfAccessSpec, out *NnfAccessSpec, s apiconversion.Scope) error { + return autoConvert_v1alpha4_NnfAccessSpec_To_v1alpha2_NnfAccessSpec(in, out, s) +} diff --git a/api/v1alpha2/zz_generated.conversion.go b/api/v1alpha2/zz_generated.conversion.go index c90daa08..d6cb21a2 100644 --- a/api/v1alpha2/zz_generated.conversion.go +++ b/api/v1alpha2/zz_generated.conversion.go @@ -78,11 +78,6 @@ func RegisterConversions(s *runtime.Scheme) error { }); err != nil { return err } - if err := s.AddGeneratedConversionFunc((*v1alpha4.NnfAccessSpec)(nil), (*NnfAccessSpec)(nil), func(a, b interface{}, scope conversion.Scope) error { - return Convert_v1alpha4_NnfAccessSpec_To_v1alpha2_NnfAccessSpec(a.(*v1alpha4.NnfAccessSpec), b.(*NnfAccessSpec), scope) - }); err != nil { - return err - } if err := s.AddGeneratedConversionFunc((*NnfAccessStatus)(nil), (*v1alpha4.NnfAccessStatus)(nil), func(a, b interface{}, scope conversion.Scope) error { return Convert_v1alpha2_NnfAccessStatus_To_v1alpha4_NnfAccessStatus(a.(*NnfAccessStatus), b.(*v1alpha4.NnfAccessStatus), scope) }); err != nil { @@ -858,6 +853,11 @@ func RegisterConversions(s *runtime.Scheme) error { }); err != nil { return err } + if err := s.AddConversionFunc((*v1alpha4.NnfAccessSpec)(nil), (*NnfAccessSpec)(nil), func(a, b interface{}, scope conversion.Scope) error { + return Convert_v1alpha4_NnfAccessSpec_To_v1alpha2_NnfAccessSpec(a.(*v1alpha4.NnfAccessSpec), b.(*NnfAccessSpec), scope) + }); err != nil { + return err + } if err := s.AddConversionFunc((*v1alpha4.NnfStorageProfileCmdLines)(nil), (*NnfStorageProfileCmdLines)(nil), func(a, b interface{}, scope conversion.Scope) error { return Convert_v1alpha4_NnfStorageProfileCmdLines_To_v1alpha2_NnfStorageProfileCmdLines(a.(*v1alpha4.NnfStorageProfileCmdLines), b.(*NnfStorageProfileCmdLines), scope) }); err != nil { @@ -938,7 +938,17 @@ func Convert_v1alpha4_NnfAccess_To_v1alpha2_NnfAccess(in *v1alpha4.NnfAccess, ou func autoConvert_v1alpha2_NnfAccessList_To_v1alpha4_NnfAccessList(in *NnfAccessList, out *v1alpha4.NnfAccessList, s conversion.Scope) error { out.ListMeta = in.ListMeta - out.Items = *(*[]v1alpha4.NnfAccess)(unsafe.Pointer(&in.Items)) + if in.Items != nil { + in, out := &in.Items, &out.Items + *out = make([]v1alpha4.NnfAccess, len(*in)) + for i := range *in { + if err := Convert_v1alpha2_NnfAccess_To_v1alpha4_NnfAccess(&(*in)[i], &(*out)[i], s); err != nil { + return err + } + } + } else { + out.Items = nil + } return nil } @@ -949,7 +959,17 @@ func Convert_v1alpha2_NnfAccessList_To_v1alpha4_NnfAccessList(in *NnfAccessList, func autoConvert_v1alpha4_NnfAccessList_To_v1alpha2_NnfAccessList(in *v1alpha4.NnfAccessList, out *NnfAccessList, s conversion.Scope) error { out.ListMeta = in.ListMeta - out.Items = *(*[]NnfAccess)(unsafe.Pointer(&in.Items)) + if in.Items != nil { + in, out := &in.Items, &out.Items + *out = make([]NnfAccess, len(*in)) + for i := range *in { + if err := Convert_v1alpha4_NnfAccess_To_v1alpha2_NnfAccess(&(*in)[i], &(*out)[i], s); err != nil { + return err + } + } + } else { + out.Items = nil + } return nil } @@ -988,14 +1008,10 @@ func autoConvert_v1alpha4_NnfAccessSpec_To_v1alpha2_NnfAccessSpec(in *v1alpha4.N out.MakeClientMounts = in.MakeClientMounts out.MountPathPrefix = in.MountPathPrefix out.StorageReference = in.StorageReference + // WARNING: in.IgnoreOfflineComputes requires manual conversion: does not exist in peer-type return nil } -// Convert_v1alpha4_NnfAccessSpec_To_v1alpha2_NnfAccessSpec is an autogenerated conversion function. -func Convert_v1alpha4_NnfAccessSpec_To_v1alpha2_NnfAccessSpec(in *v1alpha4.NnfAccessSpec, out *NnfAccessSpec, s conversion.Scope) error { - return autoConvert_v1alpha4_NnfAccessSpec_To_v1alpha2_NnfAccessSpec(in, out, s) -} - func autoConvert_v1alpha2_NnfAccessStatus_To_v1alpha4_NnfAccessStatus(in *NnfAccessStatus, out *v1alpha4.NnfAccessStatus, s conversion.Scope) error { out.State = in.State out.Ready = in.Ready @@ -3203,6 +3219,7 @@ func autoConvert_v1alpha4_NnfSystemStorageSpec_To_v1alpha2_NnfSystemStorageSpec( out.Type = in.Type // WARNING: in.Shared requires manual conversion: does not exist in peer-type out.StorageProfile = in.StorageProfile + // WARNING: in.IgnoreOfflineComputes requires manual conversion: does not exist in peer-type out.MakeClientMounts = in.MakeClientMounts out.ClientMountPath = in.ClientMountPath return nil diff --git a/api/v1alpha3/conversion.go b/api/v1alpha3/conversion.go index 32a98544..3e3ea021 100644 --- a/api/v1alpha3/conversion.go +++ b/api/v1alpha3/conversion.go @@ -42,13 +42,20 @@ func (src *NnfAccess) ConvertTo(dstRaw conversion.Hub) error { // Manually restore data. restored := &nnfv1alpha4.NnfAccess{} - 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.IgnoreOfflineComputes = restored.Spec.IgnoreOfflineComputes + } else { + dst.Spec.IgnoreOfflineComputes = false + } + return nil } @@ -501,8 +508,10 @@ func (src *NnfSystemStorage) ConvertTo(dstRaw conversion.Hub) error { if hasAnno { dst.Spec.Shared = restored.Spec.Shared + dst.Spec.IgnoreOfflineComputes = restored.Spec.IgnoreOfflineComputes } else { dst.Spec.Shared = true + dst.Spec.IgnoreOfflineComputes = false } return nil @@ -662,3 +671,7 @@ func Convert_v1alpha4_NnfStorageProfileLustreCmdLines_To_v1alpha3_NnfStorageProf 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) } + +func Convert_v1alpha4_NnfAccessSpec_To_v1alpha3_NnfAccessSpec(in *nnfv1alpha4.NnfAccessSpec, out *NnfAccessSpec, s apiconversion.Scope) error { + return autoConvert_v1alpha4_NnfAccessSpec_To_v1alpha3_NnfAccessSpec(in, out, s) +} diff --git a/api/v1alpha3/zz_generated.conversion.go b/api/v1alpha3/zz_generated.conversion.go index 3470fa2c..c19ca524 100644 --- a/api/v1alpha3/zz_generated.conversion.go +++ b/api/v1alpha3/zz_generated.conversion.go @@ -78,11 +78,6 @@ func RegisterConversions(s *runtime.Scheme) error { }); err != nil { return err } - if err := s.AddGeneratedConversionFunc((*v1alpha4.NnfAccessSpec)(nil), (*NnfAccessSpec)(nil), func(a, b interface{}, scope conversion.Scope) error { - return Convert_v1alpha4_NnfAccessSpec_To_v1alpha3_NnfAccessSpec(a.(*v1alpha4.NnfAccessSpec), b.(*NnfAccessSpec), scope) - }); err != nil { - return err - } if err := s.AddGeneratedConversionFunc((*NnfAccessStatus)(nil), (*v1alpha4.NnfAccessStatus)(nil), func(a, b interface{}, scope conversion.Scope) error { return Convert_v1alpha3_NnfAccessStatus_To_v1alpha4_NnfAccessStatus(a.(*NnfAccessStatus), b.(*v1alpha4.NnfAccessStatus), scope) }); err != nil { @@ -858,6 +853,11 @@ func RegisterConversions(s *runtime.Scheme) error { }); err != nil { return err } + if err := s.AddConversionFunc((*v1alpha4.NnfAccessSpec)(nil), (*NnfAccessSpec)(nil), func(a, b interface{}, scope conversion.Scope) error { + return Convert_v1alpha4_NnfAccessSpec_To_v1alpha3_NnfAccessSpec(a.(*v1alpha4.NnfAccessSpec), b.(*NnfAccessSpec), scope) + }); err != nil { + return err + } if err := s.AddConversionFunc((*v1alpha4.NnfStorageProfileCmdLines)(nil), (*NnfStorageProfileCmdLines)(nil), func(a, b interface{}, scope conversion.Scope) error { return Convert_v1alpha4_NnfStorageProfileCmdLines_To_v1alpha3_NnfStorageProfileCmdLines(a.(*v1alpha4.NnfStorageProfileCmdLines), b.(*NnfStorageProfileCmdLines), scope) }); err != nil { @@ -938,7 +938,17 @@ func Convert_v1alpha4_NnfAccess_To_v1alpha3_NnfAccess(in *v1alpha4.NnfAccess, ou func autoConvert_v1alpha3_NnfAccessList_To_v1alpha4_NnfAccessList(in *NnfAccessList, out *v1alpha4.NnfAccessList, s conversion.Scope) error { out.ListMeta = in.ListMeta - out.Items = *(*[]v1alpha4.NnfAccess)(unsafe.Pointer(&in.Items)) + if in.Items != nil { + in, out := &in.Items, &out.Items + *out = make([]v1alpha4.NnfAccess, len(*in)) + for i := range *in { + if err := Convert_v1alpha3_NnfAccess_To_v1alpha4_NnfAccess(&(*in)[i], &(*out)[i], s); err != nil { + return err + } + } + } else { + out.Items = nil + } return nil } @@ -949,7 +959,17 @@ func Convert_v1alpha3_NnfAccessList_To_v1alpha4_NnfAccessList(in *NnfAccessList, func autoConvert_v1alpha4_NnfAccessList_To_v1alpha3_NnfAccessList(in *v1alpha4.NnfAccessList, out *NnfAccessList, s conversion.Scope) error { out.ListMeta = in.ListMeta - out.Items = *(*[]NnfAccess)(unsafe.Pointer(&in.Items)) + if in.Items != nil { + in, out := &in.Items, &out.Items + *out = make([]NnfAccess, len(*in)) + for i := range *in { + if err := Convert_v1alpha4_NnfAccess_To_v1alpha3_NnfAccess(&(*in)[i], &(*out)[i], s); err != nil { + return err + } + } + } else { + out.Items = nil + } return nil } @@ -988,14 +1008,10 @@ func autoConvert_v1alpha4_NnfAccessSpec_To_v1alpha3_NnfAccessSpec(in *v1alpha4.N out.MakeClientMounts = in.MakeClientMounts out.MountPathPrefix = in.MountPathPrefix out.StorageReference = in.StorageReference + // WARNING: in.IgnoreOfflineComputes requires manual conversion: does not exist in peer-type return nil } -// Convert_v1alpha4_NnfAccessSpec_To_v1alpha3_NnfAccessSpec is an autogenerated conversion function. -func Convert_v1alpha4_NnfAccessSpec_To_v1alpha3_NnfAccessSpec(in *v1alpha4.NnfAccessSpec, out *NnfAccessSpec, s conversion.Scope) error { - return autoConvert_v1alpha4_NnfAccessSpec_To_v1alpha3_NnfAccessSpec(in, out, s) -} - func autoConvert_v1alpha3_NnfAccessStatus_To_v1alpha4_NnfAccessStatus(in *NnfAccessStatus, out *v1alpha4.NnfAccessStatus, s conversion.Scope) error { out.State = in.State out.Ready = in.Ready @@ -3202,6 +3218,7 @@ func autoConvert_v1alpha4_NnfSystemStorageSpec_To_v1alpha3_NnfSystemStorageSpec( out.Type = in.Type // WARNING: in.Shared requires manual conversion: does not exist in peer-type out.StorageProfile = in.StorageProfile + // WARNING: in.IgnoreOfflineComputes requires manual conversion: does not exist in peer-type out.MakeClientMounts = in.MakeClientMounts out.ClientMountPath = in.ClientMountPath return nil diff --git a/api/v1alpha4/nnfaccess_types.go b/api/v1alpha4/nnfaccess_types.go index 2b33e617..55956f93 100644 --- a/api/v1alpha4/nnfaccess_types.go +++ b/api/v1alpha4/nnfaccess_types.go @@ -71,6 +71,9 @@ type NnfAccessSpec struct { // StorageReference is the NnfStorage reference StorageReference corev1.ObjectReference `json:"storageReference"` + + // +kubebuilder:default=false + IgnoreOfflineComputes bool `json:"ignoreOfflineComputes"` } // NnfAccessStatus defines the observed state of NnfAccess diff --git a/api/v1alpha4/nnfsystemstorage_types.go b/api/v1alpha4/nnfsystemstorage_types.go index 2e29de8b..62abe589 100644 --- a/api/v1alpha4/nnfsystemstorage_types.go +++ b/api/v1alpha4/nnfsystemstorage_types.go @@ -91,6 +91,9 @@ type NnfSystemStorageSpec struct { // StorageProfile is an object reference to the storage profile to use StorageProfile corev1.ObjectReference `json:"storageProfile"` + // +kubebuilder:default:=false + IgnoreOfflineComputes bool `json:"ignoreOfflineComputes"` + // MakeClientMounts specifies whether to make ClientMount resources or just // make the devices available to the client // +kubebuilder:default:=false diff --git a/config/crd/bases/nnf.cray.hpe.com_nnfaccesses.yaml b/config/crd/bases/nnf.cray.hpe.com_nnfaccesses.yaml index c9c82df9..9c0a2ad6 100644 --- a/config/crd/bases/nnf.cray.hpe.com_nnfaccesses.yaml +++ b/config/crd/bases/nnf.cray.hpe.com_nnfaccesses.yaml @@ -615,6 +615,9 @@ spec: description: GroupID for the new mount. Currently only used for raw format: int32 type: integer + ignoreOfflineComputes: + default: false + type: boolean makeClientMounts: default: true description: |- @@ -706,6 +709,7 @@ spec: required: - desiredState - groupID + - ignoreOfflineComputes - makeClientMounts - storageReference - target diff --git a/config/crd/bases/nnf.cray.hpe.com_nnfsystemstorages.yaml b/config/crd/bases/nnf.cray.hpe.com_nnfsystemstorages.yaml index fec341f2..9fb38926 100644 --- a/config/crd/bases/nnf.cray.hpe.com_nnfsystemstorages.yaml +++ b/config/crd/bases/nnf.cray.hpe.com_nnfsystemstorages.yaml @@ -565,6 +565,9 @@ spec: items: type: string type: array + ignoreOfflineComputes: + default: false + type: boolean includeComputes: description: |- IncludeComputes is a list of computes nodes to use rather than getting the list of compute nodes @@ -692,6 +695,7 @@ spec: type: string required: - capacity + - ignoreOfflineComputes - makeClientMounts - shared - storageProfile diff --git a/internal/controller/nnf_access_controller.go b/internal/controller/nnf_access_controller.go index ab206a52..d5fdf698 100644 --- a/internal/controller/nnf_access_controller.go +++ b/internal/controller/nnf_access_controller.go @@ -870,6 +870,34 @@ func (r *NnfAccessReconciler) getBlockStorageAccessStatus(ctx context.Context, a for allocationIndex, allocation := range nnfNodeBlockStorage.Spec.Allocations { for _, nodeName := range allocation.Access { blockAccess, exists := nnfNodeBlockStorage.Status.Allocations[allocationIndex].Accesses[nodeName] + if access.Spec.IgnoreOfflineComputes { + storage := &dwsv1alpha2.Storage{ + ObjectMeta: metav1.ObjectMeta{ + Name: nnfNodeBlockStorage.GetNamespace(), + Namespace: corev1.NamespaceDefault, + }, + } + + if err := r.Get(ctx, client.ObjectKeyFromObject(storage), storage); err != nil { + return false, err + } + + computeOffline := false + for _, compute := range storage.Status.Access.Computes { + if compute.Name != nodeName { + continue + } + + if compute.Status == dwsv1alpha2.OfflineStatus { + computeOffline = true + } + } + + // If the compute is offline, don't check its status + if computeOffline { + continue + } + } // if the map entry doesn't exist in the status section for this node yet, then keep waiting if !exists { diff --git a/internal/controller/nnfsystemstorage_controller.go b/internal/controller/nnfsystemstorage_controller.go index 30d95f4c..72b66a23 100644 --- a/internal/controller/nnfsystemstorage_controller.go +++ b/internal/controller/nnfsystemstorage_controller.go @@ -610,6 +610,7 @@ func (r *NnfSystemStorageReconciler) createNnfAccess(ctx context.Context, nnfSys } else { nnfAccess.Spec.Target = "single" } + nnfAccess.Spec.IgnoreOfflineComputes = nnfSystemStorage.Spec.IgnoreOfflineComputes nnfAccess.Spec.MakeClientMounts = nnfSystemStorage.Spec.MakeClientMounts nnfAccess.Spec.MountPath = nnfSystemStorage.Spec.ClientMountPath nnfAccess.Spec.ClientReference = corev1.ObjectReference{