Skip to content

Commit

Permalink
Add ephemeral storage support to the AdditionalBlockDevices
Browse files Browse the repository at this point in the history
Co-authored-by: Emilien Macchi <[email protected]>
Co-authored-by: Martin André <[email protected]>
  • Loading branch information
3 people committed Oct 24, 2023
1 parent 3853737 commit ea650f0
Show file tree
Hide file tree
Showing 13 changed files with 571 additions and 121 deletions.
8 changes: 7 additions & 1 deletion api/v1alpha7/openstackmachine_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,9 +84,15 @@ type OpenStackMachineSpec struct {
// The volume metadata to boot from
RootVolume *RootVolume `json:"rootVolume,omitempty"`

// AdditionalBlockDevices is a list of specifications for additional block devices to attach to the server instance
// additionalBlockDevices is a list of specifications for additional block devices to attach to the server instance
//
// + ---
// + While it's possible to have unlimited number of block devices attached to a server instance, the number is
// + limited to 255 to avoid rule cost exceeded error in CRD validation.
// +kubebuilder:validation:MaxItems=255
// +listType=map
// +listMapKey=name
// +optional
AdditionalBlockDevices []AdditionalBlockDevice `json:"additionalBlockDevices,omitempty"`

// The server group to assign the machine to
Expand Down
83 changes: 73 additions & 10 deletions api/v1alpha7/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -163,20 +163,83 @@ type RootVolume struct {
AvailabilityZone string `json:"availabilityZone,omitempty"`
}

type AdditionalBlockDevice struct {
// Name of the Cinder volume in the context of a machine.
// It will be combined with the machine name to make the actual volume name.
Name string `json:"name"`
// Size is the size in GB of the volume.
Size int `json:"diskSize"`
// VolumeType is the volume type of the volume.
// If omitted, the default type will be used.
VolumeType string `json:"volumeType,omitempty"`
// AvailabilityZone is the volume availability zone to create the volume in.
// blockDeviceStorage is the storage type of a block device to create and
// contains additional storage options.
// +kubebuilder:validation:XValidation:rule="self.type == 'Local' ? !has(self.volume) : has(self.volume)",message="volume is forbidden for type 'Local'"
// +union
//
//nolint:godot
type BlockDeviceStorage struct {
// type is the type of block device to create.
// This can be either "Volume" or "Local".
// +kubebuilder:validation:Enum="Volume";"Local"
// +kubebuilder:validation:Required
// +unionDiscriminator
Type BlockDeviceType `json:"type"`

// volume contains additional storage options for a volume block device.
// +optional
// +unionMember,optional
Volume *BlockDeviceVolume `json:"volume,omitempty"`
}

// blockDeviceVolume contains additional storage options for a volume block device.
type BlockDeviceVolume struct {
// type is the Cinder volume type of the volume.
// If omitted, the default Cinder volume type that is configured in the OpenStack cloud
// will be used.
// The maximum length of a volume type name is 255 characters, as per the OpenStack limit.
// +kubebuilder:validation:MinLength=1
// +kubebuilder:validation:MaxLength=255
// +optional
Type string `json:"type,omitempty"`

// availabilityZone is the volume availability zone to create the volume in.
// If omitted, the availability zone of the server will be used.
// The availability zone must NOT contain spaces otherwise it will lead to volume that belongs
// to this availability zone register failure, see kubernetes/cloud-provider-openstack#1379 for
// further information.
// The maximum length of availability zone name is 63 as per labels limits.
// +kubebuilder:validation:MinLength=1
// +kubebuilder:validation:MaxLength=63
// +kubebuilder:validation:XValidation:rule="!self.contains(' ')",message="availabilityZone may not contain spaces"
// +optional
AvailabilityZone string `json:"availabilityZone,omitempty"`
}

// additionalBlockDevice is a block device to attach to the server.
type AdditionalBlockDevice struct {
// name of the block device in the context of a machine.
// If the block device is a volume, the Cinder volume will be named
// as a combination of the machine name and this name.
// Also, this name will be used for tagging the block device.
// Information about the block device tag can be obtained from the OpenStack
// metadata API or the config drive.
// +kubebuilder:validation:Required
Name string `json:"name"`

// sizeGiB is the size of the block device in gibibytes (GiB).
// +kubebuilder:validation:Minimum=1
// +kubebuilder:validation:Required
SizeGiB int `json:"sizeGiB"`

// storage specifies the storage type of the block device and
// additional storage options.
// +kubebuilder:validation:Required
Storage BlockDeviceStorage `json:"storage"`
}

// BlockDeviceType defines the type of block device to create.
type BlockDeviceType string

const (
// LocalBlockDevice is an ephemeral block device attached to the server.
LocalBlockDevice BlockDeviceType = "Local"

// VolumeBlockDevice is a volume block device attached to the server.
VolumeBlockDevice BlockDeviceType = "Volume"
)

// NetworkStatus contains basic information about an existing neutron network.
type NetworkStatus struct {
Name string `json:"name"`
Expand Down
40 changes: 39 additions & 1 deletion api/v1alpha7/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -3771,31 +3771,83 @@ spec:
description: Instance for the bastion itself
properties:
additionalBlockDevices:
description: AdditionalBlockDevices is a list of specifications
description: additionalBlockDevices is a list of specifications
for additional block devices to attach to the server instance
items:
description: additionalBlockDevice is a block device to
attach to the server.
properties:
availabilityZone:
description: AvailabilityZone is the volume availability
zone to create the volume in. If omitted, the availability
zone of the server will be used.
type: string
diskSize:
description: Size is the size in GB of the volume.
type: integer
name:
description: Name of the Cinder volume in the context
of a machine. It will be combined with the machine
name to make the actual volume name.
type: string
volumeType:
description: VolumeType is the volume type of the volume.
If omitted, the default type will be used.
description: name of the block device in the context
of a machine. If the block device is a volume, the
Cinder volume will be named as a combination of the
machine name and this name. Also, this name will be
used for tagging the block device. Information about
the block device tag can be obtained from the OpenStack
metadata API or the config drive.
type: string
sizeGiB:
description: sizeGiB is the size of the block device
in gibibytes (GiB).
minimum: 1
type: integer
storage:
description: storage specifies the storage type of the
block device and additional storage options.
properties:
type:
description: type is the type of block device to
create. This can be either "Volume" or "Local".
enum:
- Volume
- Local
type: string
volume:
description: volume contains additional storage
options for a volume block device.
properties:
availabilityZone:
description: availabilityZone is the volume
availability zone to create the volume in.
If omitted, the availability zone of the server
will be used. The availability zone must NOT
contain spaces otherwise it will lead to volume
that belongs to this availability zone register
failure, see kubernetes/cloud-provider-openstack#1379
for further information. The maximum length
of availability zone name is 63 as per labels
limits.
maxLength: 63
minLength: 1
type: string
x-kubernetes-validations:
- message: availabilityZone may not contain
spaces
rule: '!self.contains('' '')'
type:
description: type is the Cinder volume type
of the volume. If omitted, the default Cinder
volume type that is configured in the OpenStack
cloud will be used. The maximum length of
a volume type name is 255 characters, as per
the OpenStack limit.
maxLength: 255
minLength: 1
type: string
type: object
required:
- type
type: object
x-kubernetes-validations:
- message: volume is forbidden for type 'Local'
rule: 'self.type == ''Local'' ? !has(self.volume)
: has(self.volume)'
required:
- diskSize
- name
- sizeGiB
- storage
type: object
maxItems: 255
type: array
x-kubernetes-list-map-keys:
- name
Expand Down
Loading

0 comments on commit ea650f0

Please sign in to comment.