-
Notifications
You must be signed in to change notification settings - Fork 212
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
Sort mixin output in order declared #2472
Sort mixin output in order declared #2472
Conversation
When we are querying mixins, such as when we are asking each mixin for Dockerfile lines to include in the bundle image, we call them in go routines. Depending on how quickly they return, the order is not guaranteed and may change. I have updated our mixin query function to sort the results of querying the mixins in a consistent order, the order that they are defined in the bundle. The Execute function now returns a bit more information about the results of each mixin command, and it's up to the caller to decide how to handle errors when not all mixins are required to have a successful exit code. Lint allows mixins to not implement that command, so in that case we check if the command isn't implemented and skip over it. Fixes getporter#2469 During build in particular, this ensures that we optimize layer caching as much as possible by always outputing the same contents of the Dockerfile when building a bundle. Previously, it could include the mixins in varying order which prevented reuse of layers from previous builds. Signed-off-by: Carolyn Van Slyck <[email protected]>
5636349
to
d063b7a
Compare
Signed-off-by: Carolyn Van Slyck <[email protected]>
I just realized that the way I'm using the map isn't safe to use with go routines. I'll revert some of it to go back to using channels. |
Signed-off-by: Carolyn Van Slyck <[email protected]>
Signed-off-by: Carolyn Van Slyck <[email protected]>
Happily, the problem was just in the unit tests, not the code. I've fixed the test helper to avoid the race. |
pkg/mixin/helpers.go
Outdated
switch commandOpts.Command { | ||
case "build": | ||
if p.ReturnBuildError { | ||
return errors.New("encountered build error") | ||
} | ||
fmt.Fprintln(pkgContext.Out, "# exec mixin has no buildtime dependencies") | ||
fmt.Fprintf(pkgContext.Out, "# %s mixin has no buildtime dependencies", 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.
should we preserve the new line break in the output here?
pkg/pkgmgmt/client/helpers.go
Outdated
func (p *TestPackageManager) GetCalled() map[string]int { | ||
return p.called | ||
func (p *TestPackageManager) GetCalled(mixin string) int { | ||
calls, _ := p.called.Load(mixin) |
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.
should we check the boolean returned by Load to make sure the mixin exist in the map before we do the type assertion?
The "unsupported command" text is printed to stderr. I have updated our mixin/plugin runner to capture the command output and include it in the returned error when the command fails. That way we can check if a mixin command failed because the command isn't implemented. Signed-off-by: Carolyn Van Slyck <[email protected]>
Signed-off-by: Carolyn Van Slyck <[email protected]>
@VinozzZ I've updated the PR with your feedback, please take another look |
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.
lgtm!
What does this change
When we are querying mixins, such as when we are asking each mixin for Dockerfile lines to include in the bundle image, we call them in go routines. Depending on how quickly they return, the order is not guaranteed and may change. I have updated our mixin query function to sort the results of querying the mixins in a consistent order, the order that they are defined in the bundle.
During build in particular, this ensures that we optimize layer caching as much as possible by always outputing the same contents of the Dockerfile when building a bundle. Previously, it could include the mixins in varying order which prevented reuse of layers from previous builds.
What issue does it fix
Fixes #2469
Notes for the reviewer
N/A
Checklist
Reviewer Checklist