From fe500284d13b7bf7a029142bb186094d6a542a08 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Andr=C3=A9?= Date: Fri, 6 Oct 2023 14:00:38 +0200 Subject: [PATCH] Fix tests --- api/v1alpha7/types.go | 8 ++++---- ...infrastructure.cluster.x-k8s.io_openstackclusters.yaml | 7 ++++--- ...ucture.cluster.x-k8s.io_openstackclustertemplates.yaml | 8 +++++--- ...infrastructure.cluster.x-k8s.io_openstackmachines.yaml | 6 ++++-- ...ucture.cluster.x-k8s.io_openstackmachinetemplates.yaml | 7 ++++--- pkg/cloud/services/compute/instance.go | 4 +--- pkg/cloud/services/compute/instance_test.go | 8 ++++++++ .../multi-az/patch-machine-template-control-plane.yaml | 1 + .../kustomize/multi-az/patch-machine-template-worker.yaml | 1 + 9 files changed, 32 insertions(+), 18 deletions(-) diff --git a/api/v1alpha7/types.go b/api/v1alpha7/types.go index 8c413ddbb2..73ae0fcbd4 100644 --- a/api/v1alpha7/types.go +++ b/api/v1alpha7/types.go @@ -178,10 +178,10 @@ type AdditionalBlockDevice struct { // 2. Add a new field for swap partitions // 3. Don't add fields, the block device will be blank and can't be used for swap partitions. - // 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. - // Required if SourceType is "volume" - Name string `json:"name,omitempty"` + // Name of the block device in the context of a machine. + // It will be combined with the machine name to make the actual cinder + // volume name, and will be used for tagging the block device. + Name string `json:"name"` // Size is the size in GB of the block device. Size int `json:"diskSize"` // VolumeType is the volume type of the volume. diff --git a/config/crd/bases/infrastructure.cluster.x-k8s.io_openstackclusters.yaml b/config/crd/bases/infrastructure.cluster.x-k8s.io_openstackclusters.yaml index 1f44967127..132b109781 100644 --- a/config/crd/bases/infrastructure.cluster.x-k8s.io_openstackclusters.yaml +++ b/config/crd/bases/infrastructure.cluster.x-k8s.io_openstackclusters.yaml @@ -3791,10 +3791,10 @@ spec: description: Size is the size in GB of the block device. type: integer name: - description: Name of the Cinder volume in the context + description: Name of the block device in the context of a machine. It will be combined with the machine - name to make the actual volume name. Required if SourceType - is "volume" + name to make the actual cinder volume name, and will + be used for tagging the block device. type: string volumeType: description: VolumeType is the volume type of the volume. @@ -3803,6 +3803,7 @@ spec: required: - blockDeviceType - diskSize + - name type: object type: array x-kubernetes-list-map-keys: diff --git a/config/crd/bases/infrastructure.cluster.x-k8s.io_openstackclustertemplates.yaml b/config/crd/bases/infrastructure.cluster.x-k8s.io_openstackclustertemplates.yaml index f29dcc0e3e..810f4c89b1 100644 --- a/config/crd/bases/infrastructure.cluster.x-k8s.io_openstackclustertemplates.yaml +++ b/config/crd/bases/infrastructure.cluster.x-k8s.io_openstackclustertemplates.yaml @@ -1635,10 +1635,11 @@ spec: device. type: integer name: - description: Name of the Cinder volume in the + description: Name of the block device in the context of a machine. It will be combined - with the machine name to make the actual volume - name. Required if SourceType is "volume" + with the machine name to make the actual cinder + volume name, and will be used for tagging + the block device. type: string volumeType: description: VolumeType is the volume type of @@ -1648,6 +1649,7 @@ spec: required: - blockDeviceType - diskSize + - name type: object type: array x-kubernetes-list-map-keys: diff --git a/config/crd/bases/infrastructure.cluster.x-k8s.io_openstackmachines.yaml b/config/crd/bases/infrastructure.cluster.x-k8s.io_openstackmachines.yaml index 52b5d76085..25e38b9015 100644 --- a/config/crd/bases/infrastructure.cluster.x-k8s.io_openstackmachines.yaml +++ b/config/crd/bases/infrastructure.cluster.x-k8s.io_openstackmachines.yaml @@ -1180,9 +1180,10 @@ spec: description: Size is the size in GB of the block device. type: integer name: - description: Name of the Cinder volume in the context of a machine. + description: Name of the block device in the context of a machine. It will be combined with the machine name to make the actual - volume name. Required if SourceType is "volume" + cinder volume name, and will be used for tagging the block + device. type: string volumeType: description: VolumeType is the volume type of the volume. If @@ -1191,6 +1192,7 @@ spec: required: - blockDeviceType - diskSize + - name type: object type: array x-kubernetes-list-map-keys: diff --git a/config/crd/bases/infrastructure.cluster.x-k8s.io_openstackmachinetemplates.yaml b/config/crd/bases/infrastructure.cluster.x-k8s.io_openstackmachinetemplates.yaml index e54fa89f25..6a3f2ce2ef 100644 --- a/config/crd/bases/infrastructure.cluster.x-k8s.io_openstackmachinetemplates.yaml +++ b/config/crd/bases/infrastructure.cluster.x-k8s.io_openstackmachinetemplates.yaml @@ -979,10 +979,10 @@ spec: description: Size is the size in GB of the block device. type: integer name: - description: Name of the Cinder volume in the context + description: Name of the block device in the context of a machine. It will be combined with the machine - name to make the actual volume name. Required if SourceType - is "volume" + name to make the actual cinder volume name, and will + be used for tagging the block device. type: string volumeType: description: VolumeType is the volume type of the volume. @@ -991,6 +991,7 @@ spec: required: - blockDeviceType - diskSize + - name type: object type: array x-kubernetes-list-map-keys: diff --git a/pkg/cloud/services/compute/instance.go b/pkg/cloud/services/compute/instance.go index 395de1f726..d65c8d9be3 100644 --- a/pkg/cloud/services/compute/instance.go +++ b/pkg/cloud/services/compute/instance.go @@ -494,7 +494,6 @@ func (s *Service) getBlockDevices(eventObject runtime.Object, instanceSpec *Inst var bdUUID string var sourceType bootfromvolume.SourceType var destinationType bootfromvolume.DestinationType - var bdSize int if blockDeviceSpec.BlockDeviceType == "volume" { blockDevice, err := s.getOrCreateVolumeBuilder(eventObject, instanceSpec, blockDeviceSpec, "", fmt.Sprintf("Additional block device for %s", instanceSpec.Name)) if err != nil { @@ -506,7 +505,6 @@ func (s *Service) getBlockDevices(eventObject runtime.Object, instanceSpec *Inst } else if blockDeviceSpec.BlockDeviceType == "local" { sourceType = bootfromvolume.SourceBlank destinationType = bootfromvolume.DestinationLocal - bdSize = blockDeviceSpec.Size } else { return []bootfromvolume.BlockDevice{}, fmt.Errorf("invalid block device type %s", blockDeviceSpec.BlockDeviceType) } @@ -517,7 +515,7 @@ func (s *Service) getBlockDevices(eventObject runtime.Object, instanceSpec *Inst UUID: bdUUID, BootIndex: -1, DeleteOnTermination: true, - VolumeSize: bdSize, + VolumeSize: blockDeviceSpec.Size, Tag: blockDeviceSpec.Name, }) } diff --git a/pkg/cloud/services/compute/instance_test.go b/pkg/cloud/services/compute/instance_test.go index c5481267ea..74788bed3e 100644 --- a/pkg/cloud/services/compute/instance_test.go +++ b/pkg/cloud/services/compute/instance_test.go @@ -665,6 +665,7 @@ func TestService_ReconcileInstance(t *testing.T) { }, { BlockDeviceType: "local", + Name: "local-device", Size: 10, }, } @@ -715,6 +716,8 @@ func TestService_ReconcileInstance(t *testing.T) { "boot_index": float64(-1), "delete_on_termination": true, "destination_type": "volume", + "volume_size": float64(50), + "tag": "etcd", }, { "source_type": "blank", @@ -722,6 +725,7 @@ func TestService_ReconcileInstance(t *testing.T) { "boot_index": float64(-1), "delete_on_termination": true, "volume_size": float64(10), + "tag": "local-device", }, } expectCreateServer(r.compute, createMap, false) @@ -777,6 +781,8 @@ func TestService_ReconcileInstance(t *testing.T) { "boot_index": float64(-1), "delete_on_termination": true, "destination_type": "volume", + "volume_size": float64(50), + "tag": "etcd", }, } expectCreateServer(r.compute, createMap, false) @@ -833,6 +839,8 @@ func TestService_ReconcileInstance(t *testing.T) { "boot_index": float64(-1), "delete_on_termination": true, "destination_type": "volume", + "volume_size": float64(50), + "tag": "etcd", }, } expectCreateServer(r.compute, createMap, false) diff --git a/test/e2e/data/kustomize/multi-az/patch-machine-template-control-plane.yaml b/test/e2e/data/kustomize/multi-az/patch-machine-template-control-plane.yaml index a7e2fab4db..70c777c1f5 100644 --- a/test/e2e/data/kustomize/multi-az/patch-machine-template-control-plane.yaml +++ b/test/e2e/data/kustomize/multi-az/patch-machine-template-control-plane.yaml @@ -11,3 +11,4 @@ name: extravol - diskSize: 1 blockDeviceType: local + name: etcd diff --git a/test/e2e/data/kustomize/multi-az/patch-machine-template-worker.yaml b/test/e2e/data/kustomize/multi-az/patch-machine-template-worker.yaml index 41f5a6ea12..6ac8e78e10 100644 --- a/test/e2e/data/kustomize/multi-az/patch-machine-template-worker.yaml +++ b/test/e2e/data/kustomize/multi-az/patch-machine-template-worker.yaml @@ -15,3 +15,4 @@ availabilityZone: ${OPENSTACK_FAILURE_DOMAIN} - diskSize: 1 blockDeviceType: local + name: etcd