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

Fix inconsistent rebuild #2719

Merged
merged 3 commits into from
Apr 12, 2023
Merged

Conversation

carolynvs
Copy link
Member

@carolynvs carolynvs commented Apr 11, 2023

What does this change

This patch corrects two interrelated issues that were causing our bundle out-of-date check to not work well:

  1. We weren't passing the --insecure-registry flag from publish to build when a rebuild was triggered.
  2. We were incorrectly comparing the mixins from the cached bundle and the current bundle, with Go maps instead of a sorted array, so rebuilds would be triggered when nothing had changed.

I have updated the calls to EnsureBundleIsUpToDate so that it correctly passes through the --insecure-registry flag. I have also fixed the mixin comparison to use a sorted array so that it consistently generates the same manifest digest when detecting changes to the bundle.

I have also added a bunch of debug messages to the comparison of the cached and current bundle so that when it's flagged as out-of-date, it will print out why and include trace data to help figure out what's wrong/different.

What issue does it fix

Closes #2718
Closes #2503
Closes #500

Notes for the reviewer

N/A

Checklist

  • Did you write tests?
  • Did you write documentation?
  • Did you change porter.yaml or a storage document record? Update the corresponding schema file.
  • If this is your first pull request, please add your name to the bottom of our Contributors list. Thank you for making Porter better! 🙇‍♀️

Reviewer Checklist

  • Comment with /azp run test-porter-release if a magefile or build script was modified
  • Comment with /azp run porter-integration if it's a non-trivial PR

When we publish a bundle, we may need to rebuild it first. Now that build supports --insecure-registry, we should pass that flag from publish to the build command so that build also respects that setting.
This was causing the smoke test for the airgap tests to intermittently fail because of _another_ bug, which caused porter to occasionally consider a bundle out-of-date and require rebuilding when in fact nothing had changed.

This first commit fixes passing the flag properly from publish to build so that when a bundle is out-of-date and it's pointed at an insecure registry, the build won't fail with https/tls errors. The next commit will fix porter triggering a rebuild at the wrong times.

Signed-off-by: Carolyn Van Slyck <me@carolynvanslyck.com>
When we consider if a previously built bundle is out-of-date and should be rebuilt, we look at the porter.yaml file and also the set of mixins used by the bundle. We were storing those mixins and their installed version in a _map_, which doesn't sort consistently. So when a bundle used more than one mixin, there was always a chance that it would sort differently from the last build and trigger a rebuild.

I have updated how we compare the mixins used by the old/new bundle so that we always sort them in alphabetical order.

I have also added a bunch of debug logging and trace data so that it's easier to troubleshoot a bundle being incorrectly flagged as out-of-date next time. 😅

Signed-off-by: Carolyn Van Slyck <me@carolynvanslyck.com>
@carolynvs carolynvs marked this pull request as ready for review April 11, 2023 20:16
}

func (m MixinRecords) Less(i, j int) bool {
return m[i].Name < m[j].Name
Copy link
Contributor

Choose a reason for hiding this comment

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

Should this be a combination of name and version?

Copy link
Member Author

Choose a reason for hiding this comment

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

A bundle can only use a single mixin version at a time, so there can't be exec@1.2.3 and exec@1.2.4 for example, so just sorting by name will work. But who knows what the future holds! I can add version into the mix just in case we change things up later once mixins can be referenced bundles instead of embedded binaries.

// getUsedMixinsVersion compare the mixins defined in the manifest and the ones installed and then retrieve the mixin's version info
func (c *ManifestConverter) getUsedMixinsVersion() map[string]string {
usedMixinsVersion := make(map[string]string)
// getUsedMixinRecords compare the mixins defined in the manifest and the ones installed and then retrieve the mixin's version info
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: Update comment now that we're returning the record instead of just version info

When sorting mixins for the bundle stamp, sort by the mixin name and also include the mixin version. Currently bundles can only have a single version of a mixin, so the version comparison is for the future, after we have mixins as bundles, where it could be possible perhaps to use two different versions of a mixin in the same bundle, because they will be referenced images instead of embedded binaries.

Make sure to sort the versions by semantic version and not string, so that the leading v prefix is ignored and stuff like pre-releases and 0.0.10 and 0.0.1 sort correctly.

Signed-off-by: Carolyn Van Slyck <me@carolynvanslyck.com>
@carolynvs
Copy link
Member Author

@sgettys I've updated the comparison to take into account name and version to future proof this for when we have mixins as bundles. Please take another look.

@carolynvs carolynvs merged commit cdaf491 into getporter:main Apr 12, 2023
@carolynvs carolynvs deleted the fix-inconsistent-rebuild branch April 12, 2023 17:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants