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

✨ (go/v4): Add new makefile target to create a cluster name to run the e2e tests #4673

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

kersten
Copy link
Contributor

@kersten kersten commented Mar 26, 2025

change default Kind cluster names to be project-specific for e2e tests

Previously, the default Kind cluster name was "kind", which could lead to conflicts when running multiple e2e tests concurrently across different projects. This change updates the Kind cluster name to be project-specific, reducing potential conflicts and improving the isolation of e2e test environments.

@k8s-ci-robot k8s-ci-robot added the cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. label Mar 26, 2025
@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: kersten
Once this PR has been reviewed and has the lgtm label, please assign camilamacedo86 for approval. For more information see the Code Review Process.

The full list of commands accepted by this bot can be found here.

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@k8s-ci-robot
Copy link
Contributor

Hi @kersten. Thanks for your PR.

I'm waiting for a kubernetes-sigs member to verify that this patch is reasonable to test. If it is, they should reply with /ok-to-test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work. Regular contributors should join the org to skip this step.

Once the patch is verified, the new status will be reflected by the ok-to-test label.

I understand the commands that are listed here.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository.

@k8s-ci-robot k8s-ci-robot added size/L Denotes a PR that changes 100-499 lines, ignoring generated files. needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. labels Mar 26, 2025
@kersten kersten force-pushed the feat/project-specific-kind-cluster branch 2 times, most recently from e87b922 to c24a8f2 Compare March 26, 2025 16:32
@camilamacedo86 camilamacedo86 changed the title 🐛 update Kind cluster naming for e2e tests ✨ (go/v4): Add new makefile target to create a cluster name to run the e2e tests Mar 27, 2025
exit 1; \
@$(KIND) get clusters | grep -q 'project-test-e2e' || { \
echo "Kind cluster not running, creating Kind cluster: project-test-e2e"; \
$(KIND) create cluster --name project-test-e2e --wait 5m; \
Copy link
Member

Choose a reason for hiding this comment

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

I the cluster exist already it will fail, so should we not remove it.
I think we will need to clean it up as well, right?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Great idea! We already have some cleanup logic in our code, I’ll add a dedicated target for it as we have. What do you think - should we clean it up automatically after each test, or just provide a target so it can be run manually? On our side, we usually clean it up manually to avoid long spin-up times during development.

Copy link
Member

@camilamacedo86 camilamacedo86 Mar 27, 2025

Choose a reason for hiding this comment

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

I think we will need something like

.PHONY: kind-clean
kind-clean: 
	$(KIND) delete cluster --name $(KIND_CLUSTER_NAME)

and call it at the end of the tests

Also, I think we do not need to check and instead only create the cluster nane

	@$(KIND) get clusters | grep -q 'project-test-e2e' || { \
		echo "Kind cluster not running, creating Kind cluster: project-test-e2e"; \
		$(KIND) create cluster --name project-test-e2e --wait 5m; \

Can we also have an env var like the others for the cluster name?

Copy link
Contributor Author

@kersten kersten Mar 27, 2025

Choose a reason for hiding this comment

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

I've added that already. And the variable was already requested in this PR: #4617. Could you recheck the changes? There ist a teardown-test-e2e target.

I'll add another change, so that it is execute after the test.

Copy link
Member

@camilamacedo86 camilamacedo86 left a comment

Choose a reason for hiding this comment

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

Hi @kersten

I think the change looks good! We just need to make sure to clean up the cluster after the tests run.

Also, I hope you don’t mind—I updated the title of the PR to make it more suitable for the release notes.

@camilamacedo86
Copy link
Member

/ok-to-test

@k8s-ci-robot k8s-ci-robot added ok-to-test Indicates a non-member PR verified by an org member that is safe to test. and removed needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. labels Mar 27, 2025
@kersten kersten force-pushed the feat/project-specific-kind-cluster branch from c24a8f2 to 5f5eb82 Compare March 27, 2025 13:46
@kersten kersten requested a review from camilamacedo86 March 27, 2025 14:05
Comment on lines 78 to 80
@$(KIND) get clusters | grep -q 'project-test-e2e' || { \
echo "Kind cluster not running, creating Kind cluster: project-test-e2e"; \
$(KIND) create cluster --name project-test-e2e --wait 5m; \
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
@$(KIND) get clusters | grep -q 'project-test-e2e' || { \
echo "Kind cluster not running, creating Kind cluster: project-test-e2e"; \
$(KIND) create cluster --name project-test-e2e --wait 5m; \
$(KIND) create cluster --name $(KIND_CLUSTER_NAME) --wait 5m; \

@kersten sorry I might not be very clear.
I think that
a) above we would need to have only the line to create the cluster ( not to check if it exist )
b) use an variable for we store the name of the cluster

Then, after we run the tests

we call a target test-e2e-tweardown or cleanup something like that will delete the cluster name

Copy link
Contributor Author

Choose a reason for hiding this comment

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

For the envvar, I would rather wait for the PR #4617, or would you like me to merge the changes into this one?

Copy link
Member

@camilamacedo86 camilamacedo86 Mar 28, 2025

Choose a reason for hiding this comment

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

Could we not do all here and keep a full proposal?
WDYT?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sure, I will do it later. Probably tonight.

Comment on lines 78 to 79
@$(KIND) get clusters | grep -q 'project-test-e2e' || { \
echo "Kind cluster not running, creating Kind cluster: project-test-e2e"; \
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
@$(KIND) get clusters | grep -q 'project-test-e2e' || { \
echo "Kind cluster not running, creating Kind cluster: project-test-e2e"; \

Could we remove it?
It has no reason to check if the cluster exists.
If we try to create and itexistst then, the command will fail, so we can try to simplify the syntax and the code

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ok, removed the check.

@kersten kersten force-pushed the feat/project-specific-kind-cluster branch from 5f5eb82 to d48303b Compare March 27, 2025 21:24
@kersten kersten requested a review from camilamacedo86 March 27, 2025 21:27
exit 1; \
}
go test ./test/e2e/ -v -ginkgo.v
@$(KIND) delete cluster --name project-test-e2e
Copy link
Member

@camilamacedo86 camilamacedo86 Mar 28, 2025

Choose a reason for hiding this comment

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

Suggested change
@$(KIND) delete cluster --name project-test-e2e
@$(KIND) delete cluster --name $(KIND_CLUSTER_NAME)

Could we use a variable for the cluster name instead?
So, that it is aligned with the other targets , the makefile standard, and to allow users to customize it if they wish to easily?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hey, could you take a look at this? #4617

I feel like we might be talking past each other - should I include that change in this PR, or do we want to merge them separately, one after the other?

@command -v $(KIND) >/dev/null 2>&1 || { \
echo "Kind is not installed. Please install Kind manually."; \
exit 1; \
}
@$(KIND) get clusters | grep -q 'kind' || { \
echo "No Kind cluster is running. Please start a Kind cluster before running the e2e tests."; \
$(KIND) create cluster --name project-test-e2e --wait 5m
Copy link
Member

@camilamacedo86 camilamacedo86 Mar 28, 2025

Choose a reason for hiding this comment

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

Suggested change
$(KIND) create cluster --name project-test-e2e --wait 5m
$(KIND) create cluster --name $(KIND_CLUSTER_NAME)

Could we use a variable for the cluster name instead?
So, that it is aligned with the other targets , the makefile standard, and to allow users to customize it if they wish to easily?

Copy link
Member

Choose a reason for hiding this comment

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

Also, do we really need wait 5m ?
Why would it be required?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It doesn't wait at least 5 minutes. As soon as the control plane is ready, it proceeds immediately. We've observed that in rare cases, kind sets up so quickly that deployments to the cluster can fail, causing the test to fail as well. I'd suggest starting with a 5-minute wait. If that turns out to be too short or too long, we can make it configurable later.

Copy link
Member

Choose a reason for hiding this comment

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

What do you think about starting without a timeout for now, and only adding one later if we run into issues or have a clear reason for it?

For context, I’ve never needed to use a timeout in similar projects so far, so it seems unlikely we’ll need one here either. And in case something does go wrong, it might be better to fail fast and return the error immediately rather than wait up to 5 minutes.

This way, we keep things simple and avoid premature optimization, while still leaving room to adjust if needed later on.

Copy link
Member

@camilamacedo86 camilamacedo86 left a comment

Choose a reason for hiding this comment

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

Hi @kersten,

I'm OK with the proposed changes — I think it's a good addition to the default scaffolds.

I just added a couple of minor suggestions:

a) Use KIND_CLUSTER_NAME to parameterize the cluster name used in the tests
b) Simplify the code by removing the extra check

Thanks for the contribution! 🎉

@kersten kersten force-pushed the feat/project-specific-kind-cluster branch 3 times, most recently from efd67e7 to 06253d9 Compare March 28, 2025 12:07
@kersten kersten force-pushed the feat/project-specific-kind-cluster branch 4 times, most recently from 03ba85e to 4acb07d Compare March 31, 2025 17:57
@kersten kersten requested a review from camilamacedo86 March 31, 2025 17:59
cluster = v
cluster, ok := os.LookupEnv("KIND_CLUSTER")
if !ok {
return fmt.Errorf("KIND_CLUSTER is not set")
Copy link
Member

Choose a reason for hiding this comment

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

Do we need this change?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It would have worked with the old code, but since we no longer have a default kind cluster, it’s not necessary anymore. However, if the environment variable isn’t set, the image deployment will fail. I’d feel more comfortable if we explicitly notify the user when it's missing.

Copy link
Member

Choose a reason for hiding this comment

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

I will need some time to test this one.
If I just have kind running ( any cluster name ) and run the e2e tests, will that work fine?
If so, I am OK with if not I think we should allow it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I get your point. I think you will start the e2e test right out of your IDE. I will have to think about that and implement it. Currently that wouldn't work out of the box. You would have to provide the ENV var in the IDE launch config. I will provide a way, where it defaults to kind.

Copy link
Member

@camilamacedo86 camilamacedo86 Apr 2, 2025

Choose a reason for hiding this comment

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

Currently that wouldn't work out of the box

Before those changes do you think that it would not also work out of the box?
(PS.: I need to check.)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Before the change, they've should work out of the box. I reverted.

Copy link
Member

Choose a reason for hiding this comment

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

So, I think we should revert the change in the utils for now.
If needed, we can revisit and improve or refactor it in a separate PR since it feels a bit out of scope for this one.

That way, we can move forward with the changes in the Makefile without blocking.
WDYT?

@kersten kersten force-pushed the feat/project-specific-kind-cluster branch from 4acb07d to d131e27 Compare April 2, 2025 14:22
@kersten kersten requested a review from camilamacedo86 April 2, 2025 15:38
@kersten kersten force-pushed the feat/project-specific-kind-cluster branch 2 times, most recently from e853a8d to 4aac705 Compare April 3, 2025 10:11
KIND_CLUSTER=$(KIND_CLUSTER) go test ./test/e2e/ -v -ginkgo.v
$(MAKE) teardown-test-e2e

.PHONY: teardown-test-e2e
Copy link
Member

Choose a reason for hiding this comment

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

After reviewing possible naming options, it seems that cleanup-test-e2e is the most suitable choice.

It aligns well with the existing setup-test-e2e and test-e2e targets, keeping the naming consistent and intuitive. It also clearly communicates its purpose without being overly verbose or ambiguous.

Let me know if you'd prefer a different naming style, but this feels like the most balanced option for now.

Copy link
Member

@camilamacedo86 camilamacedo86 left a comment

Choose a reason for hiding this comment

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

Hi @kersten 👋

Thank you so much for this change, and sorry for the delay in reviewing it!

After going through everything, I believe we're definitely good to move forward — just two small nitpicks to address before merging:

  1. Revert the unnecessary change in the scaffolds method under utils, so that for now we keep only the Makefile improvements.
    👉 See: https://github.com/kubernetes-sigs/kubebuilder/pull/4673/files#r2030095359

  2. Consider renaming the e2e cleanup test target to cleanup-test-e2e instead of teardown-test-e2e.
    I think it would simplify the name and align better with the existing naming conventions.
    👉 See: https://github.com/kubernetes-sigs/kubebuilder/pull/4673/files#r2030095626

Thanks again for the contribution — really appreciate the effort here! 🙌

@kersten kersten force-pushed the feat/project-specific-kind-cluster branch 2 times, most recently from 1db61f0 to 37a0dd4 Compare April 7, 2025 07:45
@kersten kersten requested a review from camilamacedo86 April 7, 2025 07:47
cluster = v
cluster, ok := os.LookupEnv("KIND_CLUSTER")
if !ok {
return fmt.Errorf("KIND_CLUSTER is not set")
Copy link
Member

Choose a reason for hiding this comment

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

Hey! Just wondering — could we not keep it as before, so that if KIND_CLUSTER isn’t set, it still works with the default kind context? We could revisit this in a follow-up if needed.

WDYT? Just trying to keep it working out of the box for folks not setting that env var. 🙏

change default Kind cluster names to be project-specific for e2e tests

Previously, the default Kind cluster name was "kind", which could lead
to conflicts when running multiple e2e tests concurrently across
different projects. This change updates the Kind cluster name to be
project-specific, reducing potential conflicts and improving
the isolation of e2e test environments.
@kersten kersten force-pushed the feat/project-specific-kind-cluster branch from 37a0dd4 to 2bbb292 Compare April 7, 2025 10:40
@kersten kersten requested a review from camilamacedo86 April 7, 2025 10:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. ok-to-test Indicates a non-member PR verified by an org member that is safe to test. size/L Denotes a PR that changes 100-499 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants