Skip to content

Commit 5968640

Browse files
authored
Merge pull request kubernetes-sigs#1696 from shiftstack/bd_ephemeral
✨ Add ephemeral storage support to the AdditionalBlockDevices
2 parents 292abc1 + 71fa48f commit 5968640

15 files changed

+479
-115
lines changed

.golangci.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,9 @@ linters-settings:
126126
- pkg: sigs.k8s.io/cluster-api/controlplane/kubeadm/api/v1beta1
127127
alias: controlplanev1
128128

129+
nolintlint:
130+
# https://github.com/golangci/golangci-lint/issues/3228
131+
allow-unused: true
129132
staticcheck:
130133
go: "1.17"
131134
stylecheck:

api/v1alpha7/openstackmachine_types.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ type OpenStackMachineSpec struct {
8787
// AdditionalBlockDevices is a list of specifications for additional block devices to attach to the server instance
8888
// +listType=map
8989
// +listMapKey=name
90+
// +optional
9091
AdditionalBlockDevices []AdditionalBlockDevice `json:"additionalBlockDevices,omitempty"`
9192

9293
// The server group to assign the machine to

api/v1alpha7/openstackmachine_webhook.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,14 @@ func (r *OpenStackMachine) ValidateCreate() (admission.Warnings, error) {
6262
allErrs = append(allErrs, field.Forbidden(field.NewPath("spec", "identityRef", "kind"), "must be a Secret"))
6363
}
6464

65+
if r.Spec.RootVolume != nil && r.Spec.AdditionalBlockDevices != nil {
66+
for _, device := range r.Spec.AdditionalBlockDevices {
67+
if device.Name == "root" {
68+
allErrs = append(allErrs, field.Forbidden(field.NewPath("spec", "additionalBlockDevices"), "cannot contain a device named \"root\" when rootVolume is set"))
69+
}
70+
}
71+
}
72+
6573
return aggregateObjErrors(r.GroupVersionKind().GroupKind(), r.Name, allErrs)
6674
}
6775

api/v1alpha7/types.go

Lines changed: 58 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -163,20 +163,69 @@ type RootVolume struct {
163163
AvailabilityZone string `json:"availabilityZone,omitempty"`
164164
}
165165

