Skip to content

Commit

Permalink
persistent state
Browse files Browse the repository at this point in the history
Signed-off-by: Matt Richerson <[email protected]>
  • Loading branch information
matthew-richerson committed Nov 7, 2024
1 parent 5c36198 commit 254c6a7
Show file tree
Hide file tree
Showing 6 changed files with 107 additions and 38 deletions.
33 changes: 30 additions & 3 deletions api/v1alpha1/conversion.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
}
Expand Down Expand Up @@ -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)
}
16 changes: 6 additions & 10 deletions api/v1alpha1/zz_generated.conversion.go

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

31 changes: 30 additions & 1 deletion api/v1alpha2/conversion.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -169,12 +170,20 @@ 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 {
if restored.Status.Error != nil {
dst.Spec.State = restored.Spec.State
dst.Status.State = restored.Status.State
dst.Status.Ready = restored.Status.Ready
}
}

return nil
}
Expand All @@ -187,6 +196,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)
}
Expand Down Expand Up @@ -399,3 +424,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)
}
40 changes: 28 additions & 12 deletions api/v1alpha2/zz_generated.conversion.go

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

13 changes: 6 additions & 7 deletions api/v1alpha3/persistentstorageinstance_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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"`
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 254c6a7

Please sign in to comment.