Skip to content

Commit

Permalink
refact(apis): refact NDM apis to adhere to k8s standard (#301)
Browse files Browse the repository at this point in the history
* refact(apis): refact BD and BDC apis to adhere to k8s api definition
* chore(code-gen): autogenerated code
* fix typo in block device apis

Signed-off-by: Akhil Mohan <[email protected]>
  • Loading branch information
akhilerm authored and kmova committed Sep 4, 2019
1 parent 54ea8ce commit d96bb03
Show file tree
Hide file tree
Showing 6 changed files with 355 additions and 150 deletions.
1 change: 0 additions & 1 deletion deploy/crds/openebs_v1alpha1_blockdevice_cr.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -29,5 +29,4 @@ spec:
- <link1> # like /dev/disk/by-path/virtio-pci-0000:00:03.0-scsi-0:0:2:0
nodeAttributes:
nodeName: <node name> # output of `kubectl get nodes` can be used
partitioned: # Yes or No
path: <devpath> # like /dev/sdb
2 changes: 1 addition & 1 deletion deploy/crds/openebs_v1alpha1_blockdeviceclaim_cr.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ kind: BlockDeviceClaim
metadata:
name: example-blockdeviceclaim
spec:
hostName: "" # hostname of the node from which you want to get a BD
nodeAttributes:
nodeName: "" # node name of the k8s node. Output from `kubectl get nodes`
hostName: "" # hostname of the node from which you want to get a BD
blockDeviceName: "" # BD name, if you want to claim a specific block device
resources:
requests:
Expand Down
187 changes: 133 additions & 54 deletions pkg/apis/openebs/v1alpha1/blockdevice_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,106 +21,185 @@ import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

// EDIT THIS FILE! THIS IS SCAFFOLDING FOR YOU TO OWN!
// NOTE: json tags are required. Any new fields you add must have json tags for the fields to be serialized.

// INSERT ADDITIONAL SPEC FIELDS - desired state of cluster
// Important: Run "operator-sdk generate k8s" to regenerate code after modifying this file

// DeviceSpec defines the desired state of BlockDevice
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
// +k8s:openapi-gen=true

// BlockDevice is the Schema used to represent a BlockDevice CR
type BlockDevice struct {
metav1.TypeMeta `json:",inline"`
metav1.ObjectMeta `json:"metadata,omitempty"`

Spec DeviceSpec `json:"spec,omitempty"`
Status DeviceStatus `json:"status,omitempty"`
}

// DeviceSpec defines the properties and runtime status of a BlockDevice
type DeviceSpec struct {
// NodeAttributes has the details of the node in which this BD is attached
NodeAttributes NodeAttribute `json:"nodeAttributes"`
Path string `json:"path"` //Path contain devpath (e.g. /dev/sdb)
Capacity DeviceCapacity `json:"capacity"` //Capacity
Details DeviceDetails `json:"details"` //Details contains static attributes (model, serial ..)
ClaimRef *v1.ObjectReference `json:"claimRef,omitempty"` // Reference to the BDC which has claimed this BD
DevLinks []DeviceDevLink `json:"devlinks"` //DevLinks contains soft links of one disk
FileSystem FileSystemInfo `json:"filesystem,omitempty"` //FileSystem contains mountpoint and filesystem type
Partitioned string `json:"partitioned"` //BlockDevice has partions or not (YES/NO)
ParentDevice string `json:"parentDevice,omitempty"` //ParentDevice has the UUID of the parent device
AggregateDevice string `json:"aggregateDevice,omitempty"` //AggregateDevice has the UUID of the aggregate device created from this device
// NodeAttributes has the details of the node on which BD is attached
NodeAttributes NodeAttribute `json:"nodeAttributes"`

// Path contain devpath (e.g. /dev/sdb)
Path string `json:"path"`

// Capacity
Capacity DeviceCapacity `json:"capacity"`

// Details contain static attributes of BD like model,serial, and so forth
Details DeviceDetails `json:"details"`

// ClaimRef is the reference to the BDC which has claimed this BD
ClaimRef *v1.ObjectReference `json:"claimRef,omitempty"`

// DevLinks contains soft links of a block device like
// /dev/by-id/...
// /dev/by-uuid/...
DevLinks []DeviceDevLink `json:"devlinks"`

// FileSystem contains mountpoint and filesystem type
FileSystem FileSystemInfo `json:"filesystem,omitempty"`

// Partitioned represents if BlockDevice has partitions or not (Yes/No)
// Currently always default to No.
// TODO @kmova to be implemented/deprecated
Partitioned string `json:"partitioned"`

// ParentDevice was intended to store the UUID of the parent
// Block Device as is the case for partitioned block devices.
//
// For example:
// /dev/sda is the parent for /dev/sdap1
// TODO @kmova to be implemented/deprecated
ParentDevice string `json:"parentDevice,omitempty"`

// AggregateDevice was intended to store the hierachical
// information in cases of LVM. However this is currently
// not implemented and may need to be re-looked into for
// better design.
// TODO @kmova to be implemented/deprecated
AggregateDevice string `json:"aggregateDevice,omitempty"`
}

// NodeAttribute defines the various attributes of the node
// NodeAttribute defines the attributes of a node where
// the block device is attached.
//
// Note: Prior to introducing NodeAttributes, the BD would
// only support gathering hostname and add it as a label
// to the BD resource.
//
// In some use cases, the caller has access only to node name, not
// the hostname. node name and hostname are different in certain
// Kubernetes clusters.
//
// NodeAttributes is added to contain attributes that are not
// available on the labels like - node name, uuid, etc.
//
// The node attributes are helpful in querying for block devices
// based on node attributes. Also, adding this in the spec allows for
// displaying in node name in the `kubectl get bd`
//
// TODO @kmova @akhilerm
// Capture and add nodeUUID to BD, that can help in determining
// if the node was recreated with same node name.
type NodeAttribute struct {
// NodeName is the name of the node in which the device is attached
// NodeName is the name of the Kubernetes node resource on which the device is attached
NodeName string `json:"nodeName"`
}

// DeviceCapacity defines the physical and logical size of the block device
type DeviceCapacity struct {
Storage uint64 `json:"storage"` // blockdevice capacity in bytes
PhysicalSectorSize uint32 `json:"physicalSectorSize"` // blockdevice physical-Sector size in bytes
LogicalSectorSize uint32 `json:"logicalSectorSize"` // blockdevice logical-sector size in bytes
// Storage is the blockdevice capacity in bytes
Storage uint64 `json:"storage"`

// PhysicalSectorSize is blockdevice physical-Sector size in bytes
PhysicalSectorSize uint32 `json:"physicalSectorSize"`

// LogicalSectorSize is blockdevice logical-sector size in bytes
LogicalSectorSize uint32 `json:"logicalSectorSize"`
}

// DeviceDetails represent certain hardware/static attributes of the block device
type DeviceDetails struct {
DeviceType string `json:"deviceType"` // DeviceType represents the type of drive like SSD, HDD etc.,
Model string `json:"model"` // Model is model of disk
Compliance string `json:"compliance"` // Implemented standards/specifications version such as SPC-1, SPC-2, etc
Serial string `json:"serial"` // Serial is serial no of disk
Vendor string `json:"vendor"` // Vendor is vendor of disk
FirmwareRevision string `json:"firmwareRevision"` // disk firmware revision
// DeviceType represents the type of drive like SSD, HDD etc.,
DeviceType string `json:"deviceType"`

// Model is model of disk
Model string `json:"model"`

// Compliance is standards/specifications version implemented by device firmware
// such as SPC-1, SPC-2, etc
Compliance string `json:"compliance"`

// Serial is serial number of disk
Serial string `json:"serial"`

// Vendor is vendor of disk
Vendor string `json:"vendor"`

// FirmwareRevision is the disk firmware revision
FirmwareRevision string `json:"firmwareRevision"`
}

// FileSystemInfo defines the filesystem type and mountpoint of the device if it exists
type FileSystemInfo struct {
Type string `json:"fsType,omitempty"` //Type represents the FileSystem type of the block device
Mountpoint string `json:"mountPoint,omitempty"` //MountPoint represents the mountpoint of the block device.
//Type represents the FileSystem type of the block device
Type string `json:"fsType,omitempty"`

//MountPoint represents the mountpoint of the block device.
Mountpoint string `json:"mountPoint,omitempty"`
}

// DeviceDevLink holds the maping between type and links like by-id type or by-path type link
type DeviceDevLink struct {
Kind string `json:"kind,omitempty"` // Kind is the type of link like by-id or by-path.
Links []string `json:"links,omitempty"` // Links are the soft links of Type type
// Kind is the type of link like by-id or by-path.
Kind string `json:"kind,omitempty"`

// Links are the soft links
Links []string `json:"links,omitempty"`
}

// DeviceStatus defines the observed state of BlockDevice
type DeviceStatus struct {
ClaimState DeviceClaimState `json:"claimState"` // claim state of the block device
State BlockDeviceState `json:"state"` // current state of the blockdevice (Active/Inactive)
}
// ClaimState represents the claim state of the block device
ClaimState DeviceClaimState `json:"claimState"`

// BlockDeviceState defines the observed state of the disk
type BlockDeviceState string

const (
// BlockDeviceActive is the state for a block device that is connected to the node
BlockDeviceActive BlockDeviceState = "Active"
// BlockDeviceInactive is the state for a block device that is disconnected from a node
BlockDeviceInactive BlockDeviceState = "Inactive"
// BlockDeviceUnknown is the state for a block device whose state (attached/detached) cannot
// be determined at this time.
BlockDeviceUnknown BlockDeviceState = "Unknown"
)
// State is the current state of the blockdevice (Active/Inactive)
State BlockDeviceState `json:"state"`
}

