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

Makefile improvements #2660

Merged
merged 5 commits into from
Mar 18, 2024
Merged

Makefile improvements #2660

merged 5 commits into from
Mar 18, 2024

Conversation

twz123
Copy link
Member

@twz123 twz123 commented Jan 31, 2023

Description

  • Improve Docker export in embedded-binaries Makefile
    Ensure that the binaries are moved into place, instead of sequentially written. Use a temporary untar folder for that, and touch the file there before moving it.

  • Remove unused "buildmode" make variable

  • Don't remove auto-generated files during builds
    Place client-gen and controller-gen generated files into their own temporary folders and move them into their proper places afterwards. Don't delete any files from the source directories. This ensures that parallel builds work as expected and tools won't encounter any "missing" Go packages during builds.

    (There's still a small potential race for client-gen. The whole directory needs to be replaced, which mv refuses to do. So move the to- be-replaced directory out of the way, move the new directory in place, and delete the old directory afterwards.)

  • Let generated assets depend on controller-gen output
    Amongst other things, the generated assets embed the controller-gen generated CRDs into the k0s binary. Ensure that all the CRDs have been generated before generating the embedded assets, so that everything is guaranteed to be up to date, especially when using parallel make builds.

  • Let CI use parallel builds

Fixes #2654.

Type of change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Documentation update

How Has This Been Tested?

  • Manual test
  • Auto test added

Checklist:

  • My code follows the style guidelines of this project
  • My commit messages are signed-off
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes
  • Any dependent changes have been merged and published in downstream modules
  • I have checked my code and corrected any misspellings

@twz123 twz123 force-pushed the parallel-make-builds branch from 1f3ea52 to c961ca9 Compare February 3, 2023 15:35
@twz123 twz123 marked this pull request as ready for review February 3, 2023 16:30
@twz123 twz123 requested a review from a team as a code owner February 3, 2023 16:30
@mikhail-sakhnov
Copy link
Contributor

@twz123 Could we keep buildmode=None behavior somehow?
I use it once in a while for different experiments or when I need to work locally on mac os without remote machine.

@twz123
Copy link
Member Author

twz123 commented Feb 13, 2023

Could we keep buildmode=None behavior somehow? I use it once in a while for different experiments or when I need to work locally on mac os without remote machine.

You mean make EMBEDDED_BINS_BUILDMODE=none? I don't think this PR interferes with it. If it does, this was certainly not intended. That mode is also used in some CI steps, so it should definitely remain intact. Please let me know if there are any issues with it.

@mikhail-sakhnov
Copy link
Contributor

@twz123 I was confused with "Remove unused "buildmode" make variable" but it seems to be about other thing, nvm

@@ -53,7 +53,7 @@ jobs:
- name: Build Tool
run: |
cd hack/tool
make
make --jobs=$(nproc)
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't really understand how here and everywhere in the diff -j helps to parallelize jobs, majority of the targets are single external commands and all of the make calls uses only one target.

Copy link
Member Author

@twz123 twz123 Feb 16, 2023

Choose a reason for hiding this comment

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

This is to ensure that k0s actually supports parallel builds, not so much to speed up things. That might prevent bugs like #2654. Parallel builds are advertised in the README, so we should ensure that there are no regressions.

It's so easy to hack on the Makefiles and do something that works flawlessly in sequential builds, but will break when run in parallel.

Copy link
Contributor

Choose a reason for hiding this comment

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

Other option is to change the readme and drop the claim, because in fact we do not support parallel build more than go build toolchain supports it. Makefile in our case basically just a job runner, not the build tool per se. Claiming that we support parallel build by passing -j is not something that exactly reflects the reality.

Copy link
Member Author

@twz123 twz123 Feb 16, 2023

Choose a reason for hiding this comment

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

It actually speeds things up a bit when building the embedded binaries (subjectively 15-20% on the GH runners). We can also drop the support for parallel builds, but then I think we should explicitly say that in the README.

@ncopa: You added the note about parallel builds. Any thoughts on that?

Copy link
Contributor

@mikhail-sakhnov mikhail-sakhnov Feb 16, 2023

Choose a reason for hiding this comment

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

15-20% is a significant difference. We could also keep the -j for the embedded binaries call (I guess it's coming from make k0s?) but drop the claim and don't put -j everywhere. On the other hand, I am not sure if claim in the readme has anything to share with our GHA workflows.

Copy link
Collaborator

Choose a reason for hiding this comment

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

I think that ensuring support for parallel builds will also help us make sure that partial builds always works. I think its worth the extra complexity.

@twz123 twz123 force-pushed the parallel-make-builds branch 3 times, most recently from eb8ab70 to 837f24b Compare February 24, 2023 14:56
ncopa
ncopa previously approved these changes Mar 7, 2023
Copy link
Collaborator

@ncopa ncopa left a comment

Choose a reason for hiding this comment

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

LGTM

@twz123
Copy link
Member Author

twz123 commented Mar 23, 2023

I'll revisit this once changes around #2909 have been sorted out.

@github-actions github-actions bot added Stale and removed Stale labels Apr 22, 2023
@github-actions github-actions bot added Stale and removed Stale labels May 24, 2023
@github-actions github-actions bot added Stale and removed Stale labels Jun 24, 2023
@github-actions github-actions bot added Stale and removed Stale labels Jul 26, 2023
@github-actions github-actions bot added the Stale label Aug 27, 2023
@twz123 twz123 removed the Stale label Aug 28, 2023
@github-actions github-actions bot added the Stale label Sep 27, 2023
@twz123 twz123 removed the Stale label Sep 28, 2023
@github-actions github-actions bot added the Stale label Oct 28, 2023
@twz123 twz123 removed the Stale label Oct 28, 2023
@twz123 twz123 force-pushed the parallel-make-builds branch from 837f24b to 8f8cfde Compare October 31, 2023 13:59
Copy link
Contributor

This pull request has merge conflicts that need to be resolved.

@twz123 twz123 force-pushed the parallel-make-builds branch from 479e09c to b447678 Compare January 17, 2024 11:05
@twz123 twz123 force-pushed the parallel-make-builds branch from b447678 to ac54421 Compare January 17, 2024 11:13
@k0sproject k0sproject deleted a comment from github-actions bot Jan 17, 2024
@k0sproject k0sproject deleted a comment from github-actions bot Jan 17, 2024
@k0sproject k0sproject deleted a comment from github-actions bot Jan 17, 2024
@k0sproject k0sproject deleted a comment from github-actions bot Jan 17, 2024
@k0sproject k0sproject deleted a comment from github-actions bot Jan 17, 2024
@k0sproject k0sproject deleted a comment from github-actions bot Jan 17, 2024
@k0sproject k0sproject deleted a comment from github-actions bot Jan 17, 2024
@k0sproject k0sproject deleted a comment from github-actions bot Jan 17, 2024
@k0sproject k0sproject deleted a comment from github-actions bot Jan 17, 2024
@twz123 twz123 disabled auto-merge February 7, 2024 11:44
Ensure that the binaries are moved into place, instead of sequentially
written. Use a temporary untar folder for that, and touch the file there
before moving it.

Signed-off-by: Tom Wieczorek <[email protected]>
Place client-gen and controller-gen generated files into their own
temporary folders and move them into their proper places afterwards.
Don't delete any files from the source directories. This ensures that
parallel builds work as expected and tools won't encounter any "missing"
Go packages during builds.

(There's still a small potential race for client-gen. The whole
directory needs to be replaced, which mv refuses to do. So move the to-
be-replaced directory out of the way, move the new directory in place,
and delete the old directory afterwards.)

Signed-off-by: Tom Wieczorek <[email protected]>
Amongst other things, the generated assets embed the controller-gen
generated CRDs into the k0s binary. Ensure that all the CRDs have been
generated _before_ generating the embedded assets, so that everything is
guaranteed to be up to date, especially when using parallel make builds.

Signed-off-by: Tom Wieczorek <[email protected]>
Signed-off-by: Tom Wieczorek <[email protected]>
@twz123 twz123 force-pushed the parallel-make-builds branch from ac54421 to c0b6ef8 Compare February 7, 2024 11:45
@twz123 twz123 enabled auto-merge February 8, 2024 08:48
Copy link
Contributor

github-actions bot commented Mar 8, 2024

The PR is marked as stale since no activity has been recorded in 30 days

@github-actions github-actions bot added the Stale label Mar 8, 2024
@twz123 twz123 removed the Stale label Mar 11, 2024
@twz123
Copy link
Member Author

twz123 commented Mar 18, 2024

@ncopa would you mind to have another look?

Copy link
Collaborator

@ncopa ncopa left a comment

Choose a reason for hiding this comment

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

LGTM

@twz123 twz123 merged commit 5ac8e6d into k0sproject:main Mar 18, 2024
73 checks passed
@twz123 twz123 deleted the parallel-make-builds branch March 18, 2024 13:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Build: make -j$(nproc) fails on first build
3 participants