|
| 1 | +// Copyright 2020-2025 Politecnico di Torino |
| 2 | +// |
| 3 | +// Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | +// you may not use this file except in compliance with the License. |
| 5 | +// You may obtain a copy of the License at |
| 6 | +// |
| 7 | +// http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | +// |
| 9 | +// Unless required by applicable law or agreed to in writing, software |
| 10 | +// distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | +// See the License for the specific language governing permissions and |
| 13 | +// limitations under the License. |
| 14 | + |
| 15 | +package v1alpha2 |
| 16 | + |
| 17 | +import ( |
| 18 | + "k8s.io/apimachinery/pkg/api/resource" |
| 19 | + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" |
| 20 | +) |
| 21 | + |
| 22 | +// EDIT THIS FILE! THIS IS SCAFFOLDING FOR YOU TO OWN! |
| 23 | +// NOTE: json tags are required. Any new fields you add must have json tags for the fields to be serialized. |
| 24 | + |
| 25 | +// +kubebuilder:validation:Enum="";"Pending";"Provisioning";"Ready";"Deleting";"ResourceQuotaExceeded";"Error" |
| 26 | + |
| 27 | +// SharedVolumePhase is an enumeration of the different phases associated with a SharedVolume. |
| 28 | +type SharedVolumePhase string |
| 29 | + |
| 30 | +const ( |
| 31 | + // SharedVolumePhaseUnset -> the shared volume phase is unknown. |
| 32 | + SharedVolumePhaseUnset SharedVolumePhase = "" |
| 33 | + // SharedVolumePhasePending -> the shared volume is pending. |
| 34 | + SharedVolumePhasePending SharedVolumePhase = "Pending" |
| 35 | + // SharedVolumePhaseProvisioning -> the shared volume's PVC is under provisioning. |
| 36 | + SharedVolumePhaseProvisioning SharedVolumePhase = "Provisioning" |
| 37 | + // SharedVolumePhaseReady -> the shared volume is bound and ready to be accessed. |
| 38 | + SharedVolumePhaseReady SharedVolumePhase = "Ready" |
| 39 | + // SharedVolumePhaseDeleting -> the shared volume is checking if it's mounted on any template before going through deletion. |
| 40 | + SharedVolumePhaseDeleting SharedVolumePhase = "Deleting" |
| 41 | + // SharedVolumePhaseResourceQuotaExceeded -> the shared volume could not be created because the resource quota is exceeded. |
| 42 | + SharedVolumePhaseResourceQuotaExceeded SharedVolumePhase = "ResourceQuotaExceeded" |
| 43 | + // SharedVolumePhaseError -> the shared volume had an error during reconcile. |
| 44 | + SharedVolumePhaseError SharedVolumePhase = "Error" |
| 45 | +) |
| 46 | + |
| 47 | +// SharedVolumeSpec is the specification of the desired state of the Shared Volume. |
| 48 | +type SharedVolumeSpec struct { |
| 49 | + // The human-readable name of the Shared Volume. |
| 50 | + PrettyName string `json:"prettyName"` |
| 51 | + |
| 52 | + // The size of the volume. |
| 53 | + Size resource.Quantity `json:"size"` |
| 54 | +} |
| 55 | + |
| 56 | +// SharedVolumeStatus reflects the most recently observed status of the Shared Volume. |
| 57 | +type SharedVolumeStatus struct { |
| 58 | + // The NFS server address. |
| 59 | + ServerAddress string `json:"serverAddress,omitempty"` |
| 60 | + |
| 61 | + // The NFS path. |
| 62 | + ExportPath string `json:"exportPath,omitempty"` |
| 63 | + |
| 64 | + // The current phase of the lifecycle of the Shared Volume. |
| 65 | + Phase SharedVolumePhase `json:"phase,omitempty"` |
| 66 | +} |
| 67 | + |
| 68 | +// +kubebuilder:object:root=true |
| 69 | +// +kubebuilder:subresource:status |
| 70 | +// +kubebuilder:resource:shortName="shvol" |
| 71 | +// +kubebuilder:storageversion |
| 72 | +// +kubebuilder:printcolumn:name="Pretty Name",type=string,JSONPath=`.spec.prettyName` |
| 73 | +// +kubebuilder:printcolumn:name="Size",type=string,JSONPath=`.spec.size` |
| 74 | +// +kubebuilder:printcolumn:name="Phase",type=string,JSONPath=`.status.phase` |
| 75 | +// +kubebuilder:printcolumn:name="Age",type=date,JSONPath=`.metadata.creationTimestamp` |
| 76 | + |
| 77 | +// SharedVolume describes a shared volume between tenants in CrownLabs. |
| 78 | +type SharedVolume struct { |
| 79 | + metav1.TypeMeta `json:",inline"` |
| 80 | + metav1.ObjectMeta `json:"metadata,omitempty"` |
| 81 | + |
| 82 | + Spec SharedVolumeSpec `json:"spec,omitempty"` |
| 83 | + Status SharedVolumeStatus `json:"status,omitempty"` |
| 84 | +} |
| 85 | + |
| 86 | +// +kubebuilder:object:root=true |
| 87 | + |
| 88 | +// SharedVolumeList contains a list of SharedVolume objects. |
| 89 | +type SharedVolumeList struct { |
| 90 | + metav1.TypeMeta `json:",inline"` |
| 91 | + metav1.ListMeta `json:"metadata,omitempty"` |
| 92 | + |
| 93 | + Items []SharedVolume `json:"items"` |
| 94 | +} |
| 95 | + |
| 96 | +func init() { |
| 97 | + SchemeBuilder.Register(&SharedVolume{}, &SharedVolumeList{}) |
| 98 | +} |
0 commit comments