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

🌱 Configure ENVTEST Binaries for IDE Debugging #1454

Merged

Conversation

camilamacedo86
Copy link
Contributor

@camilamacedo86 camilamacedo86 commented Nov 13, 2024

This change introduces downloading the specific binaries required to run ENVTEST-based tests into the project/bin directory. This setup makes configuring tests for debugging directly in an IDE easier.

Motivation

  1. Ease of IDE Debugging:
    • By setting the BinaryAssetsDirectory dynamically, contributors can debug tests in their preferred IDEs (e.g., GoLand, VSCode) without requiring additional environment configuration such as setting KUBEBUILDER_ASSETS.

Screenshot 2024-11-13 at 17 38 40

  1. Project-Specific Binaries:

Installing binaries inside the project avoids conflicts with other projects or system-wide installations, particularly useful for contributors with restricted environments (e.g., corporate laptops).

The binaries installed by envtest-setup are no longer placed in the HOME/global directory. See the default behavior here:
https://github.com/kubernetes-sigs/controller-runtime/blob/e3347b5405cdd0da5bff527af3d406117938ba6b/tools/setup-envtest/README.md?plain=1#L57-L70

This change ensures binaries are placed locally, avoiding the conflicts and clutter caused by global installations.

I’m referring to the binaries required for ENVTEST (not those managed by BINGO).

Screenshot 2024-11-19 at 01 22 59

Before this PR those are placed for example in a Mac OS at: /Users/camilam/Library/Application Support/io.kubebuilder.envtest/k8s/1.31.0-darwin-arm64

$ pwd
/Users/camilam/Library/Application Support/io.kubebuilder.envtest/k8s/1.31.0-darwin-arm64

ls -la
total 337856
dr-xr-xr-x  5 camilam  staff       160 19 Nov 09:20 .
drwxr-xr-x  3 camilam  staff        96 19 Nov 09:20 ..
-r-xr-xr-x  1 camilam  staff  26058562 19 Nov 09:20 etcd
-r-xr-xr-x  1 camilam  staff  90359954 19 Nov 09:20 kube-apiserver
-r-xr-xr-x  1 camilam  staff  56560754 19 Nov 09:20 kubectl

  1. Simplified Contributor Onboarding:
    • New contributors often face a learning curve to:
      • Understand ENVTEST and its dependency on binaries.
      • Configure KUBEBUILDER_ASSETS manually.
      • Set up their IDE for debugging tests.
    • This setup minimizes friction and ensures tests can be run consistently across different environments.

While setting KUBEBUILDER_ASSETS is sufficient for experienced contributors, this change makes it easier for newcomers and supports debugging directly in IDEs without additional configuration.

@openshift-ci openshift-ci bot added the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Nov 13, 2024
Copy link

netlify bot commented Nov 13, 2024

Deploy Preview for olmv1 ready!

Name Link
🔨 Latest commit 450d120
🔍 Latest deploy log https://app.netlify.com/sites/olmv1/deploys/6761547aaf2b600008a23e39
😎 Deploy Preview https://deploy-preview-1454--olmv1.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

