diff --git a/api/v1alpha1/conversion.go b/api/v1alpha1/conversion.go index fd10b5f4..72cbf1c1 100644 --- a/api/v1alpha1/conversion.go +++ b/api/v1alpha1/conversion.go @@ -437,18 +437,26 @@ func (src *NnfStorageProfile) ConvertTo(dstRaw conversion.Hub) error { if hasAnno { dst.Data.LustreStorage.MgtCmdLines.PostActivate = append([]string(nil), restored.Data.LustreStorage.MgtCmdLines.PostActivate...) dst.Data.LustreStorage.MgtCmdLines.PreDeactivate = append([]string(nil), restored.Data.LustreStorage.MgtCmdLines.PreDeactivate...) + dst.Data.LustreStorage.MgtCmdLines.PostMount = append([]string(nil), restored.Data.LustreStorage.MgtCmdLines.PostMount...) + dst.Data.LustreStorage.MgtCmdLines.PreUnmount = append([]string(nil), restored.Data.LustreStorage.MgtCmdLines.PreUnmount...) dst.Data.LustreStorage.MgtMdtCmdLines.PostActivate = append([]string(nil), restored.Data.LustreStorage.MgtMdtCmdLines.PostActivate...) dst.Data.LustreStorage.MgtMdtCmdLines.PreDeactivate = append([]string(nil), restored.Data.LustreStorage.MgtMdtCmdLines.PreDeactivate...) + dst.Data.LustreStorage.MgtMdtCmdLines.PostMount = append([]string(nil), restored.Data.LustreStorage.MgtMdtCmdLines.PostMount...) + dst.Data.LustreStorage.MgtMdtCmdLines.PreUnmount = append([]string(nil), restored.Data.LustreStorage.MgtMdtCmdLines.PreUnmount...) dst.Data.LustreStorage.MdtCmdLines.PostActivate = append([]string(nil), restored.Data.LustreStorage.MdtCmdLines.PostActivate...) dst.Data.LustreStorage.MdtCmdLines.PreDeactivate = append([]string(nil), restored.Data.LustreStorage.MdtCmdLines.PreDeactivate...) + dst.Data.LustreStorage.MdtCmdLines.PostMount = append([]string(nil), restored.Data.LustreStorage.MdtCmdLines.PostMount...) + dst.Data.LustreStorage.MdtCmdLines.PreUnmount = append([]string(nil), restored.Data.LustreStorage.MdtCmdLines.PreUnmount...) dst.Data.LustreStorage.OstCmdLines.PostActivate = append([]string(nil), restored.Data.LustreStorage.OstCmdLines.PostActivate...) dst.Data.LustreStorage.OstCmdLines.PreDeactivate = append([]string(nil), restored.Data.LustreStorage.OstCmdLines.PreDeactivate...) - dst.Data.RawStorage.CmdLines.PostActivate = append([]string(nil), restored.Data.RawStorage.CmdLines.PostActivate...) - dst.Data.RawStorage.CmdLines.PreDeactivate = append([]string(nil), restored.Data.RawStorage.CmdLines.PreDeactivate...) - dst.Data.XFSStorage.CmdLines.PostActivate = append([]string(nil), restored.Data.XFSStorage.CmdLines.PostActivate...) - dst.Data.XFSStorage.CmdLines.PreDeactivate = append([]string(nil), restored.Data.XFSStorage.CmdLines.PreDeactivate...) - dst.Data.GFS2Storage.CmdLines.PostActivate = append([]string(nil), restored.Data.GFS2Storage.CmdLines.PostActivate...) - dst.Data.GFS2Storage.CmdLines.PreDeactivate = append([]string(nil), restored.Data.GFS2Storage.CmdLines.PreDeactivate...) + dst.Data.LustreStorage.OstCmdLines.PostMount = append([]string(nil), restored.Data.LustreStorage.OstCmdLines.PostMount...) + dst.Data.LustreStorage.OstCmdLines.PreUnmount = append([]string(nil), restored.Data.LustreStorage.OstCmdLines.PreUnmount...) + dst.Data.RawStorage.CmdLines.PostMount = append([]string(nil), restored.Data.RawStorage.CmdLines.PostMount...) + dst.Data.RawStorage.CmdLines.PreUnmount = append([]string(nil), restored.Data.RawStorage.CmdLines.PreUnmount...) + dst.Data.XFSStorage.CmdLines.PostMount = append([]string(nil), restored.Data.XFSStorage.CmdLines.PostMount...) + dst.Data.XFSStorage.CmdLines.PreUnmount = append([]string(nil), restored.Data.XFSStorage.CmdLines.PreUnmount...) + dst.Data.GFS2Storage.CmdLines.PostMount = append([]string(nil), restored.Data.GFS2Storage.CmdLines.PostMount...) + dst.Data.GFS2Storage.CmdLines.PreUnmount = append([]string(nil), restored.Data.GFS2Storage.CmdLines.PreUnmount...) } return nil diff --git a/api/v1alpha1/zz_generated.conversion.go b/api/v1alpha1/zz_generated.conversion.go index ea29aa94..015dc2a5 100644 --- a/api/v1alpha1/zz_generated.conversion.go +++ b/api/v1alpha1/zz_generated.conversion.go @@ -2683,9 +2683,9 @@ func autoConvert_v1alpha4_NnfStorageProfileCmdLines_To_v1alpha1_NnfStorageProfil } out.LvRemove = in.LvRemove out.MountRabbit = in.MountRabbit - // WARNING: in.PostActivate requires manual conversion: does not exist in peer-type + // WARNING: in.PostMount requires manual conversion: does not exist in peer-type out.MountCompute = in.MountCompute - // WARNING: in.PreDeactivate requires manual conversion: does not exist in peer-type + // WARNING: in.PreUnmount requires manual conversion: does not exist in peer-type return nil } @@ -2866,6 +2866,8 @@ func autoConvert_v1alpha4_NnfStorageProfileLustreCmdLines_To_v1alpha1_NnfStorage out.Mkfs = in.Mkfs out.MountTarget = in.MountTarget // WARNING: in.PostActivate requires manual conversion: does not exist in peer-type + // WARNING: in.PostMount requires manual conversion: does not exist in peer-type + // WARNING: in.PreUnmount requires manual conversion: does not exist in peer-type // WARNING: in.PreDeactivate requires manual conversion: does not exist in peer-type return nil } diff --git a/api/v1alpha2/conversion.go b/api/v1alpha2/conversion.go index c564d223..4fb0531b 100644 --- a/api/v1alpha2/conversion.go +++ b/api/v1alpha2/conversion.go @@ -437,18 +437,26 @@ func (src *NnfStorageProfile) ConvertTo(dstRaw conversion.Hub) error { if hasAnno { dst.Data.LustreStorage.MgtCmdLines.PostActivate = append([]string(nil), restored.Data.LustreStorage.MgtCmdLines.PostActivate...) dst.Data.LustreStorage.MgtCmdLines.PreDeactivate = append([]string(nil), restored.Data.LustreStorage.MgtCmdLines.PreDeactivate...) + dst.Data.LustreStorage.MgtCmdLines.PostMount = append([]string(nil), restored.Data.LustreStorage.MgtCmdLines.PostMount...) + dst.Data.LustreStorage.MgtCmdLines.PreUnmount = append([]string(nil), restored.Data.LustreStorage.MgtCmdLines.PreUnmount...) dst.Data.LustreStorage.MgtMdtCmdLines.PostActivate = append([]string(nil), restored.Data.LustreStorage.MgtMdtCmdLines.PostActivate...) dst.Data.LustreStorage.MgtMdtCmdLines.PreDeactivate = append([]string(nil), restored.Data.LustreStorage.MgtMdtCmdLines.PreDeactivate...) + dst.Data.LustreStorage.MgtMdtCmdLines.PostMount = append([]string(nil), restored.Data.LustreStorage.MgtMdtCmdLines.PostMount...) + dst.Data.LustreStorage.MgtMdtCmdLines.PreUnmount = append([]string(nil), restored.Data.LustreStorage.MgtMdtCmdLines.PreUnmount...) dst.Data.LustreStorage.MdtCmdLines.PostActivate = append([]string(nil), restored.Data.LustreStorage.MdtCmdLines.PostActivate...) dst.Data.LustreStorage.MdtCmdLines.PreDeactivate = append([]string(nil), restored.Data.LustreStorage.MdtCmdLines.PreDeactivate...) + dst.Data.LustreStorage.MdtCmdLines.PostMount = append([]string(nil), restored.Data.LustreStorage.MdtCmdLines.PostMount...) + dst.Data.LustreStorage.MdtCmdLines.PreUnmount = append([]string(nil), restored.Data.LustreStorage.MdtCmdLines.PreUnmount...) dst.Data.LustreStorage.OstCmdLines.PostActivate = append([]string(nil), restored.Data.LustreStorage.OstCmdLines.PostActivate...) dst.Data.LustreStorage.OstCmdLines.PreDeactivate = append([]string(nil), restored.Data.LustreStorage.OstCmdLines.PreDeactivate...) - dst.Data.RawStorage.CmdLines.PostActivate = append([]string(nil), restored.Data.RawStorage.CmdLines.PostActivate...) - dst.Data.RawStorage.CmdLines.PreDeactivate = append([]string(nil), restored.Data.RawStorage.CmdLines.PreDeactivate...) - dst.Data.XFSStorage.CmdLines.PostActivate = append([]string(nil), restored.Data.XFSStorage.CmdLines.PostActivate...) - dst.Data.XFSStorage.CmdLines.PreDeactivate = append([]string(nil), restored.Data.XFSStorage.CmdLines.PreDeactivate...) - dst.Data.GFS2Storage.CmdLines.PostActivate = append([]string(nil), restored.Data.GFS2Storage.CmdLines.PostActivate...) - dst.Data.GFS2Storage.CmdLines.PreDeactivate = append([]string(nil), restored.Data.GFS2Storage.CmdLines.PreDeactivate...) + dst.Data.LustreStorage.OstCmdLines.PostMount = append([]string(nil), restored.Data.LustreStorage.OstCmdLines.PostMount...) + dst.Data.LustreStorage.OstCmdLines.PreUnmount = append([]string(nil), restored.Data.LustreStorage.OstCmdLines.PreUnmount...) + dst.Data.RawStorage.CmdLines.PostMount = append([]string(nil), restored.Data.RawStorage.CmdLines.PostMount...) + dst.Data.RawStorage.CmdLines.PreUnmount = append([]string(nil), restored.Data.RawStorage.CmdLines.PreUnmount...) + dst.Data.XFSStorage.CmdLines.PostMount = append([]string(nil), restored.Data.XFSStorage.CmdLines.PostMount...) + dst.Data.XFSStorage.CmdLines.PreUnmount = append([]string(nil), restored.Data.XFSStorage.CmdLines.PreUnmount...) + dst.Data.GFS2Storage.CmdLines.PostMount = append([]string(nil), restored.Data.GFS2Storage.CmdLines.PostMount...) + dst.Data.GFS2Storage.CmdLines.PreUnmount = append([]string(nil), restored.Data.GFS2Storage.CmdLines.PreUnmount...) } return nil diff --git a/api/v1alpha2/zz_generated.conversion.go b/api/v1alpha2/zz_generated.conversion.go index 214f3c85..73545eb2 100644 --- a/api/v1alpha2/zz_generated.conversion.go +++ b/api/v1alpha2/zz_generated.conversion.go @@ -2683,9 +2683,9 @@ func autoConvert_v1alpha4_NnfStorageProfileCmdLines_To_v1alpha2_NnfStorageProfil } out.LvRemove = in.LvRemove out.MountRabbit = in.MountRabbit - // WARNING: in.PostActivate requires manual conversion: does not exist in peer-type + // WARNING: in.PostMount requires manual conversion: does not exist in peer-type out.MountCompute = in.MountCompute - // WARNING: in.PreDeactivate requires manual conversion: does not exist in peer-type + // WARNING: in.PreUnmount requires manual conversion: does not exist in peer-type return nil } @@ -2866,6 +2866,8 @@ func autoConvert_v1alpha4_NnfStorageProfileLustreCmdLines_To_v1alpha2_NnfStorage out.Mkfs = in.Mkfs out.MountTarget = in.MountTarget // WARNING: in.PostActivate requires manual conversion: does not exist in peer-type + // WARNING: in.PostMount requires manual conversion: does not exist in peer-type + // WARNING: in.PreUnmount requires manual conversion: does not exist in peer-type // WARNING: in.PreDeactivate requires manual conversion: does not exist in peer-type return nil } diff --git a/api/v1alpha3/conversion.go b/api/v1alpha3/conversion.go index db8e7da2..504ad723 100644 --- a/api/v1alpha3/conversion.go +++ b/api/v1alpha3/conversion.go @@ -21,6 +21,7 @@ package v1alpha3 import ( apierrors "k8s.io/apimachinery/pkg/api/errors" + apiconversion "k8s.io/apimachinery/pkg/conversion" "k8s.io/apimachinery/pkg/runtime/schema" "sigs.k8s.io/controller-runtime/pkg/conversion" logf "sigs.k8s.io/controller-runtime/pkg/log" @@ -425,12 +426,37 @@ func (src *NnfStorageProfile) ConvertTo(dstRaw conversion.Hub) error { // Manually restore data. restored := &nnfv1alpha4.NnfStorageProfile{} - 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.Data.LustreStorage.MgtCmdLines.PostMount = append([]string(nil), restored.Data.LustreStorage.MgtCmdLines.PostMount...) + dst.Data.LustreStorage.MgtCmdLines.PreUnmount = append([]string(nil), restored.Data.LustreStorage.MgtCmdLines.PreUnmount...) + dst.Data.LustreStorage.MgtMdtCmdLines.PostMount = append([]string(nil), restored.Data.LustreStorage.MgtMdtCmdLines.PostMount...) + dst.Data.LustreStorage.MgtMdtCmdLines.PreUnmount = append([]string(nil), restored.Data.LustreStorage.MgtMdtCmdLines.PreUnmount...) + dst.Data.LustreStorage.MdtCmdLines.PostMount = append([]string(nil), restored.Data.LustreStorage.MdtCmdLines.PostMount...) + dst.Data.LustreStorage.MdtCmdLines.PreUnmount = append([]string(nil), restored.Data.LustreStorage.MdtCmdLines.PreUnmount...) + dst.Data.LustreStorage.OstCmdLines.PostMount = append([]string(nil), restored.Data.LustreStorage.OstCmdLines.PostMount...) + dst.Data.LustreStorage.OstCmdLines.PreUnmount = append([]string(nil), restored.Data.LustreStorage.OstCmdLines.PreUnmount...) + dst.Data.RawStorage.CmdLines.PostMount = append([]string(nil), restored.Data.RawStorage.CmdLines.PostMount...) + dst.Data.RawStorage.CmdLines.PreUnmount = append([]string(nil), restored.Data.RawStorage.CmdLines.PreUnmount...) + dst.Data.XFSStorage.CmdLines.PostMount = append([]string(nil), restored.Data.XFSStorage.CmdLines.PostMount...) + dst.Data.XFSStorage.CmdLines.PreUnmount = append([]string(nil), restored.Data.XFSStorage.CmdLines.PreUnmount...) + dst.Data.GFS2Storage.CmdLines.PostMount = append([]string(nil), restored.Data.GFS2Storage.CmdLines.PostMount...) + dst.Data.GFS2Storage.CmdLines.PreUnmount = append([]string(nil), restored.Data.GFS2Storage.CmdLines.PreUnmount...) + } else { + // For non-lustre, PostActivate is now PostMount and PreDeactivate is now PreUnmount + dst.Data.RawStorage.CmdLines.PostMount = src.Data.RawStorage.CmdLines.PostActivate + dst.Data.XFSStorage.CmdLines.PostMount = src.Data.XFSStorage.CmdLines.PostActivate + dst.Data.GFS2Storage.CmdLines.PostMount = src.Data.GFS2Storage.CmdLines.PostActivate + dst.Data.RawStorage.CmdLines.PreUnmount = src.Data.RawStorage.CmdLines.PreDeactivate + dst.Data.XFSStorage.CmdLines.PreUnmount = src.Data.XFSStorage.CmdLines.PreDeactivate + dst.Data.GFS2Storage.CmdLines.PreUnmount = src.Data.GFS2Storage.CmdLines.PreDeactivate + } return nil } @@ -443,6 +469,14 @@ func (dst *NnfStorageProfile) ConvertFrom(srcRaw conversion.Hub) error { return err } + // For non-lustre, PostActivate is now PostMount and PreDeactivate is now PreUnmount + dst.Data.RawStorage.CmdLines.PostActivate = src.Data.RawStorage.CmdLines.PostMount + dst.Data.XFSStorage.CmdLines.PostActivate = src.Data.XFSStorage.CmdLines.PostMount + dst.Data.GFS2Storage.CmdLines.PostActivate = src.Data.GFS2Storage.CmdLines.PostMount + dst.Data.RawStorage.CmdLines.PreDeactivate = src.Data.RawStorage.CmdLines.PreUnmount + dst.Data.XFSStorage.CmdLines.PreDeactivate = src.Data.XFSStorage.CmdLines.PreUnmount + dst.Data.GFS2Storage.CmdLines.PreDeactivate = src.Data.GFS2Storage.CmdLines.PreUnmount + // Preserve Hub data on down-conversion except for metadata. return utilconversion.MarshalData(src, dst) } @@ -599,3 +633,21 @@ func (src *NnfSystemStorageList) ConvertTo(dstRaw conversion.Hub) error { func (dst *NnfSystemStorageList) ConvertFrom(srcRaw conversion.Hub) error { return apierrors.NewMethodNotSupported(resource("NnfSystemStorageList"), "ConvertFrom") } + +// The conversion-gen tool dropped these from zz_generated.conversion.go to +// force us to acknowledge that we are addressing the conversion requirements. + +// Convert_v1alpha3_NnfStorageProfileCmdLines_To_v1alpha4_NnfStorageProfileCmdLines is an autogenerated conversion function. +func Convert_v1alpha3_NnfStorageProfileCmdLines_To_v1alpha4_NnfStorageProfileCmdLines(in *NnfStorageProfileCmdLines, out *nnfv1alpha4.NnfStorageProfileCmdLines, s apiconversion.Scope) error { + return autoConvert_v1alpha3_NnfStorageProfileCmdLines_To_v1alpha4_NnfStorageProfileCmdLines(in, out, s) +} + +// Convert_v1alpha4_NnfStorageProfileCmdLines_To_v1alpha3_NnfStorageProfileCmdLines is an autogenerated conversion function. +func Convert_v1alpha4_NnfStorageProfileCmdLines_To_v1alpha3_NnfStorageProfileCmdLines(in *nnfv1alpha4.NnfStorageProfileCmdLines, out *NnfStorageProfileCmdLines, s apiconversion.Scope) error { + return autoConvert_v1alpha4_NnfStorageProfileCmdLines_To_v1alpha3_NnfStorageProfileCmdLines(in, out, s) +} + +// Convert_v1alpha4_NnfStorageProfileLustreCmdLines_To_v1alpha3_NnfStorageProfileLustreCmdLines is an autogenerated conversion function. +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) +} diff --git a/api/v1alpha3/zz_generated.conversion.go b/api/v1alpha3/zz_generated.conversion.go index 1f6d905f..dd057153 100644 --- a/api/v1alpha3/zz_generated.conversion.go +++ b/api/v1alpha3/zz_generated.conversion.go @@ -703,16 +703,6 @@ func RegisterConversions(s *runtime.Scheme) error { }); err != nil { return err } - if err := s.AddGeneratedConversionFunc((*NnfStorageProfileCmdLines)(nil), (*v1alpha4.NnfStorageProfileCmdLines)(nil), func(a, b interface{}, scope conversion.Scope) error { - return Convert_v1alpha3_NnfStorageProfileCmdLines_To_v1alpha4_NnfStorageProfileCmdLines(a.(*NnfStorageProfileCmdLines), b.(*v1alpha4.NnfStorageProfileCmdLines), scope) - }); err != nil { - return err - } - if err := s.AddGeneratedConversionFunc((*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 { - return err - } if err := s.AddGeneratedConversionFunc((*NnfStorageProfileData)(nil), (*v1alpha4.NnfStorageProfileData)(nil), func(a, b interface{}, scope conversion.Scope) error { return Convert_v1alpha3_NnfStorageProfileData_To_v1alpha4_NnfStorageProfileData(a.(*NnfStorageProfileData), b.(*v1alpha4.NnfStorageProfileData), scope) }); err != nil { @@ -768,11 +758,6 @@ func RegisterConversions(s *runtime.Scheme) error { }); err != nil { return err } - if err := s.AddGeneratedConversionFunc((*v1alpha4.NnfStorageProfileLustreCmdLines)(nil), (*NnfStorageProfileLustreCmdLines)(nil), func(a, b interface{}, scope conversion.Scope) error { - return Convert_v1alpha4_NnfStorageProfileLustreCmdLines_To_v1alpha3_NnfStorageProfileLustreCmdLines(a.(*v1alpha4.NnfStorageProfileLustreCmdLines), b.(*NnfStorageProfileLustreCmdLines), scope) - }); err != nil { - return err - } if err := s.AddGeneratedConversionFunc((*NnfStorageProfileLustreData)(nil), (*v1alpha4.NnfStorageProfileLustreData)(nil), func(a, b interface{}, scope conversion.Scope) error { return Convert_v1alpha3_NnfStorageProfileLustreData_To_v1alpha4_NnfStorageProfileLustreData(a.(*NnfStorageProfileLustreData), b.(*v1alpha4.NnfStorageProfileLustreData), scope) }); err != nil { @@ -873,6 +858,21 @@ func RegisterConversions(s *runtime.Scheme) error { }); err != nil { return err } + if err := s.AddConversionFunc((*NnfStorageProfileCmdLines)(nil), (*v1alpha4.NnfStorageProfileCmdLines)(nil), func(a, b interface{}, scope conversion.Scope) error { + return Convert_v1alpha3_NnfStorageProfileCmdLines_To_v1alpha4_NnfStorageProfileCmdLines(a.(*NnfStorageProfileCmdLines), b.(*v1alpha4.NnfStorageProfileCmdLines), 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 { + return err + } + if err := s.AddConversionFunc((*v1alpha4.NnfStorageProfileLustreCmdLines)(nil), (*NnfStorageProfileLustreCmdLines)(nil), func(a, b interface{}, scope conversion.Scope) error { + return Convert_v1alpha4_NnfStorageProfileLustreCmdLines_To_v1alpha3_NnfStorageProfileLustreCmdLines(a.(*v1alpha4.NnfStorageProfileLustreCmdLines), b.(*NnfStorageProfileLustreCmdLines), scope) + }); err != nil { + return err + } return nil } @@ -2658,17 +2658,12 @@ func autoConvert_v1alpha3_NnfStorageProfileCmdLines_To_v1alpha4_NnfStorageProfil } out.LvRemove = in.LvRemove out.MountRabbit = in.MountRabbit - out.PostActivate = *(*[]string)(unsafe.Pointer(&in.PostActivate)) + // WARNING: in.PostActivate requires manual conversion: does not exist in peer-type out.MountCompute = in.MountCompute - out.PreDeactivate = *(*[]string)(unsafe.Pointer(&in.PreDeactivate)) + // WARNING: in.PreDeactivate requires manual conversion: does not exist in peer-type return nil } -// Convert_v1alpha3_NnfStorageProfileCmdLines_To_v1alpha4_NnfStorageProfileCmdLines is an autogenerated conversion function. -func Convert_v1alpha3_NnfStorageProfileCmdLines_To_v1alpha4_NnfStorageProfileCmdLines(in *NnfStorageProfileCmdLines, out *v1alpha4.NnfStorageProfileCmdLines, s conversion.Scope) error { - return autoConvert_v1alpha3_NnfStorageProfileCmdLines_To_v1alpha4_NnfStorageProfileCmdLines(in, out, s) -} - func autoConvert_v1alpha4_NnfStorageProfileCmdLines_To_v1alpha3_NnfStorageProfileCmdLines(in *v1alpha4.NnfStorageProfileCmdLines, out *NnfStorageProfileCmdLines, s conversion.Scope) error { out.Mkfs = in.Mkfs out.SharedVg = in.SharedVg @@ -2685,17 +2680,12 @@ func autoConvert_v1alpha4_NnfStorageProfileCmdLines_To_v1alpha3_NnfStorageProfil } out.LvRemove = in.LvRemove out.MountRabbit = in.MountRabbit - out.PostActivate = *(*[]string)(unsafe.Pointer(&in.PostActivate)) + // WARNING: in.PostMount requires manual conversion: does not exist in peer-type out.MountCompute = in.MountCompute - out.PreDeactivate = *(*[]string)(unsafe.Pointer(&in.PreDeactivate)) + // WARNING: in.PreUnmount requires manual conversion: does not exist in peer-type return nil } -// Convert_v1alpha4_NnfStorageProfileCmdLines_To_v1alpha3_NnfStorageProfileCmdLines is an autogenerated conversion function. -func Convert_v1alpha4_NnfStorageProfileCmdLines_To_v1alpha3_NnfStorageProfileCmdLines(in *v1alpha4.NnfStorageProfileCmdLines, out *NnfStorageProfileCmdLines, s conversion.Scope) error { - return autoConvert_v1alpha4_NnfStorageProfileCmdLines_To_v1alpha3_NnfStorageProfileCmdLines(in, out, s) -} - func autoConvert_v1alpha3_NnfStorageProfileData_To_v1alpha4_NnfStorageProfileData(in *NnfStorageProfileData, out *v1alpha4.NnfStorageProfileData, s conversion.Scope) error { out.Default = in.Default out.Pinned = in.Pinned @@ -2816,7 +2806,17 @@ func Convert_v1alpha4_NnfStorageProfileLVMVgChangeCmdLines_To_v1alpha3_NnfStorag func autoConvert_v1alpha3_NnfStorageProfileList_To_v1alpha4_NnfStorageProfileList(in *NnfStorageProfileList, out *v1alpha4.NnfStorageProfileList, s conversion.Scope) error { out.ListMeta = in.ListMeta - out.Items = *(*[]v1alpha4.NnfStorageProfile)(unsafe.Pointer(&in.Items)) + if in.Items != nil { + in, out := &in.Items, &out.Items + *out = make([]v1alpha4.NnfStorageProfile, len(*in)) + for i := range *in { + if err := Convert_v1alpha3_NnfStorageProfile_To_v1alpha4_NnfStorageProfile(&(*in)[i], &(*out)[i], s); err != nil { + return err + } + } + } else { + out.Items = nil + } return nil } @@ -2827,7 +2827,17 @@ func Convert_v1alpha3_NnfStorageProfileList_To_v1alpha4_NnfStorageProfileList(in func autoConvert_v1alpha4_NnfStorageProfileList_To_v1alpha3_NnfStorageProfileList(in *v1alpha4.NnfStorageProfileList, out *NnfStorageProfileList, s conversion.Scope) error { out.ListMeta = in.ListMeta - out.Items = *(*[]NnfStorageProfile)(unsafe.Pointer(&in.Items)) + if in.Items != nil { + in, out := &in.Items, &out.Items + *out = make([]NnfStorageProfile, len(*in)) + for i := range *in { + if err := Convert_v1alpha4_NnfStorageProfile_To_v1alpha3_NnfStorageProfile(&(*in)[i], &(*out)[i], s); err != nil { + return err + } + } + } else { + out.Items = nil + } return nil } @@ -2855,15 +2865,12 @@ func autoConvert_v1alpha4_NnfStorageProfileLustreCmdLines_To_v1alpha3_NnfStorage out.Mkfs = in.Mkfs out.MountTarget = in.MountTarget out.PostActivate = *(*[]string)(unsafe.Pointer(&in.PostActivate)) + // WARNING: in.PostMount requires manual conversion: does not exist in peer-type + // WARNING: in.PreUnmount requires manual conversion: does not exist in peer-type out.PreDeactivate = *(*[]string)(unsafe.Pointer(&in.PreDeactivate)) return nil } -// Convert_v1alpha4_NnfStorageProfileLustreCmdLines_To_v1alpha3_NnfStorageProfileLustreCmdLines is an autogenerated conversion function. -func Convert_v1alpha4_NnfStorageProfileLustreCmdLines_To_v1alpha3_NnfStorageProfileLustreCmdLines(in *v1alpha4.NnfStorageProfileLustreCmdLines, out *NnfStorageProfileLustreCmdLines, s conversion.Scope) error { - return autoConvert_v1alpha4_NnfStorageProfileLustreCmdLines_To_v1alpha3_NnfStorageProfileLustreCmdLines(in, out, s) -} - func autoConvert_v1alpha3_NnfStorageProfileLustreData_To_v1alpha4_NnfStorageProfileLustreData(in *NnfStorageProfileLustreData, out *v1alpha4.NnfStorageProfileLustreData, s conversion.Scope) error { out.CombinedMGTMDT = in.CombinedMGTMDT out.ExternalMGS = in.ExternalMGS diff --git a/api/v1alpha4/nnfstorage_types.go b/api/v1alpha4/nnfstorage_types.go index f2577b24..b9ab275c 100644 --- a/api/v1alpha4/nnfstorage_types.go +++ b/api/v1alpha4/nnfstorage_types.go @@ -28,7 +28,8 @@ import ( ) const ( - AllocationSetLabel = "nnf.cray.hpe.com/allocationset" + AllocationSetLabel = "nnf.cray.hpe.com/allocationset" + AllocationSetOST0Label = "nnf.cray.hpe.com/allocationset_ost0" ) // NnfStorageAllocationNodes identifies the node and properties of the allocation to make on that node diff --git a/api/v1alpha4/nnfstorageprofile_types.go b/api/v1alpha4/nnfstorageprofile_types.go index 6adc8b05..6370606e 100644 --- a/api/v1alpha4/nnfstorageprofile_types.go +++ b/api/v1alpha4/nnfstorageprofile_types.go @@ -46,6 +46,16 @@ type NnfStorageProfileLustreCmdLines struct { // Lustre target has been activated PostActivate []string `json:"postActivate,omitempty"` + // PostMount specifies a list of commands to run on the Rabbit (Lustre client) after the Lustre + // target is activated. This includes mounting the Lustre filesystem beforehand and unmounting + // it afterward. + PostMount []string `json:"postMount,omitempty"` + + // PreUnmount specifies a list of commands to run on the Rabbit (Lustre client) before the + // Lustre target is deactivated. This includes mounting the Lustre filesystem beforehand and + // unmounting it afterward. + PreUnmount []string `json:"preUnmount,omitempty"` + // PreDeactivate specifies a list of commands to run on the Rabbit before the // Lustre target is deactivated PreDeactivate []string `json:"preDeactivate,omitempty"` @@ -178,16 +188,16 @@ type NnfStorageProfileCmdLines struct { // MountRabbit specifies mount options for mounting on the Rabbit. MountRabbit string `json:"mountRabbit,omitempty"` - // PreDeactivate specifies a list of commands to run on the Rabbit after the - // file system has been activated - PostActivate []string `json:"postActivate,omitempty"` + // PostMount specifies a list of commands to run on the Rabbit after the + // file system has been activated and mounted. + PostMount []string `json:"postMount,omitempty"` // MountCompute specifies mount options for mounting on the Compute. MountCompute string `json:"mountCompute,omitempty"` - // PreDeactivate specifies a list of commands to run on the Rabbit before the - // file system is deactivated - PreDeactivate []string `json:"preDeactivate,omitempty"` + // PreUnmount specifies a list of commands to run on the Rabbit before the + // file system is deactivated and unmounted. + PreUnmount []string `json:"preUnmount,omitempty"` } // NnfStorageProfileLVMVgChangeCmdLines diff --git a/api/v1alpha4/zz_generated.deepcopy.go b/api/v1alpha4/zz_generated.deepcopy.go index a9b084bb..dbbf2b92 100644 --- a/api/v1alpha4/zz_generated.deepcopy.go +++ b/api/v1alpha4/zz_generated.deepcopy.go @@ -1646,13 +1646,13 @@ func (in *NnfStorageProfileCmdLines) DeepCopyInto(out *NnfStorageProfileCmdLines *out = *in out.VgChange = in.VgChange out.LvChange = in.LvChange - if in.PostActivate != nil { - in, out := &in.PostActivate, &out.PostActivate + if in.PostMount != nil { + in, out := &in.PostMount, &out.PostMount *out = make([]string, len(*in)) copy(*out, *in) } - if in.PreDeactivate != nil { - in, out := &in.PreDeactivate, &out.PreDeactivate + if in.PreUnmount != nil { + in, out := &in.PreUnmount, &out.PreUnmount *out = make([]string, len(*in)) copy(*out, *in) } @@ -1778,6 +1778,16 @@ func (in *NnfStorageProfileLustreCmdLines) DeepCopyInto(out *NnfStorageProfileLu *out = make([]string, len(*in)) copy(*out, *in) } + if in.PostMount != nil { + in, out := &in.PostMount, &out.PostMount + *out = make([]string, len(*in)) + copy(*out, *in) + } + if in.PreUnmount != nil { + in, out := &in.PreUnmount, &out.PreUnmount + *out = make([]string, len(*in)) + copy(*out, *in) + } if in.PreDeactivate != nil { in, out := &in.PreDeactivate, &out.PreDeactivate *out = make([]string, len(*in)) diff --git a/config/crd/bases/nnf.cray.hpe.com_nnfstorageprofiles.yaml b/config/crd/bases/nnf.cray.hpe.com_nnfstorageprofiles.yaml index 9ed1addf..adfd59a4 100644 --- a/config/crd/bases/nnf.cray.hpe.com_nnfstorageprofiles.yaml +++ b/config/crd/bases/nnf.cray.hpe.com_nnfstorageprofiles.yaml @@ -1923,17 +1923,17 @@ spec: description: MountRabbit specifies mount options for mounting on the Rabbit. type: string - postActivate: + postMount: description: |- - PreDeactivate specifies a list of commands to run on the Rabbit after the - file system has been activated + PostMount specifies a list of commands to run on the Rabbit after the + file system has been activated and mounted. items: type: string type: array - preDeactivate: + preUnmount: description: |- - PreDeactivate specifies a list of commands to run on the Rabbit before the - file system is deactivated + PreUnmount specifies a list of commands to run on the Rabbit before the + file system is deactivated and unmounted. items: type: string type: array @@ -2041,6 +2041,14 @@ spec: items: type: string type: array + postMount: + description: |- + PostMount specifies a list of commands to run on the Rabbit (Lustre client) after the Lustre + target is activated. This includes mounting the Lustre filesystem beforehand and unmounting + it afterward. + items: + type: string + type: array preDeactivate: description: |- PreDeactivate specifies a list of commands to run on the Rabbit before the @@ -2048,6 +2056,14 @@ spec: items: type: string type: array + preUnmount: + description: |- + PreUnmount specifies a list of commands to run on the Rabbit (Lustre client) before the + Lustre target is deactivated. This includes mounting the Lustre filesystem beforehand and + unmounting it afterward. + items: + type: string + type: array zpoolCreate: description: |- ZpoolCreate specifies the zpool create commandline, minus the "zpool create". @@ -2107,6 +2123,14 @@ spec: items: type: string type: array + postMount: + description: |- + PostMount specifies a list of commands to run on the Rabbit (Lustre client) after the Lustre + target is activated. This includes mounting the Lustre filesystem beforehand and unmounting + it afterward. + items: + type: string + type: array preDeactivate: description: |- PreDeactivate specifies a list of commands to run on the Rabbit before the @@ -2114,6 +2138,14 @@ spec: items: type: string type: array + preUnmount: + description: |- + PreUnmount specifies a list of commands to run on the Rabbit (Lustre client) before the + Lustre target is deactivated. This includes mounting the Lustre filesystem beforehand and + unmounting it afterward. + items: + type: string + type: array zpoolCreate: description: |- ZpoolCreate specifies the zpool create commandline, minus the "zpool create". @@ -2144,6 +2176,14 @@ spec: items: type: string type: array + postMount: + description: |- + PostMount specifies a list of commands to run on the Rabbit (Lustre client) after the Lustre + target is activated. This includes mounting the Lustre filesystem beforehand and unmounting + it afterward. + items: + type: string + type: array preDeactivate: description: |- PreDeactivate specifies a list of commands to run on the Rabbit before the @@ -2151,6 +2191,14 @@ spec: items: type: string type: array + preUnmount: + description: |- + PreUnmount specifies a list of commands to run on the Rabbit (Lustre client) before the + Lustre target is deactivated. This includes mounting the Lustre filesystem beforehand and + unmounting it afterward. + items: + type: string + type: array zpoolCreate: description: |- ZpoolCreate specifies the zpool create commandline, minus the "zpool create". @@ -2248,6 +2296,14 @@ spec: items: type: string type: array + postMount: + description: |- + PostMount specifies a list of commands to run on the Rabbit (Lustre client) after the Lustre + target is activated. This includes mounting the Lustre filesystem beforehand and unmounting + it afterward. + items: + type: string + type: array preDeactivate: description: |- PreDeactivate specifies a list of commands to run on the Rabbit before the @@ -2255,6 +2311,14 @@ spec: items: type: string type: array + preUnmount: + description: |- + PreUnmount specifies a list of commands to run on the Rabbit (Lustre client) before the + Lustre target is deactivated. This includes mounting the Lustre filesystem beforehand and + unmounting it afterward. + items: + type: string + type: array zpoolCreate: description: |- ZpoolCreate specifies the zpool create commandline, minus the "zpool create". @@ -2348,17 +2412,17 @@ spec: description: MountRabbit specifies mount options for mounting on the Rabbit. type: string - postActivate: + postMount: description: |- - PreDeactivate specifies a list of commands to run on the Rabbit after the - file system has been activated + PostMount specifies a list of commands to run on the Rabbit after the + file system has been activated and mounted. items: type: string type: array - preDeactivate: + preUnmount: description: |- - PreDeactivate specifies a list of commands to run on the Rabbit before the - file system is deactivated + PreUnmount specifies a list of commands to run on the Rabbit before the + file system is deactivated and unmounted. items: type: string type: array @@ -2451,17 +2515,17 @@ spec: description: MountRabbit specifies mount options for mounting on the Rabbit. type: string - postActivate: + postMount: description: |- - PreDeactivate specifies a list of commands to run on the Rabbit after the - file system has been activated + PostMount specifies a list of commands to run on the Rabbit after the + file system has been activated and mounted. items: type: string type: array - preDeactivate: + preUnmount: description: |- - PreDeactivate specifies a list of commands to run on the Rabbit before the - file system is deactivated + PreUnmount specifies a list of commands to run on the Rabbit before the + file system is deactivated and unmounted. items: type: string type: array diff --git a/config/examples/nnf_nnfstorageprofile.yaml b/config/examples/nnf_nnfstorageprofile.yaml index 74211b41..73b0a676 100644 --- a/config/examples/nnf_nnfstorageprofile.yaml +++ b/config/examples/nnf_nnfstorageprofile.yaml @@ -23,6 +23,8 @@ data: zpoolCreate: -O canmount=off -o cachefile=none $POOL_NAME $DEVICE_LIST mkfs: --ost --backfstype=$BACKFS --fsname=$FS_NAME --mgsnode=$MGS_NID --index=$INDEX $ZVOL_NAME mountTarget: $ZVOL_NAME $MOUNT_PATH + postMount: + - 'lfs setstripe -E 64K -L mdt -E 16m -c 1 -S 16m -E 1G -c 2 -E 4G -c 4 -E 16G -c 8 -E 64G -c 16 -E -1 -c -1 $MOUNT_PATH' ostOptions: scale: 5 colocateComputes: true @@ -52,8 +54,8 @@ data: mkfs: -j2 -p $PROTOCOL -t $CLUSTER_NAME:$LOCK_SPACE $DEVICE mountRabbit: $DEVICE $MOUNT_PATH mountCompute: $DEVICE $MOUNT_PATH - postActivate: - - "chown $USERID:$GROUPID $MOUNT_PATH" + postMount: + - 'chown $USERID:$GROUPID $MOUNT_PATH' xfsStorage: commandlines: sharedVg: true @@ -72,8 +74,8 @@ data: mkfs: $DEVICE mountRabbit: $DEVICE $MOUNT_PATH mountCompute: $DEVICE $MOUNT_PATH - postActivate: - - "chown $USERID:$GROUPID $MOUNT_PATH" + postMount: + - 'chown $USERID:$GROUPID $MOUNT_PATH' rawStorage: commandlines: sharedVg: true @@ -89,5 +91,3 @@ data: activate: --activate y $VG_NAME/$LV_NAME deactivate: --activate n $VG_NAME/$LV_NAME lvRemove: $VG_NAME - - diff --git a/internal/controller/filesystem_helpers.go b/internal/controller/filesystem_helpers.go index e81dc58f..cb176cb3 100644 --- a/internal/controller/filesystem_helpers.go +++ b/internal/controller/filesystem_helpers.go @@ -348,8 +348,8 @@ func newBindFileSystem(ctx context.Context, c client.Client, nnfNodeStorage *nnf fs.TempDir = fmt.Sprintf("/mnt/temp/%s-%d", nnfNodeStorage.Name, index) fs.CommandArgs.Mount = "-o bind $DEVICE $MOUNT_PATH" - fs.CommandArgs.PostActivate = cmdLines.PostActivate - fs.CommandArgs.PreDeactivate = cmdLines.PreDeactivate + fs.CommandArgs.PostMount = cmdLines.PostMount + fs.CommandArgs.PreUnmount = cmdLines.PreUnmount fs.CommandArgs.Vars = map[string]string{ "$USERID": fmt.Sprintf("%d", nnfNodeStorage.Spec.UserID), "$GROUPID": fmt.Sprintf("%d", nnfNodeStorage.Spec.GroupID), @@ -372,8 +372,8 @@ func newGfs2FileSystem(ctx context.Context, c client.Client, nnfNodeStorage *nnf } else { fs.CommandArgs.Mount = cmdLines.MountCompute } - fs.CommandArgs.PostActivate = cmdLines.PostActivate - fs.CommandArgs.PreDeactivate = cmdLines.PreDeactivate + fs.CommandArgs.PostMount = cmdLines.PostMount + fs.CommandArgs.PreUnmount = cmdLines.PreUnmount fs.CommandArgs.Mkfs = fmt.Sprintf("-O %s", cmdLines.Mkfs) fs.CommandArgs.Vars = map[string]string{ "$CLUSTER_NAME": nnfNodeStorage.Namespace, @@ -400,8 +400,8 @@ func newXfsFileSystem(ctx context.Context, c client.Client, nnfNodeStorage *nnfv } else { fs.CommandArgs.Mount = cmdLines.MountCompute } - fs.CommandArgs.PostActivate = cmdLines.PostActivate - fs.CommandArgs.PreDeactivate = cmdLines.PreDeactivate + fs.CommandArgs.PostMount = cmdLines.PostMount + fs.CommandArgs.PreUnmount = cmdLines.PreUnmount fs.CommandArgs.Mkfs = cmdLines.Mkfs fs.CommandArgs.Vars = map[string]string{ "$USERID": fmt.Sprintf("%d", nnfNodeStorage.Spec.UserID), @@ -427,12 +427,15 @@ func newLustreFileSystem(ctx context.Context, c client.Client, nnfNodeStorage *n fs.MgsAddress = nnfNodeStorage.Spec.LustreStorage.MgsAddress fs.Index = nnfNodeStorage.Spec.LustreStorage.StartIndex + index fs.BackFs = nnfNodeStorage.Spec.LustreStorage.BackFs - fs.CommandArgs.Mkfs = cmdLines.Mkfs fs.CommandArgs.MountTarget = cmdLines.MountTarget fs.CommandArgs.Mount = mountCommand fs.CommandArgs.PostActivate = cmdLines.PostActivate + fs.CommandArgs.PostMount = cmdLines.PostMount + fs.CommandArgs.PreUnmount = cmdLines.PreUnmount fs.CommandArgs.PreDeactivate = cmdLines.PreDeactivate + fs.TempDir = fmt.Sprintf("/mnt/temp/%s-%d", nnfNodeStorage.Name, index) + fs.CommandArgs.Vars = map[string]string{ "$USERID": fmt.Sprintf("%d", nnfNodeStorage.Spec.UserID), "$GROUPID": fmt.Sprintf("%d", nnfNodeStorage.Spec.GroupID), diff --git a/internal/controller/integration_test.go b/internal/controller/integration_test.go index 6dc224dc..b36f0b02 100644 --- a/internal/controller/integration_test.go +++ b/internal/controller/integration_test.go @@ -94,7 +94,10 @@ var _ = Describe("Integration Test", func() { }, } - Expect(k8sClient.Get(context.TODO(), client.ObjectKeyFromObject(nnfNodeStorage), nnfNodeStorage)).To(Succeed()) + Eventually(func() error { + return k8sClient.Get(context.TODO(), client.ObjectKeyFromObject(nnfNodeStorage), nnfNodeStorage) + }).Should(Succeed()) + By("Verify that the NnfNodeStorage has a label for the pinned profile") _, err := getPinnedStorageProfileFromLabel(context.TODO(), k8sClient, nnfNodeStorage) Expect(err).ShouldNot(HaveOccurred()) diff --git a/internal/controller/nnf_access_controller.go b/internal/controller/nnf_access_controller.go index 9b85780e..ab206a52 100644 --- a/internal/controller/nnf_access_controller.go +++ b/internal/controller/nnf_access_controller.go @@ -1093,25 +1093,27 @@ func (r *NnfAccessReconciler) getClientMountStatus(ctx context.Context, access * } // Check whether the clientmounts have finished mounting/unmounting + count := 0 for _, clientMount := range clientMounts { if len(clientMount.Status.Mounts) != len(clientMount.Spec.Mounts) { return false, nil } for _, mount := range clientMount.Status.Mounts { + count++ if string(mount.State) != access.Status.State { return false, nil } - if mount.Ready == false { + if !mount.Ready { return false, nil } } } - if len(clientMounts) != len(clientList) { + if count != len(clientList) { if access.GetDeletionTimestamp().IsZero() { - log.Info("unexpected number of ClientMounts", "found", len(clientMounts), "expected", len(clientList)) + log.Info("unexpected number of ClientMounts", "found", count, "expected", len(clientList)) } return false, nil } diff --git a/internal/controller/nnf_node_storage_controller.go b/internal/controller/nnf_node_storage_controller.go index e9f27ca2..e40604a1 100644 --- a/internal/controller/nnf_node_storage_controller.go +++ b/internal/controller/nnf_node_storage_controller.go @@ -49,8 +49,6 @@ const ( // prevents the system from deleting the custom resource until the // reconciler has finished using the resource. finalizerNnfNodeStorage = "nnf.cray.hpe.com/nnf_node_storage" - - nnfNodeStorageResourceName = "nnf-node-storage" ) // NnfNodeStorageReconciler contains the elements needed during reconciliation for NnfNodeStorage @@ -216,7 +214,7 @@ func (r *NnfNodeStorageReconciler) Reconcile(ctx context.Context, req ctrl.Reque } for _, allocation := range nnfNodeStorage.Status.Allocations { - if allocation.Ready == false { + if !allocation.Ready { nnfNodeStorage.Status.Ready = false return ctrl.Result{Requeue: true}, nil @@ -259,6 +257,17 @@ func (r *NnfNodeStorageReconciler) deleteAllocation(ctx context.Context, nnfNode log.Info("Activated file system", "allocation", index) } + lustreOST0 := nnfNodeStorage.Spec.FileSystemType == "lustre" && nnfNodeStorage.Spec.LustreStorage.TargetType == "ost" && nnfNodeStorage.Spec.LustreStorage.StartIndex == 0 + if lustreOST0 || nnfNodeStorage.Spec.FileSystemType != "lustre" { + ran, err = fileSystem.PreUnmount(ctx) + if err != nil { + return nil, dwsv1alpha2.NewResourceError("could not run pre unmount for file system").WithError(err).WithMajor() + } + if ran { + log.Info("Pre unmount file system", "allocation", index) + } + } + ran, err = fileSystem.PreDeactivate(ctx) if err != nil { return nil, dwsv1alpha2.NewResourceError("could not run pre deactivate for file system").WithError(err).WithMajor() @@ -363,6 +372,19 @@ func (r *NnfNodeStorageReconciler) createAllocations(ctx context.Context, nnfNod log.Info("Post activate file system", "allocation", index) } + // For lustre, PostMount should only happen on OST0 only. For other file systems, just run + // PostMount + lustreOST0 := nnfNodeStorage.Spec.FileSystemType == "lustre" && nnfNodeStorage.Spec.LustreStorage.TargetType == "ost" && nnfNodeStorage.Spec.LustreStorage.StartIndex == 0 + if lustreOST0 || nnfNodeStorage.Spec.FileSystemType != "lustre" { + ran, err = fileSystem.PostMount(ctx, allocationStatus.Ready) + if err != nil { + return nil, dwsv1alpha2.NewResourceError("could not run post mount").WithError(err).WithMajor() + } + if ran { + log.Info("Post mount file system", "allocation", index) + } + } + allocationStatus.Ready = true } diff --git a/internal/controller/nnf_storage_controller.go b/internal/controller/nnf_storage_controller.go index 05e805cb..d9cd6e3e 100644 --- a/internal/controller/nnf_storage_controller.go +++ b/internal/controller/nnf_storage_controller.go @@ -63,10 +63,6 @@ const ( // has finished in using the resource. finalizerNnfStorage = "nnf.cray.hpe.com/nnf_storage" - // ownerAnnotation is a name/namespace pair used on the NnfNodeStorage resources - // for owner information. See nnfNodeStorageMapFunc() below. - ownerAnnotation = "nnf.cray.hpe.com/owner" - // Minimum size of lustre allocation sizes. If a user requests less than this, then the capacity // is set to this value. minimumLustreAllocationSizeInBytes = 4000000000 @@ -218,7 +214,7 @@ func (r *NnfStorageReconciler) Reconcile(ctx context.Context, req ctrl.Request) // Collect status information from the NnfNodeStorage resources and aggregate it into the // NnfStorage for i := range storage.Spec.AllocationSets { - res, err := r.aggregateNodeStorageStatus(ctx, storage, i, false) + res, err := r.aggregateNodeStorageStatus(ctx, storage, i, false, false) if err != nil { return ctrl.Result{}, err } @@ -234,12 +230,12 @@ func (r *NnfStorageReconciler) Reconcile(ctx context.Context, req ctrl.Request) // Wait for all the allocation sets to be ready for _, allocationSet := range storage.Status.AllocationSets { - if allocationSet.Ready == false { + if !allocationSet.Ready { return ctrl.Result{}, nil } } - if storage.Spec.FileSystemType == "lustre" && storage.Status.Ready == false { + if storage.Spec.FileSystemType == "lustre" && !storage.Status.Ready { res, err := r.setLustreOwnerGroup(ctx, storage) if err != nil { return ctrl.Result{}, err @@ -470,7 +466,7 @@ func (r *NnfStorageReconciler) aggregateNodeBlockStorageStatus(ctx context.Conte } for _, nnfNodeBlockStorage := range nnfNodeBlockStorages { - if nnfNodeBlockStorage.Status.Ready == false { + if !nnfNodeBlockStorage.Status.Ready { return &ctrl.Result{}, nil } } @@ -503,7 +499,7 @@ func (r *NnfStorageReconciler) createNodeStorage(ctx context.Context, storage *n if allocationSet.TargetType == "mgt" || allocationSet.TargetType == "mgtmdt" { // Wait for the MGT to be set up before creating nnfnodestorages for the other allocation sets if allocationSetIndex != i { - if storage.Status.AllocationSets[i].Ready == false { + if !storage.Status.AllocationSets[i].Ready { return nil, nil } } @@ -573,6 +569,31 @@ func (r *NnfStorageReconciler) createNodeStorage(ctx context.Context, storage *n } allocationSet := storage.Spec.AllocationSets[allocationSetIndex] + lustreOST := storage.Spec.FileSystemType == "lustre" && allocationSet.TargetType == "ost" + + // When creating lustre filesystems, we want to create Lustre OST0 last so we can signal to the + // NnfNodeStorage controller when it is OK to run PostMount commands. OST0 should be created + // last and only when all of the other NnfNodeStorage for each allocation sets is ready. Until + // those are ready, skip the creation of OST0. + skipOST0 := false + if lustreOST { + for i := range storage.Spec.AllocationSets { + res, err := r.aggregateNodeStorageStatus(ctx, storage, i, false, true) + if err != nil { + return &ctrl.Result{}, err + } + + if res != nil { + if *res == (ctrl.Result{}) { + skipOST0 = true // not ready, skip OST0 + continue + } else { + return res, nil + } + } + } + } + startIndex := 0 for i, node := range allocationSet.Nodes { // Per Rabbit namespace. @@ -583,6 +604,12 @@ func (r *NnfStorageReconciler) createNodeStorage(ctx context.Context, storage *n }, } + // Do not create lustre OST0 until all other NnfNodeStorages are ready + if lustreOST && startIndex == 0 && skipOST0 { + startIndex += node.Count + continue + } + result, err := ctrl.CreateOrUpdate(ctx, r.Client, nnfNodeStorage, func() error { dwsv1alpha2.InheritParentLabels(nnfNodeStorage, storage) @@ -590,6 +617,9 @@ func (r *NnfStorageReconciler) createNodeStorage(ctx context.Context, storage *n labels := nnfNodeStorage.GetLabels() labels[nnfv1alpha4.AllocationSetLabel] = allocationSet.Name + if lustreOST && startIndex == 0 { + labels[nnfv1alpha4.AllocationSetOST0Label] = "true" + } nnfNodeStorage.SetLabels(labels) nnfNodeStorage.Spec.BlockReference = corev1.ObjectReference{ @@ -641,9 +671,11 @@ func (r *NnfStorageReconciler) createNodeStorage(ctx context.Context, storage *n } // Get the status from all the child NnfNodeStorage resources and use them to build the status -// for the NnfStorage. -func (r *NnfStorageReconciler) aggregateNodeStorageStatus(ctx context.Context, storage *nnfv1alpha4.NnfStorage, allocationSetIndex int, deleting bool) (*ctrl.Result, error) { +// for the NnfStorage. When skipOST0 is set, expect 1 less NnfNodeStorage resource when processing +// allocationSets for Lustre OST. +func (r *NnfStorageReconciler) aggregateNodeStorageStatus(ctx context.Context, storage *nnfv1alpha4.NnfStorage, allocationSetIndex int, deleting, skipOST0 bool) (*ctrl.Result, error) { log := r.Log.WithValues("NnfStorage", types.NamespacedName{Name: storage.Name, Namespace: storage.Namespace}) + lustreOST := storage.Spec.FileSystemType == "lustre" && storage.Spec.AllocationSets[allocationSetIndex].TargetType == "ost" nnfNodeStorageList := &nnfv1alpha4.NnfNodeStorageList{} matchLabels := dwsv1alpha2.MatchingOwner(storage) @@ -706,7 +738,7 @@ func (r *NnfStorageReconciler) aggregateNodeStorageStatus(ctx context.Context, s } for _, nnfNodeStorage := range nnfNodeStorages { - if nnfNodeStorage.Status.Ready == false { + if !nnfNodeStorage.Status.Ready { return &ctrl.Result{}, nil } } @@ -714,9 +746,18 @@ func (r *NnfStorageReconciler) aggregateNodeStorageStatus(ctx context.Context, s // Ensure that we found all the NnfNodeStorage resources we were expecting. This can be expected // transiently as it takes time for the client cache to be updated. Log a message in case the count // never reaches the expected value. - if len(nnfNodeStorages) != len(storage.Spec.AllocationSets[allocationSetIndex].Nodes) { + found := len(nnfNodeStorages) + expected := len(storage.Spec.AllocationSets[allocationSetIndex].Nodes) + + // In the Lustre OST0 case, the NnfNodeStorage has not been created yet, so we can safely expect + // 1 less than the total number of OSTs. + if lustreOST && skipOST0 { + expected = expected - 1 + } + + if found != expected { if storage.GetDeletionTimestamp().IsZero() { - log.Info("unexpected number of NnfNodeStorages", "found", len(nnfNodeStorages), "expected", len(storage.Spec.AllocationSets[allocationSetIndex].Nodes)) + log.Info("unexpected number of NnfNodeStorages", "found", found, "expected", expected) } return &ctrl.Result{}, nil } @@ -901,21 +942,16 @@ func (r *NnfStorageReconciler) setLustreOwnerGroup(ctx context.Context, nnfStora return &ctrl.Result{}, dwsv1alpha2.NewResourceError("zero length node array for OST").WithFatal() } - tempMountDir := os.Getenv("NNF_TEMP_MOUNT_PATH") - if len(tempMountDir) == 0 { - tempMountDir = "/mnt/tmp/" - } - dwsv1alpha2.InheritParentLabels(clientMount, nnfStorage) dwsv1alpha2.AddOwnerLabels(clientMount, nnfStorage) clientMount.Spec.Node = allocationSet.Nodes[0].Name clientMount.Spec.DesiredState = dwsv1alpha2.ClientMountStateMounted clientMount.Spec.Mounts = []dwsv1alpha2.ClientMountInfo{ - dwsv1alpha2.ClientMountInfo{ + { Type: nnfStorage.Spec.FileSystemType, TargetType: "directory", - MountPath: fmt.Sprintf("/%s/%s", tempMountDir, nnfNodeStorageName(nnfStorage, index, 0)), + MountPath: getTempClientMountDir(nnfStorage, index), Device: dwsv1alpha2.ClientMountDevice{ Type: dwsv1alpha2.ClientMountDeviceTypeLustre, Lustre: &dwsv1alpha2.ClientMountDeviceLustre{ @@ -955,7 +991,7 @@ func (r *NnfStorageReconciler) setLustreOwnerGroup(ctx context.Context, nnfStora switch clientMount.Status.Mounts[0].State { case dwsv1alpha2.ClientMountStateMounted: - if clientMount.Status.Mounts[0].Ready == false { + if !clientMount.Status.Mounts[0].Ready { return &ctrl.Result{}, nil } @@ -972,7 +1008,7 @@ func (r *NnfStorageReconciler) setLustreOwnerGroup(ctx context.Context, nnfStora return &ctrl.Result{}, nil case dwsv1alpha2.ClientMountStateUnmounted: - if clientMount.Status.Mounts[0].Ready == false { + if !clientMount.Status.Mounts[0].Ready { return &ctrl.Result{}, nil } @@ -983,6 +1019,18 @@ func (r *NnfStorageReconciler) setLustreOwnerGroup(ctx context.Context, nnfStora return &ctrl.Result{}, nil } +func getTempMountDir() string { + tempMountDir := os.Getenv("NNF_TEMP_MOUNT_PATH") + if len(tempMountDir) == 0 { + tempMountDir = "/mnt/tmp/" + } + return tempMountDir +} + +func getTempClientMountDir(nnfStorage *nnfv1alpha4.NnfStorage, index int) string { + return fmt.Sprintf("/%s/%s", getTempMountDir(), nnfNodeStorageName(nnfStorage, index, 0)) +} + // Get the status from all the child NnfNodeStorage resources and use them to build the status // for the NnfStorage. func (r *NnfStorageReconciler) aggregateClientMountStatus(ctx context.Context, storage *nnfv1alpha4.NnfStorage, deleting bool) error { @@ -1031,12 +1079,32 @@ func (r *NnfStorageReconciler) teardownStorage(ctx context.Context, storage *nnf } if storage.Spec.FileSystemType == "lustre" { - // Delete the OSTs and MDTs first so we can drop the claim on the NnfLustreMgt resource. This will trigger - // an lctl command to run to remove the fsname from the MGT. childObjects := []dwsv1alpha2.ObjectList{ &nnfv1alpha4.NnfNodeStorageList{}, } + // Delete OST0 first so that PreUnmount commands can happen + ost0DeleteStatus, err := dwsv1alpha2.DeleteChildrenWithLabels(ctx, r.Client, childObjects, storage, client.MatchingLabels{nnfv1alpha4.AllocationSetOST0Label: "true"}) + if err != nil { + return nodeStoragesExist, err + } + + // Collect status information from the NnfNodeStorage resources and aggregate it into the + // NnfStorage + for i := range storage.Status.AllocationSets { + _, err := r.aggregateNodeStorageStatus(ctx, storage, i, true, false) + if err != nil { + return nodeStoragesExist, err + } + } + + // Ensure OST0 is deleted before continuing + if !ost0DeleteStatus.Complete() { + return nodeStoragesExist, nil + } + + // Then, delete the rest of the OSTs and MDTs so we can drop the claim on the NnfLustreMgt + // resource. This will trigger an lctl command to run to remove the fsname from the MGT. ostDeleteStatus, err := dwsv1alpha2.DeleteChildrenWithLabels(ctx, r.Client, childObjects, storage, client.MatchingLabels{nnfv1alpha4.AllocationSetLabel: "ost"}) if err != nil { return nodeStoragesExist, err @@ -1050,7 +1118,7 @@ func (r *NnfStorageReconciler) teardownStorage(ctx context.Context, storage *nnf // Collect status information from the NnfNodeStorage resources and aggregate it into the // NnfStorage for i := range storage.Status.AllocationSets { - _, err := r.aggregateNodeStorageStatus(ctx, storage, i, true) + _, err := r.aggregateNodeStorageStatus(ctx, storage, i, true, false) if err != nil { return nodeStoragesExist, err } @@ -1091,7 +1159,7 @@ func (r *NnfStorageReconciler) teardownStorage(ctx context.Context, storage *nnf // Collect status information from the NnfNodeStorage resources and aggregate it into the // NnfStorage for i := range storage.Status.AllocationSets { - _, err := r.aggregateNodeStorageStatus(ctx, storage, i, true) + _, err := r.aggregateNodeStorageStatus(ctx, storage, i, true, false) if err != nil { return nodeStoragesExist, err } @@ -1176,6 +1244,34 @@ func nnfNodeStorageName(storage *nnfv1alpha4.NnfStorage, allocationSetIndex int, return storage.Namespace + "-" + storage.Name + "-" + storage.Spec.AllocationSets[allocationSetIndex].Name + "-" + strconv.Itoa(duplicateRabbitIndex) } +// Get the NnfNodeStorage for Lustre OST0 for a given NnfStorage +func (r *NnfStorageReconciler) getLustreOST0(ctx context.Context, storage *nnfv1alpha4.NnfStorage) (*nnfv1alpha4.NnfNodeStorage, error) { + if storage.Spec.FileSystemType != "lustre" { + return nil, nil + } + + // Get al the NnfNodeStorages for the OSTs + nnfNodeStorageList := &nnfv1alpha4.NnfNodeStorageList{} + matchLabels := dwsv1alpha2.MatchingOwner(storage) + matchLabels[nnfv1alpha4.AllocationSetLabel] = "ost" + + listOptions := []client.ListOption{ + matchLabels, + } + + if err := r.List(ctx, nnfNodeStorageList, listOptions...); err != nil { + return nil, dwsv1alpha2.NewResourceError("could not list NnfNodeStorages").WithError(err) + } + + for _, nnfNodeStorage := range nnfNodeStorageList.Items { + if nnfNodeStorage.Spec.LustreStorage.StartIndex == 0 { + return &nnfNodeStorage, nil + } + } + + return nil, nil +} + // SetupWithManager sets up the controller with the Manager. func (r *NnfStorageReconciler) SetupWithManager(mgr ctrl.Manager) error { r.ChildObjects = []dwsv1alpha2.ObjectList{ diff --git a/pkg/filesystem/filesystem.go b/pkg/filesystem/filesystem.go index a2b2d9f1..193dee94 100644 --- a/pkg/filesystem/filesystem.go +++ b/pkg/filesystem/filesystem.go @@ -45,4 +45,10 @@ type FileSystem interface { // Run any commands against the activated file system before it is deactivated PreDeactivate(ctx context.Context) (bool, error) + + // Run any commands against the file system after it has been mounted + PostMount(ctx context.Context, complete bool) (bool, error) + + // Run any commands against the file system before it is unmounted + PreUnmount(ctx context.Context) (bool, error) } diff --git a/pkg/filesystem/kind.go b/pkg/filesystem/kind.go index 6905926e..7aae05ba 100644 --- a/pkg/filesystem/kind.go +++ b/pkg/filesystem/kind.go @@ -1,5 +1,5 @@ /* - * Copyright 2023 Hewlett Packard Enterprise Development LP + * Copyright 2023-2024 Hewlett Packard Enterprise Development LP * Other additional copyright holders may be indicated within. * * The entirety of this work is licensed under the Apache License, @@ -39,7 +39,7 @@ type KindFileSystem struct { var _ FileSystem = &KindFileSystem{} func (m *KindFileSystem) Create(ctx context.Context, complete bool) (bool, error) { - if complete == true { + if complete { return false, nil } @@ -60,7 +60,7 @@ func (m *KindFileSystem) Destroy(ctx context.Context) (bool, error) { } func (m *KindFileSystem) Activate(ctx context.Context, complete bool) (bool, error) { - if complete == true { + if complete { return false, nil } @@ -74,7 +74,7 @@ func (m *KindFileSystem) Deactivate(ctx context.Context) (bool, error) { } func (m *KindFileSystem) Mount(ctx context.Context, path string, complete bool) (bool, error) { - if complete == true { + if complete { return false, nil } @@ -95,7 +95,7 @@ func (m *KindFileSystem) Unmount(ctx context.Context, path string) (bool, error) } func (m *KindFileSystem) PostActivate(ctx context.Context, complete bool) (bool, error) { - if complete == true { + if complete { return false, nil } @@ -109,3 +109,19 @@ func (m *KindFileSystem) PreDeactivate(ctx context.Context) (bool, error) { return true, nil } + +func (m *KindFileSystem) PostMount(ctx context.Context, complete bool) (bool, error) { + if complete { + return false, nil + } + + m.Log.Info("Ran PostMount") + + return true, nil +} + +func (m *KindFileSystem) PreUnmount(ctx context.Context) (bool, error) { + m.Log.Info("Ran PreUnmount") + + return true, nil +} diff --git a/pkg/filesystem/lustre.go b/pkg/filesystem/lustre.go index 6e545989..d705c351 100644 --- a/pkg/filesystem/lustre.go +++ b/pkg/filesystem/lustre.go @@ -1,5 +1,5 @@ /* - * Copyright 2023 Hewlett Packard Enterprise Development LP + * Copyright 2023-2024 Hewlett Packard Enterprise Development LP * Other additional copyright holders may be indicated within. * * The entirety of this work is licensed under the Apache License, @@ -40,6 +40,8 @@ type LustreFileSystemCommandArgs struct { Mount string PostActivate []string PreDeactivate []string + PostMount []string + PreUnmount []string Vars map[string]string } @@ -54,6 +56,7 @@ type LustreFileSystem struct { MgsAddress string Index int BackFs string + TempDir string BlockDevice blockdevice.BlockDevice } @@ -82,7 +85,7 @@ func (l *LustreFileSystem) parseArgs(args string) string { } func (l *LustreFileSystem) Create(ctx context.Context, complete bool) (bool, error) { - if complete == true { + if complete { return false, nil } @@ -212,8 +215,9 @@ func (l *LustreFileSystem) Mount(ctx context.Context, path string, complete bool } // Found an existing mount at this path. Check if it's the mount we expect - if m.Type != "lustre" { - return false, fmt.Errorf("unexpected mount at path %s. Device %s type %s", path, m.Device, m.Type) + devStr := fmt.Sprintf("%s:/%s", l.MgsAddress, l.Name) + if m.Device != devStr || m.Type != "lustre" { + return false, fmt.Errorf("unexpected mount at path %s. Expected device %s of type lustre, found device %s type %s", path, devStr, m.Device, m.Type) } // The file system is already mounted. Nothing left to do @@ -254,8 +258,9 @@ func (l *LustreFileSystem) Unmount(ctx context.Context, path string) (bool, erro } // Found an existing mount at this path. Check if it's the mount we expect - if m.Device != fmt.Sprintf("%s:/%s", l.MgsAddress, l.Name) || m.Type != "lustre" { - return false, fmt.Errorf("unexpected mount at path %s. Device %s type %s", path, m.Device, m.Type) + devStr := fmt.Sprintf("%s:/%s", l.MgsAddress, l.Name) + if m.Device != devStr || m.Type != "lustre" { + return false, fmt.Errorf("unexpected mount at path %s. Expected device %s of type lustre, found device %s type %s", path, devStr, m.Device, m.Type) } if _, err := command.Run(fmt.Sprintf("umount %s", path), l.Log); err != nil { @@ -311,5 +316,84 @@ func (l *LustreFileSystem) PreDeactivate(ctx context.Context) (bool, error) { } } - return false, nil + return true, nil +} + +func (l *LustreFileSystem) PostMount(ctx context.Context, complete bool) (bool, error) { + if len(l.CommandArgs.PostMount) == 0 { + return false, nil + } + + if complete { + return false, nil + } + + if l.TargetType == "none" { + return false, nil + } + + if _, err := l.Mount(ctx, l.TempDir, false); err != nil { + return false, fmt.Errorf("could not mount temp dir '%s' for post mount: %w", l.TempDir, err) + } + + // Build the commands from the args provided + if l.CommandArgs.Vars == nil { + l.CommandArgs.Vars = make(map[string]string) + } + l.CommandArgs.Vars["$MOUNT_PATH"] = filepath.Clean(l.TempDir) + + for _, rawCommand := range l.CommandArgs.PostMount { + formattedCommand := l.parseArgs(rawCommand) + l.Log.Info("PostMount", "command", formattedCommand) + + if _, err := command.Run(formattedCommand, l.Log); err != nil { + if _, unmountErr := l.Unmount(ctx, l.TempDir); unmountErr != nil { + return false, fmt.Errorf("could not unmount after post mount command failed: %s: %w", formattedCommand, unmountErr) + } + return false, fmt.Errorf("could not run post mount command: %s: %w", formattedCommand, err) + } + } + + if _, err := l.Unmount(ctx, l.TempDir); err != nil { + return false, fmt.Errorf("could not unmount after post mount '%s': %w", l.TempDir, err) + } + + return true, nil +} + +func (l *LustreFileSystem) PreUnmount(ctx context.Context) (bool, error) { + if len(l.CommandArgs.PreUnmount) == 0 { + return false, nil + } + + if l.TargetType == "none" { + return false, nil + } + + if _, err := l.Mount(ctx, l.TempDir, false); err != nil { + return false, fmt.Errorf("could not mount temp dir '%s' for pre unmount: %w", l.TempDir, err) + } + // Build the commands from the args provided + if l.CommandArgs.Vars == nil { + l.CommandArgs.Vars = make(map[string]string) + } + l.CommandArgs.Vars["$MOUNT_PATH"] = filepath.Clean(l.TempDir) + + for _, rawCommand := range l.CommandArgs.PreUnmount { + formattedCommand := l.parseArgs(rawCommand) + l.Log.Info("PreUnmount", "command", formattedCommand) + + if _, err := command.Run(formattedCommand, l.Log); err != nil { + if _, unmountErr := l.Unmount(ctx, l.TempDir); unmountErr != nil { + return false, fmt.Errorf("could not unmount after pre unmount command failed: %s: %w", formattedCommand, unmountErr) + } + return false, fmt.Errorf("could not run pre unmount command: %s: %w", formattedCommand, err) + } + } + + if _, err := l.Unmount(ctx, l.TempDir); err != nil { + return false, fmt.Errorf("could not unmount after pre unmount '%s': %w", l.TempDir, err) + } + + return true, nil } diff --git a/pkg/filesystem/mock.go b/pkg/filesystem/mock.go index ed10a88f..6ec1df71 100644 --- a/pkg/filesystem/mock.go +++ b/pkg/filesystem/mock.go @@ -1,5 +1,5 @@ /* - * Copyright 2023 Hewlett Packard Enterprise Development LP + * Copyright 2023-2024 Hewlett Packard Enterprise Development LP * Other additional copyright holders may be indicated within. * * The entirety of this work is licensed under the Apache License, @@ -37,7 +37,7 @@ type MockFileSystem struct { var _ FileSystem = &MockFileSystem{} func (m *MockFileSystem) Create(ctx context.Context, complete bool) (bool, error) { - if complete == true { + if complete { return false, nil } @@ -52,7 +52,7 @@ func (m *MockFileSystem) Destroy(ctx context.Context) (bool, error) { } func (m *MockFileSystem) Activate(ctx context.Context, complete bool) (bool, error) { - if complete == true { + if complete { return false, nil } @@ -67,7 +67,7 @@ func (m *MockFileSystem) Deactivate(ctx context.Context) (bool, error) { } func (m *MockFileSystem) Mount(ctx context.Context, path string, complete bool) (bool, error) { - if complete == true { + if complete { return false, nil } @@ -82,7 +82,7 @@ func (m *MockFileSystem) Unmount(ctx context.Context, path string) (bool, error) } func (m *MockFileSystem) PostActivate(ctx context.Context, complete bool) (bool, error) { - if complete == true { + if complete { return false, nil } @@ -96,3 +96,19 @@ func (m *MockFileSystem) PreDeactivate(ctx context.Context) (bool, error) { return true, nil } + +func (m *MockFileSystem) PostMount(ctx context.Context, complete bool) (bool, error) { + if complete { + return false, nil + } + + m.Log.Info("Ran PostMount") + + return true, nil +} + +func (m *MockFileSystem) PreUnmount(ctx context.Context) (bool, error) { + m.Log.Info("Ran PreUnmount") + + return true, nil +} diff --git a/pkg/filesystem/simple.go b/pkg/filesystem/simple.go index 1133daa4..2e98de28 100644 --- a/pkg/filesystem/simple.go +++ b/pkg/filesystem/simple.go @@ -1,5 +1,5 @@ /* - * Copyright 2023 Hewlett Packard Enterprise Development LP + * Copyright 2023-2024 Hewlett Packard Enterprise Development LP * Other additional copyright holders may be indicated within. * * The entirety of this work is licensed under the Apache License, @@ -34,10 +34,10 @@ import ( ) type SimpleFileSystemCommandArgs struct { - Mkfs string - Mount string - PostActivate []string - PreDeactivate []string + Mkfs string + Mount string + PostMount []string + PreUnmount []string Vars map[string]string } @@ -198,8 +198,8 @@ func (f *SimpleFileSystem) Unmount(ctx context.Context, path string) (bool, erro return false, nil } -func (f *SimpleFileSystem) PostActivate(ctx context.Context, complete bool) (bool, error) { - if len(f.CommandArgs.PostActivate) == 0 { +func (f *SimpleFileSystem) PostMount(ctx context.Context, complete bool) (bool, error) { + if len(f.CommandArgs.PostMount) == 0 { return false, nil } @@ -212,7 +212,7 @@ func (f *SimpleFileSystem) PostActivate(ctx context.Context, complete bool) (boo } if _, err := f.Mount(ctx, f.TempDir, false); err != nil { - return false, fmt.Errorf("could not mount temp dir '%s': %w", f.TempDir, err) + return false, fmt.Errorf("could not mount temp dir '%s' for post mount: %w", f.TempDir, err) } // Build the commands from the args provided @@ -221,9 +221,9 @@ func (f *SimpleFileSystem) PostActivate(ctx context.Context, complete bool) (boo } f.CommandArgs.Vars["$MOUNT_PATH"] = f.TempDir - for _, rawCommand := range f.CommandArgs.PostActivate { + for _, rawCommand := range f.CommandArgs.PostMount { formattedCommand := f.parseArgs(rawCommand) - f.Log.Info("PostActivate", "command", formattedCommand) + f.Log.Info("PostMount", "command", formattedCommand) if _, err := command.Run(formattedCommand, f.Log); err != nil { if _, unmountErr := f.Unmount(ctx, f.TempDir); unmountErr != nil { @@ -237,11 +237,11 @@ func (f *SimpleFileSystem) PostActivate(ctx context.Context, complete bool) (boo return false, fmt.Errorf("could not unmount after post activate '%s': %w", f.TempDir, err) } - return false, nil + return true, nil } -func (f *SimpleFileSystem) PreDeactivate(ctx context.Context) (bool, error) { - if len(f.CommandArgs.PreDeactivate) == 0 { +func (f *SimpleFileSystem) PreUnmount(ctx context.Context) (bool, error) { + if len(f.CommandArgs.PreUnmount) == 0 { return false, nil } @@ -250,7 +250,7 @@ func (f *SimpleFileSystem) PreDeactivate(ctx context.Context) (bool, error) { } if _, err := f.Mount(ctx, f.TempDir, false); err != nil { - return false, fmt.Errorf("could not mount temp dir '%s': %w", f.TempDir, err) + return false, fmt.Errorf("could not mount temp dir '%s' for pre unmount: %w", f.TempDir, err) } // Build the commands from the args provided @@ -259,21 +259,31 @@ func (f *SimpleFileSystem) PreDeactivate(ctx context.Context) (bool, error) { } f.CommandArgs.Vars["$MOUNT_PATH"] = f.TempDir - for _, rawCommand := range f.CommandArgs.PreDeactivate { + for _, rawCommand := range f.CommandArgs.PreUnmount { formattedCommand := f.parseArgs(rawCommand) - f.Log.Info("PreDeactivate", "command", formattedCommand) + f.Log.Info("PreUnmount", "command", formattedCommand) if _, err := command.Run(formattedCommand, f.Log); err != nil { if _, unmountErr := f.Unmount(ctx, f.TempDir); unmountErr != nil { - return false, fmt.Errorf("could not unmount after pre-deactivate command failed: %s: %w", formattedCommand, unmountErr) + return false, fmt.Errorf("could not unmount after pre-unmount command failed: %s: %w", formattedCommand, unmountErr) } - return false, fmt.Errorf("could not run pre-deactivate command: %s: %w", formattedCommand, err) + return false, fmt.Errorf("could not run pre-unmount command: %s: %w", formattedCommand, err) } } if _, err := f.Unmount(ctx, f.TempDir); err != nil { - return false, fmt.Errorf("could not unmount after pre-deactivate '%s': %w", f.TempDir, err) + return false, fmt.Errorf("could not unmount after pre-unmount'%s': %w", f.TempDir, err) } + return true, nil +} + +// PostActivate is not supported for simple filesystems +func (f *SimpleFileSystem) PostActivate(ctx context.Context, complete bool) (bool, error) { + return false, nil +} + +// PreDeactivate is not supported for simple filesystems +func (f *SimpleFileSystem) PreDeactivate(ctx context.Context) (bool, error) { return false, nil }