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

hcp: reject iteration with diff template types #12132

Merged
merged 3 commits into from
Dec 7, 2022

Conversation

lbajolet-hashicorp
Copy link
Contributor

Right now if someone starts an HCP build, which doesn't end with full completion for any reason (cancellation, only/except, etc.), and starts building the same iteration again with a template that is different in its type (HCL2/JSON), we let them do, which makes for some unpredictable behaviour, as the naming scheme for the two types are different.

To prevent this issue, we check-in the template type when we create the iteration, and reject any subsequent builds with a template that is of a different type.

@lbajolet-hashicorp lbajolet-hashicorp requested a review from a team as a code owner November 25, 2022 22:12
@lbajolet-hashicorp lbajolet-hashicorp changed the title hcp: reject iteration with diff template types [WIP] hcp: reject iteration with diff template types Nov 25, 2022
@lbajolet-hashicorp
Copy link
Contributor Author

This cannot be merged as-is, as it needs an SDK update before we can consider that.

@lbajolet-hashicorp lbajolet-hashicorp force-pushed the write_template_type_hcp branch 4 times, most recently from 0dc642c to 9b9c61e Compare November 28, 2022 21:21
Copy link
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.

This looks good to me. I tested with a locally generated SDK. Once the SDK is released we can get this merged in. I left a question about storing the template type on the Iteration type. Doesn't seem like it is need at this moment.

@@ -318,12 +322,12 @@ func (b *Bucket) createIteration() (*models.HashicorpCloudPackerIteration, error
return createIterationResp.Payload.Iteration, nil
}

func (b *Bucket) initializeIteration(ctx context.Context) error {
func (b *Bucket) initializeIteration(ctx context.Context, templateType models.HashicorpCloudPackerIterationTemplateType) error {
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we want to persist the templateType on the actual iteration, like we do the Fingerprint and other related info?

@nywilken
Copy link
Contributor

In the Packer change log we need to call out the tracking of template types in HCP Packer registry as the PR title is more on rejecting the continuation of builds using a different template type.

@lbajolet-hashicorp
Copy link
Contributor Author

In the Packer change log we need to call out the tracking of template types in HCP Packer registry as the PR title is more on rejecting the continuation of builds using a different template type.

Yes, this should be highlighted in the changelog. In addition to this, we could also change the title of the PR if you prefer to highlight this change?
I left the default value for the title (and description) of the PR, i.e. the initial commit's title/message. This can be updated to give more context and information on the change itself

The grpc_gateway v2 changes had some repercussions in the payloads of
the API calls, making the current code non-functional against the latest
SDK.

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
In order to ensure users keep the same templates between two packer
invocations for a single iteration, we start tracking the type of
template used when building images.
As a follow-up to tracking the template type for an iteration, we
actively check that it remains consistent between two invocations of
packer, and reject the update if it is not the case.
@lbajolet-hashicorp lbajolet-hashicorp changed the title [WIP] hcp: reject iteration with diff template types hcp: reject iteration with diff template types Dec 7, 2022
@lbajolet-hashicorp lbajolet-hashicorp merged commit 4846301 into main Dec 7, 2022
@lbajolet-hashicorp lbajolet-hashicorp deleted the write_template_type_hcp branch December 7, 2022 21:18
@nywilken nywilken added this to the 1.8.5 milestone Dec 12, 2022
@github-actions
Copy link

I'm going to lock this pull request because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues.
If you have found a problem that seems related to this change, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jan 13, 2023
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.

None yet

2 participants