-
Notifications
You must be signed in to change notification settings - Fork 14
Add support for setting volume size and type #76
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -8,6 +8,7 @@ import ( | |
| "sync/atomic" | ||
| "time" | ||
|
|
||
| "github.com/gophercloud/gophercloud/v2/openstack/blockstorage/v2/volumes" | ||
| "github.com/gophercloud/gophercloud/v2/openstack/compute/v2/servers" | ||
| "github.com/hashicorp/go-hclog" | ||
| "github.com/jinzhu/copier" | ||
|
|
@@ -29,6 +30,8 @@ type InstanceGroup struct { | |
| UseIgnition bool `json:"use_ignition"` // Configure keys via Ignition (Fedora CoreOS / Flatcar) | ||
| BootTimeS string `json:"boot_time"` // optional: wait some time before report machine as available | ||
| BootTime time.Duration | ||
| VolumeType string `json:"volume_type"` | ||
| VolumeSize int `json:"volume_size"` | ||
|
|
||
| client openstackclient.Client | ||
| settings provider.Settings | ||
|
|
@@ -242,6 +245,34 @@ func (g *InstanceGroup) createInstance(ctx context.Context) (string, error) { | |
| } | ||
| } | ||
|
|
||
| if g.VolumeSize != 0 && g.VolumeType != "" { | ||
| volumeOpts := volumes.CreateOpts{ | ||
| Name: spec.Name, | ||
| Size: g.VolumeSize, | ||
| VolumeType: g.VolumeType, | ||
| ImageID: spec.ImageRef, | ||
| } | ||
| volume, err := g.client.CreateVolume(ctx, volumeOpts) | ||
| if err != nil { | ||
| return "", err | ||
| } | ||
|
|
||
| err = g.client.WaitForVolumeStatus(ctx, volume.ID, "available") | ||
| if err != nil { | ||
| return "", err | ||
| } | ||
|
|
||
|
Comment on lines
+248
to
+264
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would remove this part as well as reverting all changes in the servers.BlockDevice{
BootIndex: 0,
DeleteOnTermination: true,
DestinationType: servers.DestinationVolume,
SourceType: servers.SourceImage,
UUID: spec.ImageRef,
VolumeSize: g.VolumeSize,
VolumeType: g.VolumeType,
} |
||
| spec.BlockDevice = []servers.BlockDevice{ | ||
| { | ||
| BootIndex: 0, | ||
| DeleteOnTermination: true, | ||
| DestinationType: servers.DestinationVolume, | ||
| SourceType: servers.SourceVolume, | ||
| UUID: volume.ID, | ||
| }, | ||
| } | ||
| } | ||
|
Comment on lines
+265
to
+274
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I do not think blindly overwriting the |
||
|
|
||
| if spec.ImageName != "" { | ||
| imageRef, imgProps, err := g.client.GetImageByName(ctx, spec.ImageName) | ||
| if err != nil { | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
spec.ImageRefis possibly not known at this point and will only be available after this block ending with line 286.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When this can be implemented, I also need this feature for our openstack project.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
FYI, you don't need to wait for this feature to use volume-backed instances, you can include
block_device_mapping_v2in the server_spec already:https://gitlab.com/alasca.cloud/infra/configuration/-/blob/86f078fb4dfa5db5da8111fa202abd56c814e5e0/gitlab-runner-managers/grm-yaook-ephemeral.tpl.toml#L54
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks — we're already using block_device_mapping_v2 in server_spec, similar to your example. The blocker for us isn't enabling volume-backed boot; it's image rotation without redeploying the runner managers.
Our setup:
Packer builds a new worker image every two weeks under a stable name (ubuntu-2404-glrunner), archiving the previous one so only one active image keeps that name.
Terraform resolves the image UUID at controller deploy time and bakes it into /etc/gitlab-runner/config.toml in block_device_mapping_v2.uuid.
We also set image_name in server_spec, which the fleeting plugin resolves to imageRef on each worker create.
The problem is that with destination_type = "volume", Nova boots from the BDM uuid, not from imageRef. The plugin's image_name resolution only updates imageRef — it does not update block_device_mapping_v2[].uuid. So after a packer run, Glance has a new image UUID under the same name, but controllers still have the old UUID hardcoded in BDM, and new workers keep booting from the old image.
The only workaround that works today without a plugin change would be redeploying controllers after each packer build — but that's not something we'd want to adopt as a process. It would only work because Terraform re-runs the image lookup at deploy time and re-bakes the new UUID into config.toml. It's operational overhead on a two-week cadence, not a real solution to the problem.
What we actually need is for the plugin to resolve image_name into BDM UUIDs at worker create time (same as it already does for imageRef), so managers don't need to be redeployed just to pick up a new image.