166-
type AdditionalBlockDevice struct {
167-
// Name of the Cinder volume in the context of a machine.
168-
// It will be combined with the machine name to make the actual volume name.
169-
Name string `json:"name"`
170-
// Size is the size in GB of the volume.
171-
Size int `json:"diskSize"`
172-
// VolumeType is the volume type of the volume.
173-
// If omitted, the default type will be used.
174-
VolumeType string `json:"volumeType,omitempty"`
166+
// BlockDeviceStorage is the storage type of a block device to create and
167+
// contains additional storage options.
168+
// +union
169+
//
170+
//nolint:godot
171+
type BlockDeviceStorage struct {
172+
// Type is the type of block device to create.
173+
// This can be either "Volume" or "Local".
174+
// +unionDiscriminator
175+
Type BlockDeviceType `json:"type"`
176+
177+
// Volume contains additional storage options for a volume block device.
178+
// +optional
179+
// +unionMember,optional
180+
Volume *BlockDeviceVolume `json:"volume,omitempty"`
181+
}
182+
183+
// BlockDeviceVolume contains additional storage options for a volume block device.
184+
type BlockDeviceVolume struct {
185+
// Type is the Cinder volume type of the volume.
186+
// If omitted, the default Cinder volume type that is configured in the OpenStack cloud
187+
// will be used.
188+
// +optional
189+
Type string `json:"type,omitempty"`
190+
175191
// AvailabilityZone is the volume availability zone to create the volume in.
176192
// If omitted, the availability zone of the server will be used.
193+
// The availability zone must NOT contain spaces otherwise it will lead to volume that belongs
194+
// to this availability zone register failure, see kubernetes/cloud-provider-openstack#1379 for
195+
// further information.
196+
// +optional
177197
AvailabilityZone string `json:"availabilityZone,omitempty"`
178198
}
179199

200+
// AdditionalBlockDevice is a block device to attach to the server.
201+
type AdditionalBlockDevice struct {
202+
// Name of the block device in the context of a machine.
203+
// If the block device is a volume, the Cinder volume will be named
204+
// as a combination of the machine name and this name.
205+
// Also, this name will be used for tagging the block device.
206+
// Information about the block device tag can be obtained from the OpenStack
207+
// metadata API or the config drive.
208+
Name string `json:"name"`
209+
210+
// SizeGiB is the size of the block device in gibibytes (GiB).
211+
SizeGiB int `json:"sizeGiB"`
212+
213+
// Storage specifies the storage type of the block device and
214+
// additional storage options.
215+
Storage BlockDeviceStorage `json:"storage"`
216+
}
217+
218+
// BlockDeviceType defines the type of block device to create.
219+
type BlockDeviceType string
220+
221+
const (
222+
// LocalBlockDevice is an ephemeral block device attached to the server.
223+
LocalBlockDevice BlockDeviceType = "Local"
224+
225+
// VolumeBlockDevice is a volume block device attached to the server.
226+
VolumeBlockDevice BlockDeviceType = "Volume"
227+
)
228+
180229
// NetworkStatus contains basic information about an existing neutron network.
181230
type NetworkStatus struct {
182231
Name string `json:"name"`

api/v1alpha7/zz_generated.deepcopy.go

Lines changed: 39 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

config/crd/bases/infrastructure.cluster.x-k8s.io_openstackclusters.yaml

Lines changed: 47 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -3774,27 +3774,58 @@ spec:
37743774
description: AdditionalBlockDevices is a list of specifications
37753775
for additional block devices to attach to the server instance
37763776
items:
3777+
description: AdditionalBlockDevice is a block device to
3778+
attach to the server.
37773779
properties:
3778-
availabilityZone:
3779-
description: AvailabilityZone is the volume availability
3780-
zone to create the volume in. If omitted, the availability
3781-
zone of the server will be used.
3782-
type: string
3783-
diskSize:
3784-
description: Size is the size in GB of the volume.
3785-
type: integer
37863780
name:
3787-
description: Name of the Cinder volume in the context
3788-
of a machine. It will be combined with the machine
3789-
name to make the actual volume name.
3790-
type: string
3791-
volumeType:
3792-
description: VolumeType is the volume type of the volume.
3793-
If omitted, the default type will be used.
3781+
description: Name of the block device in the context
3782+
of a machine. If the block device is a volume, the
3783+
Cinder volume will be named as a combination of the
3784+
machine name and this name. Also, this name will be
3785+
used for tagging the block device. Information about
3786+
the block device tag can be obtained from the OpenStack
3787+
metadata API or the config drive.
37943788
type: string
3789+
sizeGiB:
3790+
description: SizeGiB is the size of the block device
3791+
in gibibytes (GiB).
3792+
type: integer
3793+
storage:
3794+
description: Storage specifies the storage type of the
3795+
block device and additional storage options.
3796+
properties:
3797+
type:
3798+
description: Type is the type of block device to
3799+
create. This can be either "Volume" or "Local".
3800+
type: string
3801+
volume:
3802+
description: Volume contains additional storage
3803+
options for a volume block device.
3804+
properties:
3805+
availabilityZone:
3806+
description: AvailabilityZone is the volume
3807+
availability zone to create the volume in.
3808+
If omitted, the availability zone of the server
3809+
will be used. The availability zone must NOT
3810+
contain spaces otherwise it will lead to volume
3811+
that belongs to this availability zone register
3812+
failure, see kubernetes/cloud-provider-openstack#1379
3813+
for further information.
3814+
type: string
3815+
type:
3816+
description: Type is the Cinder volume type
3817+
of the volume. If omitted, the default Cinder
3818+
volume type that is configured in the OpenStack
3819+
cloud will be used.
3820+
type: string
3821+
type: object
3822+
required:
3823+
- type
3824+
type: object
37953825
required:
3796-
- diskSize
37973826
- name
3827+
- sizeGiB
3828+
- storage
37983829
type: object
37993830
type: array
38003831
x-kubernetes-list-map-keys:

config/crd/bases/infrastructure.cluster.x-k8s.io_openstackclustertemplates.yaml

Lines changed: 52 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1615,30 +1615,63 @@ spec:
16151615
for additional block devices to attach to the server
16161616
instance
16171617
items:
1618+
description: AdditionalBlockDevice is a block device
1619+
to attach to the server.
16181620
properties:
1619-
availabilityZone:
1620-
description: AvailabilityZone is the volume
1621-
availability zone to create the volume in.
1622-
If omitted, the availability zone of the server
1623-
will be used.
1624-
type: string
1625-
diskSize:
1626-
description: Size is the size in GB of the volume.
1627-
type: integer
16281621
name:
1629-
description: Name of the Cinder volume in the
1630-
context of a machine. It will be combined
1631-
with the machine name to make the actual volume
1632-
name.
1633-
type: string
1634-
volumeType:
1635-
description: VolumeType is the volume type of
1636-
the volume. If omitted, the default type will
1637-
be used.
1622+
description: Name of the block device in the
1623+
context of a machine. If the block device
1624+
is a volume, the Cinder volume will be named
1625+
as a combination of the machine name and this
1626+
name. Also, this name will be used for tagging
1627+
the block device. Information about the block
1628+
device tag can be obtained from the OpenStack
1629+
metadata API or the config drive.
16381630
type: string
1631+
sizeGiB:
1632+
description: SizeGiB is the size of the block
1633+
device in gibibytes (GiB).
1634+
type: integer
1635+
storage:
1636+
description: Storage specifies the storage type
1637+
of the block device and additional storage
1638+
options.
1639+
properties:
1640+
type:
1641+
description: Type is the type of block device
1642+
to create. This can be either "Volume"
1643+
or "Local".
1644+
type: string
1645+
volume:
1646+
description: Volume contains additional
1647+
storage options for a volume block device.
1648+
properties:
1649+
availabilityZone:
1650+
description: AvailabilityZone is the
1651+
volume availability zone to create
1652+
the volume in. If omitted, the availability
1653+
zone of the server will be used. The
1654+
availability zone must NOT contain
1655+
spaces otherwise it will lead to volume
1656+
that belongs to this availability
1657+
zone register failure, see kubernetes/cloud-provider-openstack#1379
1658+
for further information.
1659+
type: string
1660+
type:
1661+
description: Type is the Cinder volume
1662+
type of the volume. If omitted, the
1663+
default Cinder volume type that is
1664+
configured in the OpenStack cloud
1665+
will be used.
1666+
type: string
1667+
type: object
1668+
required:
1669+
- type
1670+
type: object
16391671
required:
1640-
- diskSize
16411672
- name
1673+
- sizeGiB
1674+
- storage
16421675
type: object
16431676
type: array
16441677
x-kubernetes-list-map-keys:

0 commit comments

Comments
 (0)