diff --git a/api/v1alpha1/conversion.go b/api/v1alpha1/conversion.go index 9befe1da..42df85de 100644 --- a/api/v1alpha1/conversion.go +++ b/api/v1alpha1/conversion.go @@ -235,14 +235,21 @@ func (src *PersistentStorageInstance) ConvertTo(dstRaw conversion.Hub) error { 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. // v1alpha2 removed Error.Recoverable and uses Error.Severity and Error.Type, instead. - if hasAnno && restored.Status.Error != nil { - dst.Status.Error.Type = restored.Status.Error.Type - dst.Status.Error.Severity = restored.Status.Error.Severity + if hasAnno { + if restored.Status.Error != nil { + dst.Status.Error.Type = restored.Status.Error.Type + dst.Status.Error.Severity = restored.Status.Error.Severity + } + + dst.Spec.State = restored.Spec.State + dst.Status.State = restored.Status.State + dst.Status.Ready = restored.Status.Ready } if src.Status.Error != nil && !src.Status.Error.Recoverable { dst.Status.Error.Severity = dwsv1alpha3.SeverityFatal @@ -269,6 +276,22 @@ func (dst *PersistentStorageInstance) ConvertFrom(srcRaw conversion.Hub) error { } } + if src.Spec.State == dwsv1alpha3.PSIStateEnabled { + dst.Spec.State = PSIStateActive + if src.Status.State == dwsv1alpha3.PSIStateEnabled && src.Status.Ready == true { + dst.Status.State = PSIStateActive + } else { + dst.Status.State = PSIStateCreating + } + } else if src.Spec.State == dwsv1alpha3.PSIStateDisabled { + dst.Spec.State = PSIStateDestroying + if src.Status.State == dwsv1alpha3.PSIStateDisabled && src.Status.Ready == true { + dst.Status.State = PSIStateDestroying + } else { + dst.Status.State = PSIStateActive + } + } + // Preserve Hub data on down-conversion except for metadata. return utilconversion.MarshalData(src, dst) } @@ -597,3 +620,7 @@ func Convert_v1alpha3_StorageSpec_To_v1alpha1_StorageSpec(in *dwsv1alpha3.Storag func Convert_v1alpha3_SystemConfigurationStatus_To_v1alpha1_SystemConfigurationStatus(in *dwsv1alpha3.SystemConfigurationStatus, out *SystemConfigurationStatus, s apiconversion.Scope) error { return autoConvert_v1alpha3_SystemConfigurationStatus_To_v1alpha1_SystemConfigurationStatus(in, out, s) } + +func Convert_v1alpha3_PersistentStorageInstanceStatus_To_v1alpha1_PersistentStorageInstanceStatus(in *dwsv1alpha3.PersistentStorageInstanceStatus, out *PersistentStorageInstanceStatus, s apiconversion.Scope) error { + return autoConvert_v1alpha3_PersistentStorageInstanceStatus_To_v1alpha1_PersistentStorageInstanceStatus(in, out, s) +} diff --git a/api/v1alpha1/zz_generated.conversion.go b/api/v1alpha1/zz_generated.conversion.go index 68da739c..775b05dc 100644 --- a/api/v1alpha1/zz_generated.conversion.go +++ b/api/v1alpha1/zz_generated.conversion.go @@ -338,11 +338,6 @@ func RegisterConversions(s *runtime.Scheme) error { }); err != nil { return err } - if err := s.AddGeneratedConversionFunc((*v1alpha3.PersistentStorageInstanceStatus)(nil), (*PersistentStorageInstanceStatus)(nil), func(a, b interface{}, scope conversion.Scope) error { - return Convert_v1alpha3_PersistentStorageInstanceStatus_To_v1alpha1_PersistentStorageInstanceStatus(a.(*v1alpha3.PersistentStorageInstanceStatus), b.(*PersistentStorageInstanceStatus), scope) - }); err != nil { - return err - } if err := s.AddGeneratedConversionFunc((*ResourceError)(nil), (*v1alpha3.ResourceError)(nil), func(a, b interface{}, scope conversion.Scope) error { return Convert_v1alpha1_ResourceError_To_v1alpha3_ResourceError(a.(*ResourceError), b.(*v1alpha3.ResourceError), scope) }); err != nil { @@ -613,6 +608,11 @@ func RegisterConversions(s *runtime.Scheme) error { }); err != nil { return err } + if err := s.AddConversionFunc((*v1alpha3.PersistentStorageInstanceStatus)(nil), (*PersistentStorageInstanceStatus)(nil), func(a, b interface{}, scope conversion.Scope) error { + return Convert_v1alpha3_PersistentStorageInstanceStatus_To_v1alpha1_PersistentStorageInstanceStatus(a.(*v1alpha3.PersistentStorageInstanceStatus), b.(*PersistentStorageInstanceStatus), scope) + }); err != nil { + return err + } if err := s.AddConversionFunc((*v1alpha3.ResourceErrorInfo)(nil), (*ResourceErrorInfo)(nil), func(a, b interface{}, scope conversion.Scope) error { return Convert_v1alpha3_ResourceErrorInfo_To_v1alpha1_ResourceErrorInfo(a.(*v1alpha3.ResourceErrorInfo), b.(*ResourceErrorInfo), scope) }); err != nil { @@ -1457,17 +1457,13 @@ func Convert_v1alpha1_PersistentStorageInstanceStatus_To_v1alpha3_PersistentStor func autoConvert_v1alpha3_PersistentStorageInstanceStatus_To_v1alpha1_PersistentStorageInstanceStatus(in *v1alpha3.PersistentStorageInstanceStatus, out *PersistentStorageInstanceStatus, s conversion.Scope) error { out.Servers = in.Servers out.State = PersistentStorageInstanceState(in.State) + // WARNING: in.Ready requires manual conversion: does not exist in peer-type if err := Convert_v1alpha3_ResourceError_To_v1alpha1_ResourceError(&in.ResourceError, &out.ResourceError, s); err != nil { return err } return nil } -// Convert_v1alpha3_PersistentStorageInstanceStatus_To_v1alpha1_PersistentStorageInstanceStatus is an autogenerated conversion function. -func Convert_v1alpha3_PersistentStorageInstanceStatus_To_v1alpha1_PersistentStorageInstanceStatus(in *v1alpha3.PersistentStorageInstanceStatus, out *PersistentStorageInstanceStatus, s conversion.Scope) error { - return autoConvert_v1alpha3_PersistentStorageInstanceStatus_To_v1alpha1_PersistentStorageInstanceStatus(in, out, s) -} - func autoConvert_v1alpha1_ResourceError_To_v1alpha3_ResourceError(in *ResourceError, out *v1alpha3.ResourceError, s conversion.Scope) error { if in.Error != nil { in, out := &in.Error, &out.Error diff --git a/api/v1alpha2/conversion.go b/api/v1alpha2/conversion.go index 49bdd5dd..74eb9f4f 100644 --- a/api/v1alpha2/conversion.go +++ b/api/v1alpha2/conversion.go @@ -21,6 +21,7 @@ package v1alpha2 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" @@ -169,12 +170,18 @@ func (src *PersistentStorageInstance) ConvertTo(dstRaw conversion.Hub) error { // Manually restore data. restored := &dwsv1alpha3.PersistentStorageInstance{} - 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.State = restored.Spec.State + dst.Status.State = restored.Status.State + dst.Status.Ready = restored.Status.Ready + } return nil } @@ -187,6 +194,22 @@ func (dst *PersistentStorageInstance) ConvertFrom(srcRaw conversion.Hub) error { return err } + if src.Spec.State == dwsv1alpha3.PSIStateEnabled { + dst.Spec.State = PSIStateActive + if src.Status.State == dwsv1alpha3.PSIStateEnabled && src.Status.Ready == true { + dst.Status.State = PSIStateActive + } else { + dst.Status.State = PSIStateCreating + } + } else if src.Spec.State == dwsv1alpha3.PSIStateDisabled { + dst.Spec.State = PSIStateDestroying + if src.Status.State == dwsv1alpha3.PSIStateDisabled && src.Status.Ready == true { + dst.Status.State = PSIStateDestroying + } else { + dst.Status.State = PSIStateActive + } + } + // Preserve Hub data on down-conversion except for metadata. return utilconversion.MarshalData(src, dst) } @@ -399,3 +422,7 @@ func (src *WorkflowList) ConvertTo(dstRaw conversion.Hub) error { func (dst *WorkflowList) ConvertFrom(srcRaw conversion.Hub) error { return apierrors.NewMethodNotSupported(resource("WorkflowList"), "ConvertFrom") } + +func Convert_v1alpha3_PersistentStorageInstanceStatus_To_v1alpha2_PersistentStorageInstanceStatus(in *dwsv1alpha3.PersistentStorageInstanceStatus, out *PersistentStorageInstanceStatus, s apiconversion.Scope) error { + return autoConvert_v1alpha3_PersistentStorageInstanceStatus_To_v1alpha2_PersistentStorageInstanceStatus(in, out, s) +} diff --git a/api/v1alpha2/zz_generated.conversion.go b/api/v1alpha2/zz_generated.conversion.go index 9fe8520d..8701bed4 100644 --- a/api/v1alpha2/zz_generated.conversion.go +++ b/api/v1alpha2/zz_generated.conversion.go @@ -348,11 +348,6 @@ func RegisterConversions(s *runtime.Scheme) error { }); err != nil { return err } - if err := s.AddGeneratedConversionFunc((*v1alpha3.PersistentStorageInstanceStatus)(nil), (*PersistentStorageInstanceStatus)(nil), func(a, b interface{}, scope conversion.Scope) error { - return Convert_v1alpha3_PersistentStorageInstanceStatus_To_v1alpha2_PersistentStorageInstanceStatus(a.(*v1alpha3.PersistentStorageInstanceStatus), b.(*PersistentStorageInstanceStatus), scope) - }); err != nil { - return err - } if err := s.AddGeneratedConversionFunc((*ResourceError)(nil), (*v1alpha3.ResourceError)(nil), func(a, b interface{}, scope conversion.Scope) error { return Convert_v1alpha2_ResourceError_To_v1alpha3_ResourceError(a.(*ResourceError), b.(*v1alpha3.ResourceError), scope) }); err != nil { @@ -653,6 +648,11 @@ func RegisterConversions(s *runtime.Scheme) error { }); err != nil { return err } + if err := s.AddConversionFunc((*v1alpha3.PersistentStorageInstanceStatus)(nil), (*PersistentStorageInstanceStatus)(nil), func(a, b interface{}, scope conversion.Scope) error { + return Convert_v1alpha3_PersistentStorageInstanceStatus_To_v1alpha2_PersistentStorageInstanceStatus(a.(*v1alpha3.PersistentStorageInstanceStatus), b.(*PersistentStorageInstanceStatus), scope) + }); err != nil { + return err + } return nil } @@ -1352,7 +1352,17 @@ func Convert_v1alpha3_PersistentStorageInstance_To_v1alpha2_PersistentStorageIns func autoConvert_v1alpha2_PersistentStorageInstanceList_To_v1alpha3_PersistentStorageInstanceList(in *PersistentStorageInstanceList, out *v1alpha3.PersistentStorageInstanceList, s conversion.Scope) error { out.ListMeta = in.ListMeta - out.Items = *(*[]v1alpha3.PersistentStorageInstance)(unsafe.Pointer(&in.Items)) + if in.Items != nil { + in, out := &in.Items, &out.Items + *out = make([]v1alpha3.PersistentStorageInstance, len(*in)) + for i := range *in { + if err := Convert_v1alpha2_PersistentStorageInstance_To_v1alpha3_PersistentStorageInstance(&(*in)[i], &(*out)[i], s); err != nil { + return err + } + } + } else { + out.Items = nil + } return nil } @@ -1363,7 +1373,17 @@ func Convert_v1alpha2_PersistentStorageInstanceList_To_v1alpha3_PersistentStorag func autoConvert_v1alpha3_PersistentStorageInstanceList_To_v1alpha2_PersistentStorageInstanceList(in *v1alpha3.PersistentStorageInstanceList, out *PersistentStorageInstanceList, s conversion.Scope) error { out.ListMeta = in.ListMeta - out.Items = *(*[]PersistentStorageInstance)(unsafe.Pointer(&in.Items)) + if in.Items != nil { + in, out := &in.Items, &out.Items + *out = make([]PersistentStorageInstance, len(*in)) + for i := range *in { + if err := Convert_v1alpha3_PersistentStorageInstance_To_v1alpha2_PersistentStorageInstance(&(*in)[i], &(*out)[i], s); err != nil { + return err + } + } + } else { + out.Items = nil + } return nil } @@ -1419,17 +1439,13 @@ func Convert_v1alpha2_PersistentStorageInstanceStatus_To_v1alpha3_PersistentStor func autoConvert_v1alpha3_PersistentStorageInstanceStatus_To_v1alpha2_PersistentStorageInstanceStatus(in *v1alpha3.PersistentStorageInstanceStatus, out *PersistentStorageInstanceStatus, s conversion.Scope) error { out.Servers = in.Servers out.State = PersistentStorageInstanceState(in.State) + // WARNING: in.Ready requires manual conversion: does not exist in peer-type if err := Convert_v1alpha3_ResourceError_To_v1alpha2_ResourceError(&in.ResourceError, &out.ResourceError, s); err != nil { return err } return nil } -// Convert_v1alpha3_PersistentStorageInstanceStatus_To_v1alpha2_PersistentStorageInstanceStatus is an autogenerated conversion function. -func Convert_v1alpha3_PersistentStorageInstanceStatus_To_v1alpha2_PersistentStorageInstanceStatus(in *v1alpha3.PersistentStorageInstanceStatus, out *PersistentStorageInstanceStatus, s conversion.Scope) error { - return autoConvert_v1alpha3_PersistentStorageInstanceStatus_To_v1alpha2_PersistentStorageInstanceStatus(in, out, s) -} - func autoConvert_v1alpha2_ResourceError_To_v1alpha3_ResourceError(in *ResourceError, out *v1alpha3.ResourceError, s conversion.Scope) error { out.Error = (*v1alpha3.ResourceErrorInfo)(unsafe.Pointer(in.Error)) return nil diff --git a/api/v1alpha3/persistentstorageinstance_types.go b/api/v1alpha3/persistentstorageinstance_types.go index 3f16a524..d08fa250 100644 --- a/api/v1alpha3/persistentstorageinstance_types.go +++ b/api/v1alpha3/persistentstorageinstance_types.go @@ -40,16 +40,13 @@ type PersistentStorageInstanceState string // State enumerations const ( - // The PSI resource exists in k8s, but the storage and filesystem that it represents has not been created yet - PSIStateCreating PersistentStorageInstanceState = "Creating" - // The storage and filesystem represented by the PSI exists and is ready for use - PSIStateActive PersistentStorageInstanceState = "Active" + PSIStateEnabled PersistentStorageInstanceState = "Enabled" // A #DW destroy_persistent directive has been issued in a workflow. // Once all other workflows with persistent_dw reservations on the PSI complete, the PSI will be destroyed. // New #DW persistent_dw requests after the PSI enters the 'destroying' state will fail. - PSIStateDestroying PersistentStorageInstanceState = "Destroying" + PSIStateDisabled PersistentStorageInstanceState = "Disabled" ) // PersistentStorageInstanceSpec defines the desired state of PersistentStorageInstance @@ -68,7 +65,7 @@ type PersistentStorageInstanceSpec struct { UserID uint32 `json:"userID"` // Desired state of the PersistentStorageInstance - // +kubebuilder:validation:Enum:=Active;Destroying + // +kubebuilder:validation:Enum:=Enabled;Disabled State PersistentStorageInstanceState `json:"state"` // List of consumers using this persistent storage @@ -81,9 +78,11 @@ type PersistentStorageInstanceStatus struct { Servers corev1.ObjectReference `json:"servers,omitempty"` // Current state of the PersistentStorageInstance - // +kubebuilder:validation:Enum:=Creating;Active;Destroying + // +kubebuilder:validation:Enum:=Enabled;Disabled State PersistentStorageInstanceState `json:"state"` + Ready bool `json:"ready"` + // Error information ResourceError `json:",inline"` } diff --git a/config/crd/bases/dataworkflowservices.github.io_persistentstorageinstances.yaml b/config/crd/bases/dataworkflowservices.github.io_persistentstorageinstances.yaml index daf1be5e..a2f03cf2 100644 --- a/config/crd/bases/dataworkflowservices.github.io_persistentstorageinstances.yaml +++ b/config/crd/bases/dataworkflowservices.github.io_persistentstorageinstances.yaml @@ -560,8 +560,8 @@ spec: state: description: Desired state of the PersistentStorageInstance enum: - - Active - - Destroying + - Enabled + - Disabled type: string userID: description: User ID of the user that created the persistent storage @@ -609,6 +609,8 @@ spec: - severity - type type: object + ready: + type: boolean servers: description: Servers refers to the Servers resource that provides the backing storage for this storage instance @@ -657,11 +659,11 @@ spec: state: description: Current state of the PersistentStorageInstance enum: - - Creating - - Active - - Destroying + - Enabled + - Disabled type: string required: + - ready - state type: object type: object diff --git a/internal/controller/conversion_test.go b/internal/controller/conversion_test.go index 77177a4b..e5ca14ce 100644 --- a/internal/controller/conversion_test.go +++ b/internal/controller/conversion_test.go @@ -273,7 +273,7 @@ var _ = Describe("Conversion Webhook Test", func() { FsType: "raw", DWDirective: "", UserID: 0, - State: "Active", + State: "Enabled", }, }