// DeviceClaimState defines the observed claim state of BlockDevice
// DeviceClaimState defines the observed state of BlockDevice
type DeviceClaimState string

const (
// BlockDeviceUnclaimed represents that the block device is not bound to any BDC,
// all cleanup jobs have been completed and is available for claiming.
BlockDeviceUnclaimed DeviceClaimState = "Unclaimed"

// BlockDeviceReleased represents that the block device is released from the BDC,
// pending cleanup jobs
BlockDeviceReleased DeviceClaimState = "Released"

// BlockDeviceClaimed represents that the block device is bound to a BDC
BlockDeviceClaimed DeviceClaimState = "Claimed"
)

// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
// BlockDeviceState defines the observed state of the disk
type BlockDeviceState string

// BlockDevice is the Schema for the devices API
// +k8s:openapi-gen=true
type BlockDevice struct {
metav1.TypeMeta `json:",inline"`
metav1.ObjectMeta `json:"metadata,omitempty"`
const (
// BlockDeviceActive is the state for a block device that is connected to the node
BlockDeviceActive BlockDeviceState = "Active"

Spec DeviceSpec `json:"spec,omitempty"`
Status DeviceStatus `json:"status,omitempty"`
}
// BlockDeviceInactive is the state for a block device that is disconnected from a node
BlockDeviceInactive BlockDeviceState = "Inactive"

// BlockDeviceUnknown is the state for a block device whose state (attached/detached) cannot
// be determined at this time.
BlockDeviceUnknown BlockDeviceState = "Unknown"
)

// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object

Expand Down
Loading

0 comments on commit d96bb03

Please sign in to comment.