Skip to content

Add pre-validate step to check if the image name has already been used#106

Closed
shengxpa wants to merge 1 commit intohashicorp:mainfrom
shengxpa:add-pre-validate-step
Closed

Add pre-validate step to check if the image name has already been used#106
shengxpa wants to merge 1 commit intohashicorp:mainfrom
shengxpa:add-pre-validate-step

Conversation

@shengxpa
Copy link
Copy Markdown

@shengxpa shengxpa commented Jul 19, 2023

For the packer image build on the Openstack platform, there is a lack of a pre-validate step for the image name like in the packer-plugin-amazon plugin, resulting in the name of the built image often being repeated like this:
image
It always causes some confusion when using image.

In this PR, a pre-validate step has been added to check if the image name has already been used. If the image name has already been used, an error will be output. "packer_force" parameter can be used to skip the pre-validate step when it is set to 'true' like the logic of packer-plugin-amazon plugin.

@shengxpa shengxpa requested a review from a team as a code owner July 19, 2023 05:41
@hashicorp-cla
Copy link
Copy Markdown

hashicorp-cla commented Jul 19, 2023

CLA assistant check
All committers have signed the CLA.

@shengxpa
Copy link
Copy Markdown
Author

Anyone can help have a review?

@shengxpa
Copy link
Copy Markdown
Author

shengxpa commented Aug 7, 2023

@nywilken Could you help have a review?

Copy link
Copy Markdown
Contributor

@nywilken nywilken left a comment

Choose a reason for hiding this comment

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

Thanks for opening up this change. Our focus has been on a few plugin changes so I do apologize for the delayed review.

I took a quick look at the OpenStack glance image creation API to see why this wasn't implemented previously. I found that the API allows for this and OpenStack itself does not consider it an issue because the ids are unique. This leaves me to think that adding this change, while logical, may break expectation for users.

In addition to the prevalidation step the use of -force generally implies to force a build when artifacts from a previous build prevent a build from running. This is not really the case here seeing as OpenStack does allow images to have the same name.

Have you considered using a timestamp when generating the image name?

The use of the timestamp function with Packer templates is a common practice for avoiding duplicate image names. It is a little tricky seeing as OpenStack does allow it. If you think this feature would benefit users over setting a timestamp then I would suggest adding an optional attribute to change the default behavior of the glance API such as

prevent_duplicate_image_name (boolean) - Set to true to check that no existing image has the same image name. If the image name is already in use the builder will exit with an error. Defaults to false

Please let me know what you think?

@nywilken
Copy link
Copy Markdown
Contributor

Closing since there have been no updates to the issue. If you believe this is still an issue please or should be a feature please open an issue first so that other users can vote on and provide insight into the usage. Thanks!

@nywilken nywilken closed this Oct 10, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants