|
| 1 | +/* |
| 2 | +Copyright 2025 The Kubernetes Authors. |
| 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 | +// DiskMode describes the desired mode to use when attaching the volume. |
| 24 | +type DiskMode string |
| 25 | + |
| 26 | +const ( |
| 27 | + // By setting DiskMode to IndependentPersistent, a virtual machine's disk is not captured in snapshots and |
| 28 | + // changes are permanently written to the disk, regardless of snapshot operations. |
| 29 | + IndependentPersistent DiskMode = "IndependentPersistent" |
| 30 | + // Changes are immediately and permanently written to the virtual disk. |
| 31 | + Persistent DiskMode = "Persistent" |
| 32 | +) |
| 33 | + |
| 34 | +// The sharing mode of the virtual disk. |
| 35 | +type SharingMode string |
| 36 | + |
| 37 | +const ( |
| 38 | + // The virtual disk is shared between multiple virtual machines. |
| 39 | + SharingMultiWriter SharingMode = "sharingMultiWriter" |
| 40 | + // The virtual disk is not shared. |
| 41 | + SharingNone SharingMode = "sharingNone" |
| 42 | +) |
| 43 | + |
| 44 | +// CnsNodeVmBatchAttachmentSpec defines the desired state of CnsNodeVmBatchAttachment |
| 45 | +// +k8s:openapi-gen=true |
| 46 | +type CnsNodeVmBatchAttachmentSpec struct { |
| 47 | + // NodeUUID indicates the UUID of the node where the volume needs to be attached to. |
| 48 | + // Here NodeUUID is the instance UUID of the node. |
| 49 | + NodeUUID string `json:"nodeuuid"` |
| 50 | + |
| 51 | + // +listType=map |
| 52 | + // +listMapKey=name |
| 53 | + // VolumeSpec reflects the desired state for each volume. |
| 54 | + Volumes []VolumeSpec `json:"volumes"` |
| 55 | +} |
| 56 | + |
| 57 | +type VolumeSpec struct { |
| 58 | + // Name of the volume as given by the user. |
| 59 | + Name string `json:"name"` |
| 60 | + // PersistentVolumeClaim contains details about the volume's desired state. |
| 61 | + PersistentVolumeClaim PersistentVolumeClaimSpec `json:"persistentVolumeClaim"` |
| 62 | +} |
| 63 | + |
| 64 | +type PersistentVolumeClaimSpec struct { |
| 65 | + // ClaimName is the PVC name. |
| 66 | + ClaimName string `json:"claimName"` |
| 67 | + // DiskMode is the desired mode to use when attaching the volume |
| 68 | + DiskMode DiskMode `json:"diskMode,omitempty"` |
| 69 | + // SharingMode indicates the shraring mode if the virtual disk while attaching. |
| 70 | + SharingMode SharingMode `json:"sharingMode,omitempty"` |
| 71 | + // ControllerKey is the object key for the controller object for this device. |
| 72 | + ControllerKey string `json:"controllerKey,omitempty"` |
| 73 | + // UnitNumber of this device on its controller. |
| 74 | + UnitNumber string `json:"unitNumber,omitempty"` |
| 75 | +} |
| 76 | + |
| 77 | +// CnsNodeVmBatchAttachmentStatus defines the observed state of CnsNodeVmBatchAttachment |
| 78 | +// +k8s:openapi-gen=true |
| 79 | +type CnsNodeVmBatchAttachmentStatus struct { |
| 80 | + // Error is the overall error status for the instance. |
| 81 | + Error string `json:"error,omitempty"` |
| 82 | + // +listType=map |
| 83 | + // +listMapKey=name |
| 84 | + // VolumeStatus reflects the status for each volume. |
| 85 | + VolumeStatus []VolumeStatus `json:"volumes,omitempty"` |
| 86 | +} |
| 87 | + |
| 88 | +type VolumeStatus struct { |
| 89 | + // Name of the volume as given by the user. |
| 90 | + Name string `json:"name"` |
| 91 | + // PersistentVolumeClaim contains details about the volume's current state. |
| 92 | + PersistentVolumeClaim PersistentVolumeClaimStatus `json:"persistentVolumeClaim"` |
| 93 | +} |
| 94 | + |
| 95 | +type PersistentVolumeClaimStatus struct { |
| 96 | + // ClaimName is the PVC name. |
| 97 | + ClaimName string `json:"claimName"` |
| 98 | + // If volume is not attached, Attached will be set to false. |
| 99 | + // If volume is attached, Attached will be set to true. |
| 100 | + // If volume is detached successfully, its entry will be removed from VolumeStatus. |
| 101 | + Attached bool `json:"attached"` |
| 102 | + // Error indicates the error which may have occurred during attach/detach. |
| 103 | + Error string `json:"error,omitempty"` |
| 104 | + // CnsVolumeID is the volume ID for the PVC. |
| 105 | + CnsVolumeID string `json:"cnsVolumeId,omitempty"` |
| 106 | + // Diskuuid is the ID obtained when volume is attached to a VM. |
| 107 | + Diskuuid string `json:"diskuuid,omitempty"` |
| 108 | +} |
| 109 | + |
| 110 | +// +genclient |
| 111 | +// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object |
| 112 | + |
| 113 | +// +k8s:openapi-gen=true |
| 114 | +// +kubebuilder:subresource:status |
| 115 | + |
| 116 | +// CnsNodeVmBatchAttachment is the Schema for the cnsnodevmbatchattachments API |
| 117 | +type CnsNodeVmBatchAttachment struct { |
| 118 | + metav1.TypeMeta `json:",inline"` |
| 119 | + metav1.ObjectMeta `json:"metadata,omitempty"` |
| 120 | + |
| 121 | + Spec CnsNodeVmBatchAttachmentSpec `json:"spec,omitempty"` |
| 122 | + Status CnsNodeVmBatchAttachmentStatus `json:"status,omitempty"` |
| 123 | +} |
| 124 | + |
| 125 | +// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object |
| 126 | + |
| 127 | +// CnsNodeVmBatchAttachmentList contains a list of CnsNodeVmBatchAttachment |
| 128 | +type CnsNodeVmBatchAttachmentList struct { |
| 129 | + metav1.TypeMeta `json:",inline"` |
| 130 | + metav1.ListMeta `json:"metadata,omitempty"` |
| 131 | + Items []CnsNodeVmBatchAttachment `json:"items"` |
| 132 | +} |
0 commit comments