Skip to content

Commit

Permalink
Merge pull request #275 from shiftstack/bd
Browse files Browse the repository at this point in the history
UPSTREAM 1696: Add ephemeral storage support to the AdditionalBlockDevices
  • Loading branch information
openshift-ci[bot] committed Oct 30, 2023
2 parents 084aab5 + e36505b commit 6fdfd82
Show file tree
Hide file tree
Showing 22 changed files with 1,035 additions and 197 deletions.
3 changes: 3 additions & 0 deletions .golangci.yml
Expand Up @@ -126,6 +126,9 @@ linters-settings:
- pkg: sigs.k8s.io/cluster-api/controlplane/kubeadm/api/v1beta1
alias: controlplanev1

nolintlint:
# https://github.com/golangci/golangci-lint/issues/3228
allow-unused: true
staticcheck:
go: "1.17"
stylecheck:
Expand Down
4 changes: 4 additions & 0 deletions api/v1alpha5/conversion.go
Expand Up @@ -433,3 +433,7 @@ func Convert_v1alpha5_OpenStackClusterStatus_To_v1alpha7_OpenStackClusterStatus(

return nil
}

func Convert_v1alpha7_OpenStackMachineSpec_To_v1alpha5_OpenStackMachineSpec(in *infrav1.OpenStackMachineSpec, out *OpenStackMachineSpec, s conversion.Scope) error {
return autoConvert_v1alpha7_OpenStackMachineSpec_To_v1alpha5_OpenStackMachineSpec(in, out, s)
}
16 changes: 6 additions & 10 deletions api/v1alpha5/zz_generated.conversion.go

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

11 changes: 7 additions & 4 deletions api/v1alpha6/conversion.go
Expand Up @@ -60,13 +60,12 @@ func restorev1alpha7MachineSpec(previous *infrav1.OpenStackMachineSpec, dst *inf
// PropagateUplinkStatus has been added in v1alpha7.
// We restore the whole Ports since they are anyway immutable.
dst.Ports = previous.Ports
dst.AdditionalBlockDevices = previous.AdditionalBlockDevices
}

func restorev1alpha7Bastion(previous **infrav1.Bastion, dst **infrav1.Bastion) {
// PropagateUplinkStatus has been added in v1alpha7.
// We restore the whole Ports since they are anyway immutable.
if *previous != nil && (*previous).Instance.Ports != nil && *dst != nil && (*dst).Instance.Ports != nil {
(*dst).Instance.Ports = (*previous).Instance.Ports
if *previous != nil && *dst != nil {
restorev1alpha7MachineSpec(&(*previous).Instance, &(*dst).Instance)
}
}

Expand Down Expand Up @@ -646,3 +645,7 @@ func Convert_v1alpha6_OpenStackClusterStatus_To_v1alpha7_OpenStackClusterStatus(

return nil
}

func Convert_v1alpha7_OpenStackMachineSpec_To_v1alpha6_OpenStackMachineSpec(in *infrav1.OpenStackMachineSpec, out *OpenStackMachineSpec, s apiconversion.Scope) error {
return autoConvert_v1alpha7_OpenStackMachineSpec_To_v1alpha6_OpenStackMachineSpec(in, out, s)
}
16 changes: 6 additions & 10 deletions api/v1alpha6/zz_generated.conversion.go

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

6 changes: 6 additions & 0 deletions api/v1alpha7/openstackmachine_types.go
Expand Up @@ -84,6 +84,12 @@ 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
// +listType=map
// +listMapKey=name
// +optional
AdditionalBlockDevices []AdditionalBlockDevice `json:"additionalBlockDevices,omitempty"`

// The server group to assign the machine to
ServerGroupID string `json:"serverGroupID,omitempty"`

Expand Down
8 changes: 8 additions & 0 deletions api/v1alpha7/openstackmachine_webhook.go
Expand Up @@ -62,6 +62,14 @@ func (r *OpenStackMachine) ValidateCreate() (admission.Warnings, error) {
allErrs = append(allErrs, field.Forbidden(field.NewPath("spec", "identityRef", "kind"), "must be a Secret"))
}

if r.Spec.RootVolume != nil && r.Spec.AdditionalBlockDevices != nil {
for _, device := range r.Spec.AdditionalBlockDevices {
if device.Name == "root" {
allErrs = append(allErrs, field.Forbidden(field.NewPath("spec", "additionalBlockDevices"), "cannot contain a device named \"root\" when rootVolume is set"))
}
}
}

return aggregateObjErrors(r.GroupVersionKind().GroupKind(), r.Name, allErrs)
}

Expand Down
63 changes: 63 additions & 0 deletions api/v1alpha7/types.go
Expand Up @@ -163,6 +163,69 @@ type RootVolume struct {
AvailabilityZone string `json:"availabilityZone,omitempty"`
}

// BlockDeviceStorage is the storage type of a block device to create and
// contains additional storage options.
// +union
//
//nolint:godot
type BlockDeviceStorage struct {
// Type is the type of block device to create.
// This can be either "Volume" or "Local".
// +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.
// +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.
// +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.
Name string `json:"name"`

// SizeGiB is the size of the block device in gibibytes (GiB).
SizeGiB int `json:"sizeGiB"`

// Storage specifies the storage type of the block device and
// additional storage options.
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
58 changes: 58 additions & 0 deletions api/v1alpha7/zz_generated.deepcopy.go

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

Expand Up @@ -3770,6 +3770,67 @@ spec:
instance:
description: Instance for the bastion itself
properties:
additionalBlockDevices:
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:
name:
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).
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".
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.
type: string
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.
type: string
type: object
required:
- type
type: object
required:
- name
- sizeGiB
- storage
type: object
type: array
x-kubernetes-list-map-keys:
- name
x-kubernetes-list-type: map
cloudName:
description: The name of the cloud to use from the clouds
secret
Expand Down

0 comments on commit 6fdfd82

Please sign in to comment.