|
| 1 | +/* |
| 2 | +Copyright 2026 Flant JSC |
| 3 | +
|
| 4 | +Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | +you may not use this file except in compliance with the License. |
| 6 | +You may obtain a copy of the License at |
| 7 | +
|
| 8 | + http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | +
|
| 10 | +Unless required by applicable law or agreed to in writing, software |
| 11 | +distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | +See the License for the specific language governing permissions and |
| 14 | +limitations under the License. |
| 15 | +*/ |
| 16 | + |
| 17 | +package v1alpha1 |
| 18 | + |
| 19 | +import ( |
| 20 | + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" |
| 21 | +) |
| 22 | + |
| 23 | +// ReplicatedVolumeOperation represents an operation to update volume configuration |
| 24 | +// or resolve eligible nodes conflicts for a ReplicatedVolume. |
| 25 | +// |
| 26 | +// +kubebuilder:object:generate=true |
| 27 | +// +kubebuilder:object:root=true |
| 28 | +// +kubebuilder:subresource:status |
| 29 | +// +kubebuilder:resource:scope=Cluster,shortName=rvo |
| 30 | +// +kubebuilder:metadata:labels=module=sds-replicated-volume |
| 31 | +// +kubebuilder:printcolumn:name="Volume",type=string,JSONPath=".spec.replicatedVolumeName" |
| 32 | +// +kubebuilder:printcolumn:name="Type",type=string,JSONPath=".spec.type" |
| 33 | +// +kubebuilder:printcolumn:name="Completed",type=string,JSONPath=".status.conditions[?(@.type=='Completed')].status" |
| 34 | +// +kubebuilder:printcolumn:name="Age",type=date,JSONPath=".metadata.creationTimestamp" |
| 35 | +type ReplicatedVolumeOperation struct { |
| 36 | + metav1.TypeMeta `json:",inline"` |
| 37 | + metav1.ObjectMeta `json:"metadata"` |
| 38 | + |
| 39 | + Spec ReplicatedVolumeOperationSpec `json:"spec"` |
| 40 | + // +patchStrategy=merge |
| 41 | + Status ReplicatedVolumeOperationStatus `json:"status,omitempty" patchStrategy:"merge"` |
| 42 | +} |
| 43 | + |
| 44 | +// +kubebuilder:object:generate=true |
| 45 | +// +kubebuilder:object:root=true |
| 46 | +// +kubebuilder:resource:scope=Cluster |
| 47 | +type ReplicatedVolumeOperationList struct { |
| 48 | + metav1.TypeMeta `json:",inline"` |
| 49 | + metav1.ListMeta `json:"metadata"` |
| 50 | + Items []ReplicatedVolumeOperation `json:"items"` |
| 51 | +} |
| 52 | + |
| 53 | +// GetStatusConditions is an adapter method to satisfy objutilv1.StatusConditionObject. |
| 54 | +// It returns the root object's `.status.conditions`. |
| 55 | +func (o *ReplicatedVolumeOperation) GetStatusConditions() []metav1.Condition { |
| 56 | + return o.Status.Conditions |
| 57 | +} |
| 58 | + |
| 59 | +// SetStatusConditions is an adapter method to satisfy objutilv1.StatusConditionObject. |
| 60 | +// It sets the root object's `.status.conditions`. |
| 61 | +func (o *ReplicatedVolumeOperation) SetStatusConditions(conditions []metav1.Condition) { |
| 62 | + o.Status.Conditions = conditions |
| 63 | +} |
| 64 | + |
| 65 | +// ReplicatedVolumeOperationSpec defines the desired state of a ReplicatedVolumeOperation. |
| 66 | +// All fields are immutable after creation. |
| 67 | +// |
| 68 | +// +kubebuilder:validation:XValidation:rule="self == oldSelf",message="spec is immutable" |
| 69 | +// +kubebuilder:object:generate=true |
| 70 | +type ReplicatedVolumeOperationSpec struct { |
| 71 | + // ReplicatedVolumeName is the name of the ReplicatedVolume this operation targets. |
| 72 | + // +kubebuilder:validation:Required |
| 73 | + // +kubebuilder:validation:MinLength=1 |
| 74 | + // +kubebuilder:validation:MaxLength=120 |
| 75 | + ReplicatedVolumeName string `json:"replicatedVolumeName"` |
| 76 | + |
| 77 | + // Type specifies the operation type. |
| 78 | + // +kubebuilder:validation:Required |
| 79 | + // +kubebuilder:validation:Enum=UpdateConfiguration;ResolveEligibleNodesConflict |
| 80 | + Type ReplicatedVolumeOperationType `json:"type"` |
| 81 | + |
| 82 | + // ResolveEligibleNodesConflict indicates whether this operation should also resolve |
| 83 | + // eligible nodes conflicts when updating configuration. Only meaningful when Type is |
| 84 | + // UpdateConfiguration. Determined by EligibleNodesConflictResolutionStrategy. |
| 85 | + // +kubebuilder:default=false |
| 86 | + // +optional |
| 87 | + ResolveEligibleNodesConflict bool `json:"resolveEligibleNodesConflict,omitempty"` |
| 88 | +} |
| 89 | + |
| 90 | +// ReplicatedVolumeOperationType enumerates possible operation types. |
| 91 | +type ReplicatedVolumeOperationType string |
| 92 | + |
| 93 | +const ( |
| 94 | + // ReplicatedVolumeOperationTypeUpdateConfiguration updates the volume configuration |
| 95 | + // to match the current storage class configuration. |
| 96 | + ReplicatedVolumeOperationTypeUpdateConfiguration ReplicatedVolumeOperationType = "UpdateConfiguration" |
| 97 | + // ReplicatedVolumeOperationTypeResolveEligibleNodesConflict moves replicas |
| 98 | + // from non-eligible nodes to eligible nodes. |
| 99 | + ReplicatedVolumeOperationTypeResolveEligibleNodesConflict ReplicatedVolumeOperationType = "ResolveEligibleNodesConflict" |
| 100 | +) |
| 101 | + |
| 102 | +func (t ReplicatedVolumeOperationType) String() string { return string(t) } |
| 103 | + |
| 104 | +// Short name suffixes for operation resource naming. |
| 105 | +// Format: <rv-name>-<suffix>-<cursor> |
| 106 | +const ( |
| 107 | + // ReplicatedVolumeOperationNameSuffixUpdateConfig is the short suffix for UpdateConfiguration operations. |
| 108 | + ReplicatedVolumeOperationNameSuffixUpdateConfig = "updateConfig" |
| 109 | + // ReplicatedVolumeOperationNameSuffixResolveNodes is the short suffix for ResolveEligibleNodesConflict operations. |
| 110 | + ReplicatedVolumeOperationNameSuffixResolveNodes = "resolveNodes" |
| 111 | +) |
| 112 | + |
| 113 | +// NameSuffix returns the short suffix for generating operation resource names. |
| 114 | +func (t ReplicatedVolumeOperationType) NameSuffix() string { |
| 115 | + switch t { |
| 116 | + case ReplicatedVolumeOperationTypeUpdateConfiguration: |
| 117 | + return ReplicatedVolumeOperationNameSuffixUpdateConfig |
| 118 | + case ReplicatedVolumeOperationTypeResolveEligibleNodesConflict: |
| 119 | + return ReplicatedVolumeOperationNameSuffixResolveNodes |
| 120 | + default: |
| 121 | + return string(t) |
| 122 | + } |
| 123 | +} |
| 124 | + |
| 125 | +// ReplicatedVolumeOperationStatus represents the current state of a ReplicatedVolumeOperation. |
| 126 | +// +kubebuilder:object:generate=true |
| 127 | +type ReplicatedVolumeOperationStatus struct { |
| 128 | + // +patchMergeKey=type |
| 129 | + // +patchStrategy=merge |
| 130 | + // +listType=map |
| 131 | + // +listMapKey=type |
| 132 | + // +optional |
| 133 | + Conditions []metav1.Condition `json:"conditions,omitempty" patchStrategy:"merge" patchMergeKey:"type" protobuf:"bytes,1,rep,name=conditions"` |
| 134 | +} |
0 commit comments