Skip to content
This repository has been archived by the owner on May 7, 2021. It is now read-only.

platform/aws: add Name tag to created images #856

Merged
merged 2 commits into from
May 23, 2018

Conversation

jlebon
Copy link
Member

@jlebon jlebon commented May 22, 2018

When creating AMIs, in addition to setting an AMI name, let's also add
an explicit Name tag with the same value. This can make it more
convenient to search for AMIs when filtering by multiple tags.

@jlebon
Copy link
Member Author

jlebon commented May 22, 2018

/cc @ashcrow

Copy link
Member

@ashcrow ashcrow left a comment

Choose a reason for hiding this comment

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

This looks like it will do for our needs. In the future we may want to add general tag support, but this works for now!

@ashcrow
Copy link
Member

ashcrow commented May 22, 2018

/cc @bgilbert

@@ -375,8 +375,15 @@ func (a *API) createImage(params *ec2.RegisterImageInput) (string, error) {
res, err := a.ec2.RegisterImage(params)

if err == nil {
err = a.CreateTags([]string{*res.ImageId}, map[string]string{
Copy link
Contributor

Choose a reason for hiding this comment

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

Is there any chance that a SIGTERM could leave the image existing but not having the new Name tag?

Would it potentially be worthwhile to validate the tag exists on the found image in the next block and add them if they don't exist?

cc @bgilbert

Copy link
Member Author

Choose a reason for hiding this comment

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

I'm open to that, though note we don't do this currently for pre-existing snapshots either.

Copy link
Contributor

Choose a reason for hiding this comment

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

I think it does for snapshots. The code that tags a snapshot runs unconditionally, even if the snapshot is "done" / "complete"

// post-process
err := a.CreateTags([]string{snapshotID}, map[string]string{
"Name": imageName,
})
if err != nil {
return nil, fmt.Errorf("couldn't create tags: %v", err)
}

Can you reference where it doesn't pick up tagging given a poorly timed SIGTERM?

Copy link
Member Author

Choose a reason for hiding this comment

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

Right, I was initially looking at how FindSnapshot returns early (and thus skips the post-processing) if we don't fall back to searching for pre-existing import tasks:

if len(snapshotRes.Snapshots) == 1 {
snapshotID := *snapshotRes.Snapshots[0].SnapshotId
plog.Infof("found existing snapshot %v", snapshotID)
return &Snapshot{
SnapshotID: snapshotID,
}, nil
}

But actually, we'd only get there if the Name tag was already correct judging by the filters. So I think you're right, we do implicitly do this for snapshots just from how we search for them in the first place. If it wasn't tagged, then the import task fallback will pick it up and complete it (assuming the task wasn't GC'ed already).

Copy link
Contributor

Choose a reason for hiding this comment

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

Yup, reading it again it's certainly non-obvious that FindSnapshot works that way.

I think it's up to you whether we make this idempotent/resumable or not.
As long as there's only async cleanup tasks that rely on the name tag, not plume itself, I don't think it really matters that much.

Copy link
Contributor

Choose a reason for hiding this comment

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

This code runs in the plume prerelease (i.e., CL release) path, even though CL releases don't actually need the tag. Since the rest of the code in that path tries pretty hard to be idempotent, I'd be in favor of also doing so here if possible.

Copy link
Member Author

Choose a reason for hiding this comment

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

I updated this to always tag pre-existing images! ⬇️

@euank
Copy link
Contributor

euank commented May 22, 2018

We've gone down the path of tagging AMIs before. Note that these tags are not visible across accounts, which makes them have limited utility.
xref coreos/bugs#111 (comment)

Assuming you still want this with the above caveat, this LGTM

@ashcrow
Copy link
Member

ashcrow commented May 22, 2018

@euank thanks for that ... good to know. The context around using tags is to allow our image pruning jobs to find the AMIs.

Reference: openshift/os#44

No functional changes, just rework a bit how the code flows when errors
occur. Prep for next patch.
When creating AMIs, in addition to setting an AMI name, let's also add
an explicit `Name` tag with the same value. This can make it more
convenient to search for AMIs when filtering by multiple tags.
@jlebon
Copy link
Member Author

jlebon commented May 22, 2018

Note that unlike the previous version, I haven't actually tested this. It seems mostly straightforward, though I can test it in a while.

Copy link
Contributor

@bgilbert bgilbert left a comment

Choose a reason for hiding this comment

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

LGTM. Please test and then I'll merge.

@jlebon
Copy link
Member Author

jlebon commented May 23, 2018

Tested working!

@bgilbert bgilbert merged commit 222e5f9 into coreos:master May 23, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants