Skip to content

Commit

Permalink
Update handling of image metadata before pushing to registry (#11458)
Browse files Browse the repository at this point in the history
When obtaining image metadata for a HCP Packer build, Packer core will
use mapstructure to decode the image metadata and validate that is has
all of the required data set. Before this change Packer core would fail
if there is extra metadata fields in the image metadata that Packer is
  not aware.

This change removes the restriction of erroring on unused metadata
fields. Packer should only care about the fields it knows and ignore the
rest. In the future, we will add new fields to the SDK but plugins may
begin sending that data sooner.
  • Loading branch information
Wilken Rivera authored Dec 17, 2021
1 parent 6176d79 commit b6f02d3
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 2 deletions.
2 changes: 1 addition & 1 deletion packer/registry_builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ func (b *RegistryBuilder) Run(ctx context.Context, ui packersdk.Ui, hook packers
decoder, err := mapstructure.NewDecoder(&mapstructure.DecoderConfig{
Result: &images,
WeaklyTypedInput: true,
ErrorUnused: true,
ErrorUnused: false,
})
if err != nil {
return artifact, fmt.Errorf("failed to create decoder for HCP Packer registry image: %w", err)
Expand Down
2 changes: 1 addition & 1 deletion packer/registry_post_processor.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ func (p *RegistryPostProcessor) PostProcess(ctx context.Context, ui packersdk.Ui
decoder, err := mapstructure.NewDecoder(&mapstructure.DecoderConfig{
Result: &images,
WeaklyTypedInput: true,
ErrorUnused: true,
ErrorUnused: false,
})
if err != nil {
return source, false, false, fmt.Errorf("failed to create decoder for HCP Packer registry image: %w", err)
Expand Down

0 comments on commit b6f02d3

Please sign in to comment.