@camilamacedo86 camilamacedo86 changed the title WIP: Allow debug tests with IDE (Blocked by #1453) - WIP: 🌱 Allow debug tests with IDE Nov 13, 2024
@camilamacedo86 camilamacedo86 force-pushed the allow-debug-test branch 2 times, most recently from 6ccb706 to bec5b49 Compare November 13, 2024 12:50
@camilamacedo86 camilamacedo86 changed the title (Blocked by #1453) - WIP: 🌱 Allow debug tests with IDE WIP: 🌱 Allow debug tests with IDE Nov 13, 2024
@camilamacedo86 camilamacedo86 force-pushed the allow-debug-test branch 5 times, most recently from ff5d402 to 94cd7d3 Compare November 13, 2024 19:30
@camilamacedo86 camilamacedo86 changed the title WIP: 🌱 Allow debug tests with IDE 🌱 (fix): configure ENVTEST binaries for IDE execution and project-specific setup Nov 13, 2024
@camilamacedo86 camilamacedo86 changed the title 🌱 (fix): configure ENVTEST binaries for IDE execution and project-specific setup WIP - 🌱 (fix): configure ENVTEST binaries for IDE execution and project-specific setup Nov 13, 2024
@camilamacedo86 camilamacedo86 force-pushed the allow-debug-test branch 5 times, most recently from 703e583 to 9ba4f50 Compare November 13, 2024 20:40
@camilamacedo86 camilamacedo86 changed the title WIP - 🌱 (fix): configure ENVTEST binaries for IDE execution and project-specific setup 🌱 (fix): configure ENVTEST binaries for IDE execution and project-specific setup Nov 13, 2024
@camilamacedo86 camilamacedo86 marked this pull request as ready for review November 13, 2024 20:49
@camilamacedo86 camilamacedo86 requested a review from a team as a code owner November 13, 2024 20:49
@openshift-ci openshift-ci bot removed the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Nov 13, 2024
Makefile Outdated Show resolved Hide resolved
Copy link

codecov bot commented Nov 17, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 74.68%. Comparing base (7ad65d6) to head (450d120).
Report is 1 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1454      +/-   ##
==========================================
- Coverage   74.87%   74.68%   -0.19%     
==========================================
  Files          42       42              
  Lines        3271     3271              
==========================================
- Hits         2449     2443       -6     
- Misses        648      652       +4     
- Partials      174      176       +2     
Flag Coverage Δ
e2e 52.15% <ø> (-0.19%) ⬇️
unit 57.99% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@camilamacedo86
Copy link
Contributor Author

Hi @m1kola,

Thank you for catching that—really good observation! 🙌

Your comment highlights an additional motivation for this change: addressing scenarios like those outlined in kubernetes-sigs/controller-runtime#2744 and kubernetes-sigs/controller-runtime#2646.

The required changes have been addressed, and we no longer use bingo here as intended. Please feel free to review this one.

@camilamacedo86 camilamacedo86 changed the title WIP (came back to use bingo)🌱 (fix): configure ENVTEST binaries for IDE execution and project-specific setup WIP (TODO: came back to use bingo)🌱 (fix): configure ENVTEST binaries for IDE execution and project-specific setup Nov 18, 2024
m1kola

This comment was marked as resolved.

@camilamacedo86

This comment was marked as resolved.

@m1kola

This comment was marked as resolved.

@camilamacedo86 camilamacedo86 changed the title WIP (TODO: came back to use bingo)🌱 (fix): configure ENVTEST binaries for IDE execution and project-specific setup 🌱 Configure ENVTEST Binaries for IDE Debugging Nov 19, 2024
@openshift-ci openshift-ci bot removed the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Nov 19, 2024
@camilamacedo86
Copy link
Contributor Author

Hi @joelanford, @m1kola, @perdasilva, @bentito,

Apologies for the confusion earlier!

This PR is NOT about Bingo. The main goal is to make debugging ENVTEST-based tests in the IDE simpler and more straightforward.

I suspect that some team members might think it’s not possible to debug with Ginkgo because the tests in question are actually ENVTEST-based. This change addresses that scenario and clarifies the process.

I’ve addressed all comments, closed all as done or outdated to avoid confusion, reverted the BINGO changes, and kept the suggestions.

@m1kola, could you please revert your block?

Thanks in advance! 😊

//
// To ensure the binaries are in the expected path without manual configuration, run:
// `make setup-envtest`
if getFirstFoundEnvTestBinaryDir() != "" {
Copy link
Contributor Author

@camilamacedo86 camilamacedo86 Nov 19, 2024

Choose a reason for hiding this comment

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

Hi @perdasilva,

You added this comment, and I deviated—sorry about that!

Would it be cleaner if we just used an environment variable like ENV_TEST_BINARY_DIR or something like that?
Then, it doesn't really matter where the binaries are placed.

We already have an environment variable (KUBEBUILDER_ASSETS) that can be used, but it’s not very convenient and involves a steep learning curve:

  • Know that ENVTEST requires binaries.
  • Then, by default, ENVTEST is expected to find the bins in local/....
  • We can override this using the KUBEBUILDER_ASSETS environment variable.
  • Note that those bins never was in the $GOPATH/bin because they are placed via the setup-invest in the global place (see here) which indeed cause issues for those which have restrictive envs.
  • Then, there’s the added challenge of knowing how to configure the tests properly in an IDE.

This PR simplifies the process so everything “just works” without extra setup or deep knowledge.
Making tests and debugging smoother and hassle-free.

I’ve also updated the code comments to clarify things further.
Hope this clears everything up! 😊

Copy link
Contributor

Choose a reason for hiding this comment

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Both are done 👍
Thank you 🥇

test-unit: $(SETUP_ENVTEST) #HELP Run the unit tests
rm -rf $(COVERAGE_UNIT_DIR) && mkdir -p $(COVERAGE_UNIT_DIR)
eval $$($(SETUP_ENVTEST) use -p env $(ENVTEST_VERSION) $(SETUP_ENVTEST_BIN_DIR_OVERRIDE)) && \
KUBEBUILDER_ASSETS="$(shell $(SETUP_ENVTEST) use -p path $(ENVTEST_VERSION) $(SETUP_ENVTEST_BIN_DIR_OVERRIDE))" \
Copy link
Contributor Author

@camilamacedo86 camilamacedo86 Nov 19, 2024

Choose a reason for hiding this comment

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

Hi @m1kola,

Just to clarify, the binaries installed by envtest-setup are no longer placed in the HOME/global directory. See the default behavior here:
https://github.com/kubernetes-sigs/controller-runtime/blob/e3347b5405cdd0da5bff527af3d406117938ba6b/tools/setup-envtest/README.md?plain=1#L57-L70

This change ensures binaries are placed locally, avoiding the conflicts and clutter caused by global installations.

To clarify, I’m referring to the binaries required for ENVTEST (not those managed by BINGO).

Screenshot 2024-11-19 at 01 22 59

Hope this clears things up! 😊

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@perdasilva ^ That might clarify better.

Makefile Outdated Show resolved Hide resolved
Makefile Show resolved Hide resolved
Makefile Show resolved Hide resolved
@camilamacedo86
Copy link
Contributor Author

Hi @m1kola

Thank you. Regards #1454 (comment) see : #1454 (comment)

That is not the goal of the PR, and this point can be addressed in a follow-up.

Copy link
Member

@m1kola m1kola left a comment

Choose a reason for hiding this comment

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

Looks good to me overall.

Just one question about $(SETUP_ENVTEST) and setup-envtest targets.

Makefile Show resolved Hide resolved
Makefile Outdated
$(SETUP_ENVTEST) use -p env $(ENVTEST_VERSION) $(SETUP_ENVTEST_BIN_DIR_OVERRIDE)

.PHONY: test-unit
test-unit: $(SETUP_ENVTEST) setup-envtest #HELP Run the unit tests
Copy link
Member

Choose a reason for hiding this comment

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

A bit strange to have $(SETUP_ENVTEST) and setup-envtest targets.

Is it beneficial to have a separate setup-envtest target here?

Maybe we can just do this?

Suggested change
test-unit: $(SETUP_ENVTEST) setup-envtest #HELP Run the unit tests
test-unit: $(SETUP_ENVTEST) #HELP Run the unit tests
mkdir -p $(ROOT_DIR)/bin
$(SETUP_ENVTEST) use -p env $(ENVTEST_VERSION) $(SETUP_ENVTEST_BIN_DIR_OVERRIDE)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

  • $(SETUP_ENVTEST) -> Downloads the binary for setting up envtest.
  • setup-envtest -> Downloads the Kubernetes binaries and actually sets up envtest.

If we make the suggested change where we are not calling setup-envtest and we do not have an option to do only that, it would allow us to have the required binaries to run the IDE without running the WHOLE unit tests.

Copy link
Member

Choose a reason for hiding this comment

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

If we make the suggested change where we are not calling setup-envtest and we do not have an option to do only that, it would allow us to have the required binaries to run the IDE without running the WHOLE unit tests.

Got it. I still don't like the naming, but I don't think we should block on this. And I can't come up with a meaningful alternative name for setup-envtest as well :)

Copy link
Contributor

@perdasilva perdasilva Dec 17, 2024

Choose a reason for hiding this comment

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

maybe we could call the target: setup-local-env or something like that. Then, it could be a generic target for developers to bootstrap their local development environment. Right now, that may only be the envtest binaries, but there could me more in the future. Maybe we could also add an @echo "adding envtest binaries to bin/ - see [link to developer docs] for more details"?

m1kola
m1kola previously approved these changes Dec 17, 2024
Makefile Outdated
$(SETUP_ENVTEST) use -p env $(ENVTEST_VERSION) $(SETUP_ENVTEST_BIN_DIR_OVERRIDE)

.PHONY: test-unit
test-unit: $(SETUP_ENVTEST) setup-envtest #HELP Run the unit tests
Copy link
Member

Choose a reason for hiding this comment

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

If we make the suggested change where we are not calling setup-envtest and we do not have an option to do only that, it would allow us to have the required binaries to run the IDE without running the WHOLE unit tests.

Got it. I still don't like the naming, but I don't think we should block on this. And I can't come up with a meaningful alternative name for setup-envtest as well :)

@camilamacedo86
Copy link
Contributor Author

Hi @m1kola

Thank you very much for the very detailed review.
If we see fit, we can also continuously improve things on follow-ups.
Sometimes, it is easier.

Again, thank you a lot for your review 🥇

This change introduces downloading the specific binaries required to run ENVTEST-based tests into the project/bin directory. This setup makes it easier to configure tests for debugging directly in an IDE.

Furthermore, no longer install binaries required for ENVTEST based tests on the project/bin instead of global path.
Copy link
Contributor

@perdasilva perdasilva left a comment

Choose a reason for hiding this comment

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

lgtm - thank you <3

@camilamacedo86 camilamacedo86 added this pull request to the merge queue Dec 17, 2024
@camilamacedo86
Copy link
Contributor Author

Thank you @perdasilva and @m1kola

I am moving forward with this one
I think all suggestions and etc are addressed

However, we can always to push enhancements in a follow-up as well.

Merged via the queue into operator-framework:main with commit d3f267a Dec 17, 2024
18 of 19 checks passed
@camilamacedo86 camilamacedo86 deleted the allow-debug-test branch December 17, 2024 12:02
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.

5 participants