github.com/openebs/node-disk-manager@v1.9.1-0.20230225014141-4531f06ffa1e/api/v1alpha1/blockdevice_types.go (about) 1 /* 2 Copyright 2021 The OpenEBS 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 v1 "k8s.io/api/core/v1" 21 metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" 22 ) 23 24 // DeviceSpec defines the properties and runtime status of a BlockDevice 25 type DeviceSpec struct { 26 27 // AggregateDevice was intended to store the hierarchical 28 // information in cases of LVM. However this is currently 29 // not implemented and may need to be re-looked into for 30 // better design. To be deprecated 31 // +optional 32 AggregateDevice string `json:"aggregateDevice,omitempty"` 33 34 // Capacity 35 Capacity DeviceCapacity `json:"capacity"` 36 37 // ClaimRef is the reference to the BDC which has claimed this BD 38 // +optional 39 ClaimRef *v1.ObjectReference `json:"claimRef,omitempty"` 40 41 // Details contain static attributes of BD like model,serial, and so forth 42 // +optional 43 Details DeviceDetails `json:"details"` 44 45 // DevLinks contains soft links of a block device like 46 // /dev/by-id/... 47 // /dev/by-uuid/... 48 DevLinks []DeviceDevLink `json:"devlinks"` 49 50 // FileSystem contains mountpoint and filesystem type 51 // +optional 52 FileSystem FileSystemInfo `json:"filesystem,omitempty"` 53 54 // NodeAttributes has the details of the node on which BD is attached 55 NodeAttributes NodeAttribute `json:"nodeAttributes"` 56 57 // ParentDevice was intended to store the UUID of the parent 58 // Block Device as is the case for partitioned block devices. 59 // 60 // For example: 61 // /dev/sda is the parent for /dev/sda1 62 // To be deprecated 63 // +kubebuilder:validation:Pattern:`^/dev/[a-z]{3,4}$` 64 // +optional 65 ParentDevice string `json:"parentDevice,omitempty"` 66 67 // Partitioned represents if BlockDevice has partitions or not (Yes/No) 68 // Currently always default to No. 69 // To be deprecated 70 // +kubebuilder:validation:Enum:=Yes;No 71 // +optional 72 Partitioned string `json:"partitioned"` 73 74 // Path contain devpath (e.g. /dev/sdb) 75 // +kubebuilder:validation:Pattern:`^/dev/[a-z]{3,4}$` 76 Path string `json:"path"` 77 } 78 79 // NodeAttribute defines the attributes of a node where 80 // the block device is attached. 81 // 82 // Note: Prior to introducing NodeAttributes, the BD would 83 // only support gathering hostname and add it as a label 84 // to the BD resource. 85 // 86 // In some use cases, the caller has access only to node name, not 87 // the hostname. node name and hostname are different in certain 88 // Kubernetes clusters. 89 // 90 // NodeAttributes is added to contain attributes that are not 91 // available on the labels like - node name, uuid, etc. 92 // 93 // The node attributes are helpful in querying for block devices 94 // based on node attributes. Also, adding this in the spec allows for 95 // displaying in node name in the `kubectl get bd` 96 // 97 // Capture and add nodeUUID to BD, that can help in determining 98 // if the node was recreated with same node name. 99 type NodeAttribute struct { 100 // NodeName is the name of the Kubernetes node resource on which the device is attached 101 // +optional 102 NodeName string `json:"nodeName"` 103 } 104 105 // DeviceCapacity defines the physical and logical size of the block device 106 type DeviceCapacity struct { 107 // Storage is the blockdevice capacity in bytes 108 Storage uint64 `json:"storage"` 109 110 // PhysicalSectorSize is blockdevice physical-Sector size in bytes 111 // +optional 112 PhysicalSectorSize uint32 `json:"physicalSectorSize"` 113 114 // LogicalSectorSize is blockdevice logical-sector size in bytes 115 // +optional 116 LogicalSectorSize uint32 `json:"logicalSectorSize"` 117 } 118 119 // DeviceDetails represent certain hardware/static attributes of the block device 120 type DeviceDetails struct { 121 // DeviceType represents the type of device like 122 // sparse, disk, partition, lvm, crypt 123 // +kubebuilder:validation:Enum:=disk;partition;sparse;loop;lvm;crypt;dm;mpath 124 // +optional 125 DeviceType string `json:"deviceType"` 126 127 // DriveType is the type of backing drive, HDD/SSD 128 // +kubebuilder:validation:Enum:=HDD;SSD;Unknown;"" 129 // +optional 130 DriveType string `json:"driveType"` 131 132 // LogicalBlockSize is the logical block size in bytes 133 // reported by /sys/class/block/sda/queue/logical_block_size 134 // +optional 135 LogicalBlockSize uint32 `json:"logicalBlockSize"` 136 137 // PhysicalBlockSize is the physical block size in bytes 138 // reported by /sys/class/block/sda/queue/physical_block_size 139 // +optional 140 PhysicalBlockSize uint32 `json:"physicalBlockSize"` 141 142 // HardwareSectorSize is the hardware sector size in bytes 143 // +optional 144 HardwareSectorSize uint32 `json:"hardwareSectorSize"` 145 146 // Model is model of disk 147 // +optional 148 Model string `json:"model"` 149 150 // Compliance is standards/specifications version implemented by device firmware 151 // such as SPC-1, SPC-2, etc 152 // +optional 153 Compliance string `json:"compliance"` 154 155 // Serial is serial number of disk 156 // +optional 157 Serial string `json:"serial"` 158 159 // Vendor is vendor of disk 160 // +optional 161 Vendor string `json:"vendor"` 162 163 // FirmwareRevision is the disk firmware revision 164 // +optional 165 FirmwareRevision string `json:"firmwareRevision"` 166 } 167 168 // FileSystemInfo defines the filesystem type and mountpoint of the device if it exists 169 type FileSystemInfo struct { 170 // Type represents the FileSystem type of the block device 171 // +optional 172 Type string `json:"fsType,omitempty"` 173 174 //MountPoint represents the mountpoint of the block device. 175 // +optional 176 Mountpoint string `json:"mountPoint,omitempty"` 177 } 178 179 // DeviceDevLink holds the mapping between type and links like by-id type or by-path type link 180 type DeviceDevLink struct { 181 // Kind is the type of link like by-id or by-path. 182 // +kubebuilder:validation:Enum:=by-id;by-path 183 Kind string `json:"kind,omitempty"` 184 185 // Links are the soft links 186 Links []string `json:"links,omitempty"` 187 } 188 189 // DeviceStatus defines the observed state of BlockDevice 190 type DeviceStatus struct { 191 // ClaimState represents the claim state of the block device 192 // +kubebuilder:validation:Enum:=Claimed;Unclaimed;Released 193 ClaimState DeviceClaimState `json:"claimState"` 194 195 // State is the current state of the blockdevice (Active/Inactive/Unknown) 196 // +kubebuilder:validation:Enum:=Active;Inactive;Unknown 197 State BlockDeviceState `json:"state"` 198 } 199 200 // DeviceClaimState defines the observed state of BlockDevice 201 type DeviceClaimState string 202 203 const ( 204 // BlockDeviceUnclaimed represents that the block device is not bound to any BDC, 205 // all cleanup jobs have been completed and is available for claiming. 206 BlockDeviceUnclaimed DeviceClaimState = "Unclaimed" 207 208 // BlockDeviceReleased represents that the block device is released from the BDC, 209 // pending cleanup jobs 210 BlockDeviceReleased DeviceClaimState = "Released" 211 212 // BlockDeviceClaimed represents that the block device is bound to a BDC 213 BlockDeviceClaimed DeviceClaimState = "Claimed" 214 ) 215 216 // BlockDeviceState defines the observed state of the disk 217 type BlockDeviceState string 218 219 const ( 220 // BlockDeviceActive is the state for a block device that is connected to the node 221 BlockDeviceActive BlockDeviceState = "Active" 222 223 // BlockDeviceInactive is the state for a block device that is disconnected from a node 224 BlockDeviceInactive BlockDeviceState = "Inactive" 225 226 // BlockDeviceUnknown is the state for a block device whose state (attached/detached) cannot 227 // be determined at this time. 228 BlockDeviceUnknown BlockDeviceState = "Unknown" 229 ) 230 231 //+kubebuilder:object:root=true 232 //+kubebuilder:resource:scope=Namespaced,shortName=bd 233 234 // BlockDevice is the Schema for the blockdevices API 235 // +kubebuilder:printcolumn:name="NodeName",type="string",JSONPath=`.spec.nodeAttributes.nodeName` 236 // +kubebuilder:printcolumn:name="Path",type="string",JSONPath=`.spec.path`,priority=1 237 // +kubebuilder:printcolumn:name="FSType",type="string",JSONPath=`.spec.filesystem.fsType`,priority=1 238 // +kubebuilder:printcolumn:name="Size",type="string",JSONPath=`.spec.capacity.storage` 239 // +kubebuilder:printcolumn:name="ClaimState",type="string",JSONPath=`.status.claimState` 240 // +kubebuilder:printcolumn:name="Status",type=string,JSONPath=`.status.state` 241 // +kubebuilder:printcolumn:name="Age",type="date",JSONPath=`.metadata.creationTimestamp` 242 type BlockDevice struct { 243 metav1.TypeMeta `json:",inline"` 244 metav1.ObjectMeta `json:"metadata,omitempty"` 245 246 Spec DeviceSpec `json:"spec,omitempty"` 247 Status DeviceStatus `json:"status,omitempty"` 248 } 249 250 //+kubebuilder:object:root=true 251 252 // BlockDeviceList contains a list of BlockDevice 253 type BlockDeviceList struct { 254 metav1.TypeMeta `json:",inline"` 255 metav1.ListMeta `json:"metadata,omitempty"` 256 Items []BlockDevice `json:"items"` 257 } 258 259 func init() { 260 SchemeBuilder.Register(&BlockDevice{}, &BlockDeviceList{}) 261 }