Skip to content
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

aws: allow the user to customize their AMI name #3886

Closed
wants to merge 1 commit into from

Conversation

lavocatt
Copy link
Contributor

@lavocatt lavocatt commented Jan 9, 2024

In the frontend a new field is allowing user to setup customized names
for their images (see
osbuild/image-builder-frontend#1136).

To allow the customization to effectively take place, this commit is
slightly changing how EC2 images are activated.

The Name tag and the AMI Name are not always sharing the same value
exactly anymore. If the user provides a SnaphsotName, the raw value is
set in the Name tag and the AMI name is set to $SnaphsotName-$UUID
(to make it unique).

This means that the Name tag can't be used anymore for the maintenance
tooling. The tooling will have to use the new Build-By tag to identify
the images built by osbuild-composer.

Example
The request:
image

Ended up producing this AMI:
image

This pull request includes:

  • adequate testing for the new functionality or fixed issue
  • adequate documentation informing people about the change such as

https://issues.redhat.com/browse/HMS-2959

@lavocatt
Copy link
Contributor Author

lavocatt commented Jan 9, 2024

What kind of test would be adequate for this functionality do you think? I could change the aws test to add a snapshotName in the request and see if I can get access to the proper name after upload? Wdyt?

@bcl
Copy link
Contributor

bcl commented Jan 10, 2024

What benefit is there in using a new UUID to make the AMI Name unique? Why not use the UUID of the image so that no matter which field you look at it is clear (ha!) that it is the same thing?

@lavocatt
Copy link
Contributor Author

lavocatt commented Jan 10, 2024

What benefit is there in using a new UUID to make the AMI Name unique? Why not use the UUID of the image so that no matter which field you look at it is clear (ha!) that it is the same thing?

Thanks for this input, I hadn't thought about it this way. I'll make the two UUIDs the same.

@lavocatt
Copy link
Contributor Author

lavocatt commented Jan 10, 2024

One thing I'm noticing is that the AMI Id seems to reference the content of the Name tag too, and I don't know why. Or is it the name of the snapshot in the parenthesis?

image

internal/cloud/awscloud/awscloud.go Outdated Show resolved Hide resolved
internal/cloud/awscloud/awscloud.go Outdated Show resolved Hide resolved
internal/cloudapi/v2/imagerequest.go Outdated Show resolved Hide resolved
@lavocatt
Copy link
Contributor Author

lavocatt commented Jan 12, 2024

The tests are failing and I'm starting to understand what's happening.

We decided to reuse the snapshot_name because we thought that this field in the request wasn't really used anywhere. But it turns out that this field is being used in the tests:

"image_request": {
"architecture": "$ARCH",
"image_type": "${IMAGE_TYPE}",
"repositories": $(jq ".\"$ARCH\"" /usr/share/tests/osbuild-composer/repositories/"$DISTRO".json),
"upload_options": {
"region": "${AWS_REGION}",
"snapshot_name": "${AWS_SNAPSHOT_NAME}",
"share_with_accounts": ["${AWS_API_TEST_SHARE_ACCOUNT}"]
}
}
}

function verify() {
$AWS_CMD ec2 describe-images \
--owners self \
--filters Name=name,Values="$AWS_SNAPSHOT_NAME" \
> "$WORKDIR/ami.json"
AMI_IMAGE_ID=$(jq -r '.Images[].ImageId' "$WORKDIR/ami.json")
AWS_SNAPSHOT_ID=$(jq -r '.Images[].BlockDeviceMappings[].Ebs.SnapshotId' "$WORKDIR/ami.json")

The test suite is using this field to recover the ID of the image that was just built. Adding a UUID to the string broke that logic. There's an easy fix which implies to simply change how the test suite is finding the image by updating the filter from being equal to containing. For that I can just add a * to the filter.

Here's a few opened questions:

  • Since there's no way to name a snapshot, maybe the snapshot_name field should be renamed to something else.
  • This field was originally made to have an easy way to find an image. Should we keep the functionality as it was originally (without changing the filter)?

I think it's reasonable to could keep the broader filter (the one with a *). But I feel like renaming the field would be a nice addition to this PR. Maybe something like CustomName instead of SnaphsotName ?

What do you think?

Copy link
Contributor

@bcl bcl left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The consistent UUID part of things looks good.

internal/cloud/awscloud/awscloud.go Outdated Show resolved Hide resolved
internal/cloudapi/v2/imagerequest.go Outdated Show resolved Hide resolved
@lavocatt lavocatt force-pushed the hms-2959 branch 8 times, most recently from 7dba54d to 4d6188e Compare January 23, 2024 11:25
@lavocatt lavocatt force-pushed the hms-2959 branch 2 times, most recently from 0d9c3b2 to bad6068 Compare February 2, 2024 13:46
@lavocatt lavocatt force-pushed the hms-2959 branch 2 times, most recently from 3454043 to 88c82f2 Compare February 12, 2024 09:03
In the frontend a new field is allowing user to setup customized names
for their images (see
osbuild/image-builder-frontend#1136).

To allow the customization to effectively take place, this commit is
slightly changing how EC2 images are activated.

The Name tag and the AMI Name are not always sharing the same value
exactly anymore. If the user provides a SnaphsotName, the raw value is
set in the `Name` tag and the AMI name is set to `$SnaphsotName-$UUID`
(to make it unique).

This means that the `Name` tag can't be used anymore for the maintenance
tooling. The tooling will have to use the new Build-By tag to identify
the images built by osbuild-composer.
Copy link
Member

@thozza thozza left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The change looks reasonable, but I'm wondering if we can't instead extend the maintenance service to use additional / different tag for filtering images? This would allow us to use the same value for the Name tag and as image name and would reduce the complexity and required changes in osbuild-composer a lot. 🤔

Comment on lines -50 to -52
// For service maintenance, images are discovered by the "Name:composer-api-*"
// tag filter. Currently all image names in the service are generated, so they're
// guaranteed to be unique as well. If users are ever allowed to name their images,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that part of this comment should be preserved. Especially the information that the maintenance service uses "Name:composer-api-*" to discover images is very useful.

Comment on lines +17 to +18
// Optional tag value if not provided will default to the ImageName's value.
TagName string `json:"tag_name,omitempty"`
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tiny nitpick: I would suggest to rename this to NameTag instead. The TagName indicates (at least to me) that it is a name (a.k.a. the key) of a tag, not a value of a tag named Name.

Comment on lines +344 to +346
{
Key: aws.String("Build-by"),
Value: aws.String("osbuild-composer"),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm wondering if the maintenance service could not leverage this new tag instead of the image name for filtering? This would allow us to keep the image name and the value of the Name tag consistent. Since you are appending an UUID to the user-provided image name, it will be unique and usable as the single image name.

@croissanne WDYT about using this new tag for the maintenance service?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yup!

@croissanne
Copy link
Member

The change looks reasonable, but I'm wondering if we can't instead extend the maintenance service to use additional / different tag for filtering images? This would allow us to use the same value for the Name tag and as image name and would reduce the complexity and required changes in osbuild-composer a lot. 🤔

I think that's already implied in the description. Might be useful to do this in the same PR though, would just require a tiny change.

Copy link

This PR is stale because it has been open 30 days with no activity. Remove "Stale" label or comment or this will be closed in 7 days.

@github-actions github-actions bot added the Stale label Mar 24, 2024
Copy link

This PR was closed because it has been stalled for 30+7 days with no activity.

@github-actions github-actions bot closed this Mar 31, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants