Set the default platform for select sources based on host arch#152
Set the default platform for select sources based on host arch#152
Conversation
Benchmark Test ResultsBenchmark results from the latest changes vs base branch |
Signed-off-by: Alex Goodman <alex.goodman@anchore.com>
543bdf2 to
bea3bc0
Compare
…tform Signed-off-by: Alex Goodman <alex.goodman@anchore.com>
| switch source { | ||
| case image.DockerTarballSource, image.OciDirectorySource, image.OciTarballSource, image.SingularitySource: | ||
| if cfg.Platform != nil { | ||
| return fmt.Errorf("specified platform=%q however image source=%q does not support selecting platform", cfg.Platform.String(), source.String()) |
There was a problem hiding this comment.
Does this need to be an error? could it just safely be ignored here?
There was a problem hiding this comment.
given that the user explicitly asked for an image with the given platform, we don't want to analyze a different image than what was intended. Logging an error would allow for the analysis to continue, and say in syft an SBOM to be produced, but the SBOM config would show a platform that differs than that of what was really analyzed (which seems wrong)
| return provider, nil | ||
| } | ||
|
|
||
| func setPlatform(source image.Source, cfg *config, defaultArch string) error { |
There was a problem hiding this comment.
nit: setDefaultPlatform or similar, since it does nothing if platform is set?
There was a problem hiding this comment.
that's probably the right name 👍
There was a problem hiding this comment.
Well, on second thought, this is also verifying that a non-default, non-nil platform is allowed to be set by the user... which goes beyond setting the default. There is probably a better name for this but setPlatform and setDefaultPlatform both don't quite fit the bill... but setPlatform is slightly less incorrect, so I'll leave it for now.
…re#152) * set the default platform for select sources based on host arch Signed-off-by: Alex Goodman <alex.goodman@anchore.com> * decompose into smaller function and add tests for setting default platform Signed-off-by: Alex Goodman <alex.goodman@anchore.com> --------- Signed-off-by: Alex Goodman <alex.goodman@anchore.com>
This PR sets a default platform to image providers that support platform options only if there is no overriding platform specified by the caller.
This should help alleviate the problems described in anchore/syft#1391 .
Fixes #149