-
Notifications
You must be signed in to change notification settings - Fork 3.3k
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: give a proper error when using conflicting build name #13300
base: main
Are you sure you want to change the base?
Conversation
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.
Overall this looks good to me, I think it maintains existing compatibility, but to be sure, have you run HPATS on those?
I left a couple comments, but nothing blocking, I'll let you address those and come back for another round of review later.
func TestRegisterAllBuilds(t *testing.T) { | ||
cases := map[string]struct { | ||
expectedBuilds []string | ||
err bool |
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.
Nit: this could be renamed to expectErr
to clarify intent
internal/hcp/registry/hcl.go
Outdated
Severity: hcl.DiagError, | ||
Summary: "Build name conflicts", | ||
Detail: "When using HCP registry, build names are used as identifier. " + | ||
"In this case, there is 2 or more build called " + name, |
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.
I wonder if we can add a lead for solving this conflict in this case, like adding a name to the build
block if relevant.
I would also suggest adding a Subject here to have a location in the error message so users know where to look in order to fix the error.
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.
Currently, the only way to get a conflict is by using the same source on the build block. We probably should add a more precise message error once we support multiple build block
1688277
to
2d88abf
Compare
internal/hcp/registry/hcl.go
Outdated
|
||
type fullBuildNames map[string]map[string]struct{} | ||
|
||
// set will return true if properly inserted and false if the values is conflicting |
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.
// set will return true if properly inserted and false if the values is conflicting | |
// set will return true if properly inserted and false if the values are conflicting |
internal/hcp/registry/hcl.go
Outdated
} | ||
|
||
func (h *HCLRegistry) Metadata() Metadata { | ||
return h.metadata | ||
} | ||
|
||
type fullBuildNames map[string]map[string]struct{} |
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.
I'm not necessarily against the idea of introducing a structure for this, but it feels a bit verbous to get them, I wonder if having functions directly on HCLRegistry
wouldn't be better for this purpose?
internal/hcp/registry/hcl.go
Outdated
configuration *hcl2template.PackerConfig | ||
bucket *Bucket | ||
ui sdkpacker.Ui | ||
metadata *MetadataStore |
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.
Come to think of it, since we change how we get the build names, does that impact that MetadataStore
? It might not but I just want to be sure we considered delving into this before this gets merged, so that we don't break things later down the line
internal/hcp/registry/hcl.go
Outdated
type fullBuildNames map[string]map[string]struct{} | ||
|
||
// set will return true if properly inserted and false if the values is conflicting | ||
func (b fullBuildNames) set(buildName string, sourceName string) bool { |
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.
Assuming we remove that structure, this function is a one-time use thing, so the code might as well be rolled into the function that adds the builds I'd think
internal/hcp/registry/hcl.go
Outdated
} | ||
|
||
// get will return the properly formatted string taking name conflict into account | ||
func (b fullBuildNames) get(buildName string, sourceName string) string { |
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.
Assuming this is rolled into the function (or not even), the signature could be changed to accept a *CoreBuild
instead, so we can do the logic of getting the build from the source/build name combination if relevant
73401f3
to
dd52d0c
Compare
It was possible to put the same source 2 times in the build and when using HCP, it would error eventually since they are considered the same build from HCP side
dd52d0c
to
cc744bb
Compare
It was possible to put the same source 2 times in the build and when using HCP, it would error eventually since they are considered the samebuild from HCP side
Test
This would give this error:
$ packer build . Error: Build name conflicts When using HCP registry, build names are used as identifier. In this case, there is 2 or more build called jammy-build-block.docker.ubuntu-jammy