github.com/openebs/node-disk-manager@v1.9.1-0.20230225014141-4531f06ffa1e/api/v1alpha1/blockdeviceclaim_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  // DeviceClaimSpec defines the request details for a BlockDevice
    25  type DeviceClaimSpec struct {
    26  
    27  	// Selector is used to find block devices to be considered for claiming
    28  	// +optional
    29  	Selector *metav1.LabelSelector `json:"selector,omitempty"`
    30  
    31  	// Resources will help with placing claims on Capacity, IOPS
    32  	// +optional
    33  	Resources DeviceClaimResources `json:"resources"`
    34  
    35  	// DeviceType represents the type of drive like SSD, HDD etc.,
    36  	// +optional
    37  	// +nullable
    38  	DeviceType string `json:"deviceType"`
    39  
    40  	// Node name from where blockdevice has to be claimed.
    41  	// To be deprecated. Use NodeAttributes.HostName instead
    42  	// +optional
    43  	HostName string `json:"hostName"`
    44  
    45  	// Details of the device to be claimed
    46  	// +optional
    47  	Details DeviceClaimDetails `json:"deviceClaimDetails,omitempty"`
    48  
    49  	// BlockDeviceName is the reference to the block-device backing this claim
    50  	// +optional
    51  	BlockDeviceName string `json:"blockDeviceName,omitempty"`
    52  
    53  	// BlockDeviceNodeAttributes is the attributes on the node from which a BD should
    54  	// be selected for this claim. It can include nodename, failure domain etc.
    55  	// +optional
    56  	BlockDeviceNodeAttributes BlockDeviceNodeAttributes `json:"blockDeviceNodeAttributes,omitempty"`
    57  }
    58  
    59  // DeviceClaimResources defines the request by the claim, eg, Capacity, IOPS
    60  type DeviceClaimResources struct {
    61  	// Requests describes the minimum resources required. eg: if storage resource of 10G is
    62  	// requested minimum capacity of 10G should be available
    63  	//TODO for validating
    64  	Requests v1.ResourceList `json:"requests"`
    65  }
    66  
    67  const (
    68  	// ResourceStorage defines the storage required as v1.Quantity
    69  	ResourceStorage v1.ResourceName = "storage"
    70  )
    71  
    72  // DeviceClaimDetails defines the details of the block device that should be claimed
    73  type DeviceClaimDetails struct {
    74  	// BlockVolumeMode represents whether to claim a device in Block mode or Filesystem mode.
    75  	// These are use cases of BlockVolumeMode:
    76  	// 1) Not specified: VolumeMode check will not be effective
    77  	// 2) VolumeModeBlock: BD should not have any filesystem or mountpoint
    78  	// 3) VolumeModeFileSystem: BD should have a filesystem and mountpoint. If DeviceFormat is
    79  	//    specified then the format should match with the FSType in BD
    80  	BlockVolumeMode BlockDeviceVolumeMode `json:"blockVolumeMode,omitempty"`
    81  
    82  	//Format of the device required, eg:ext4, xfs
    83  	DeviceFormat string `json:"formatType,omitempty"`
    84  
    85  	//AllowPartition represents whether to claim a full block device or a device that is a partition
    86  	AllowPartition bool `json:"allowPartition,omitempty"`
    87  }
    88  
    89  // BlockDeviceVolumeMode specifies the type in which the BlockDevice can be used
    90  type BlockDeviceVolumeMode string
    91  
    92  const (
    93  	// VolumeModeBlock specifies that the block device needs to be used as a raw block
    94  	VolumeModeBlock BlockDeviceVolumeMode = "Block"
    95  
    96  	// VolumeModeFileSystem specifies that block device will be used with a filesystem
    97  	// already existing
    98  	VolumeModeFileSystem BlockDeviceVolumeMode = "FileSystem"
    99  )
   100  
   101  // BlockDeviceNodeAttributes contains the attributes of the node from which the BD should
   102  // be selected for claiming. A BDC can specify one or more attributes. When multiple values
   103  // are specified, the NDM Operator will claim a Block Device that matches all
   104  // the requested attributes.
   105  type BlockDeviceNodeAttributes struct {
   106  	// NodeName represents the name of the Kubernetes node resource
   107  	// where the BD should be present
   108  	NodeName string `json:"nodeName,omitempty"`
   109  
   110  	// HostName represents the hostname of the Kubernetes node resource
   111  	// where the BD should be present
   112  	HostName string `json:"hostName,omitempty"`
   113  }
   114  
   115  // DeviceClaimStatus defines the observed state of BlockDeviceClaim
   116  type DeviceClaimStatus struct {
   117  	// Phase represents the current phase of the claim
   118  	Phase DeviceClaimPhase `json:"phase"`
   119  }
   120  
   121  // DeviceClaimPhase is a typed string for phase field of BlockDeviceClaim.
   122  type DeviceClaimPhase string
   123  
   124  // BlockDeviceClaim CR, when created pass through phases before it got some Devices Assigned.
   125  // Given below table, have all phases which BlockDeviceClaim CR can go before it is marked done.
   126  const (
   127  	// BlockDeviceClaimStatusEmpty represents that the BlockDeviceClaim was just created.
   128  	BlockDeviceClaimStatusEmpty DeviceClaimPhase = ""
   129  
   130  	// BlockDeviceClaimStatusPending represents BlockDeviceClaim has not been assigned devices yet. Rather
   131  	// search is going on for matching devices.
   132  	BlockDeviceClaimStatusPending DeviceClaimPhase = "Pending"
   133  
   134  	// BlockDeviceClaimStatusInvalidCapacity represents BlockDeviceClaim has invalid capacity request i.e. 0/-1
   135  	// Deprecated
   136  	BlockDeviceClaimStatusInvalidCapacity DeviceClaimPhase = "Invalid Capacity Request"
   137  
   138  	// BlockDeviceClaimStatusDone represents BlockDeviceClaim has been assigned backing blockdevice and ready for use.
   139  	BlockDeviceClaimStatusDone DeviceClaimPhase = "Bound"
   140  )
   141  
   142  // BlockDeviceClaim is the Schema for the blockdeviceclaims API
   143  //+kubebuilder:object:root=true
   144  // +kubebuilder:resource:scope=Namespaced,shortName=bdc
   145  // +kubebuilder:printcolumn:name="BlockDeviceName",type="string",JSONPath=`.spec.blockDeviceName`
   146  // +kubebuilder:printcolumn:name="Phase",type="string",JSONPath=`.status.phase`
   147  // +kubebuilder:printcolumn:name="Age",type="date",JSONPath=`.metadata.creationTimestamp`
   148  type BlockDeviceClaim struct {
   149  	metav1.TypeMeta   `json:",inline"`
   150  	metav1.ObjectMeta `json:"metadata,omitempty"`
   151  
   152  	Spec   DeviceClaimSpec   `json:"spec,omitempty"`
   153  	Status DeviceClaimStatus `json:"status,omitempty"`
   154  }
   155  
   156  //+kubebuilder:object:root=true
   157  
   158  // BlockDeviceClaimList contains a list of BlockDeviceClaim
   159  type BlockDeviceClaimList struct {
   160  	metav1.TypeMeta `json:",inline"`
   161  	metav1.ListMeta `json:"metadata,omitempty"`
   162  	Items           []BlockDeviceClaim `json:"items"`
   163  }
   164  
   165  func init() {
   166  	SchemeBuilder.Register(&BlockDeviceClaim{}, &BlockDeviceClaimList{})
   167  }