-
Notifications
You must be signed in to change notification settings - Fork 22
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
Convert existing e2e tests from Gingko to e2e framework #62
base: main
Are you sure you want to change the base?
Convert existing e2e tests from Gingko to e2e framework #62
Conversation
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: abdurrehman107 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 |
Hi @abdurrehman107. Thanks for your PR. I'm waiting for a etcd-io member to verify that this patch is reasonable to test. If it is, they should reply with Once the patch is verified, the new status will be reflected by the 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. |
9ee93c7
to
2477fcf
Compare
/ok-to-test |
0635056
to
8108e75
Compare
/retest |
d6c967c
to
48b58ec
Compare
/retest |
c8133bf
to
0d14085
Compare
The high level structure looks ok, but there is some overlaps between the e2e test suite and the Makefile as pointed out the above comments. The most straightforward way is to reuse the existing Makefile targets. Any refactoring or improvement should be in separate PRs. @hakman @gdasson @ArkaSaha30 PTAL The etcdcluster_controller_test.go needs to be updated as well. It can be addressed in a separate PR. |
40c08a3
to
4e63d28
Compare
Right. I'll take this up in the PR right after the |
1f83aa1
to
dd1123b
Compare
Suggest to follow the same order to setup & teardown the env. All e2e tests will be executed in between. Setup:
Teardown
Also please always keep in mind that one PR is supposed to do only one thing. Please move unrelated change (i.e. etcd version bumping) into separate PR. |
@ahrtr do you want me to remove the |
I won't insist on it this time. Please keep in mind next time. Please organize & order the setup & teardown stuff based on my comment above. |
8cb7c25
to
366396a
Compare
366396a
to
24f0672
Compare
@ahrtr, implemented your suggestions. Can you please review again? |
Signed-off-by: Abdur Rehman <[email protected]>
24f0672
to
053e196
Compare
Addressed feedback @ahrtr, can you please review again? |
test/e2e/e2e_suite_test.go
Outdated
testEnv.Setup( | ||
// create KinD cluster and namespace | ||
envfuncs.CreateCluster(kindCluster, kindClusterName), | ||
envfuncs.CreateNamespace(namespace), |
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.
Pls move it into "setup up environment" as the first step.
And remove the namespace in "cleanup environment" as the last step.
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.
@ahrtr make undeploy
deletes the namespace earlier. So deleting it manually errors out. I think we should also remove the step to create the namespace, since make deploy
creates it eitherway.
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.
The existing e2e test create the namespace and deploy the controller in BeforeAll
, and undeploy the controller and remove the namespace in AfterAll
. Can you sort out why the existing e2e test doesn't run into any issue?
etcd-operator/test/e2e/e2e_test.go
Lines 50 to 85 in 3879c6e
BeforeAll(func() { | |
By("creating manager namespace") | |
cmd := exec.Command("kubectl", "create", "ns", namespace) | |
_, err := utils.Run(cmd) | |
Expect(err).NotTo(HaveOccurred(), "Failed to create namespace") | |
By("installing CRDs") | |
cmd = exec.Command("make", "install") | |
_, err = utils.Run(cmd) | |
Expect(err).NotTo(HaveOccurred(), "Failed to install CRDs") | |
By("deploying the controller-manager") | |
cmd = exec.Command("make", "deploy", fmt.Sprintf("IMG=%s", projectImage)) | |
_, err = utils.Run(cmd) | |
Expect(err).NotTo(HaveOccurred(), "Failed to deploy the controller-manager") | |
}) | |
// After all tests have been executed, clean up by undeploying the controller, uninstalling CRDs, | |
// and deleting the namespace. | |
AfterAll(func() { | |
By("cleaning up the curl pod for metrics") | |
cmd := exec.Command("kubectl", "delete", "pod", "curl-metrics", "-n", namespace) | |
_, _ = utils.Run(cmd) | |
By("undeploying the controller-manager") | |
cmd = exec.Command("make", "undeploy") | |
_, _ = utils.Run(cmd) | |
By("uninstalling CRDs") | |
cmd = exec.Command("make", "uninstall") | |
_, _ = utils.Run(cmd) | |
By("removing manager namespace") | |
cmd = exec.Command("kubectl", "delete", "ns", namespace) | |
_, _ = utils.Run(cmd) | |
}) |
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.
Just manually ran the Gingko tests by commenting out the part where they delete the namespace. It still worked. From my understanding it is meant to be a fault tolerant way to ensure that the namespace does not remain not-deleted at the end of the test.
However, I don't think this is needed in our case. Because we dont have to manually pre-create a Kind cluster like with Gingko (we must have a kind cluster already there to run the e2e test in Gingko). In our case we create and destroy the entire Kind cluster, all within the e2e test. So we don't need a "fault-tolerant" method, because the cluster would get deleted anyways.
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.
Just manually ran the Gingko tests by commenting out the part where they delete the namespace. It still worked.
It works doesn't means it's correct. You create it, then you need to remove it.
It seems that the namespace etcd-operator-system
automatically applied? The existing e2e test still manually create the namespace on setup and remove it on teardown as mentioned above. Is it necessary or not? @ArkaSaha30
namespace: etcd-operator-system |
Generally, I suggest to following existing e2e pattern. Any improvement can be done later in separate PR.
if err := os.Chdir("../../"); err != nil { | ||
log.Printf("Unable to set working directory: %s", err) | ||
return ctx, err | ||
} |
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.
We expect users to run the e2e test from the root directory. go test ./test/e2e/
if err := os.Chdir("../../"); err != nil { | |
log.Printf("Unable to set working directory: %s", err) | |
return ctx, err | |
} |
if err := os.Chdir("../../"); err != nil { | ||
log.Printf("Unable to set working directory: %s", err) | ||
return ctx, err | ||
} |
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.
We expect users to run the e2e test from the root directory. go test ./test/e2e/
if err := os.Chdir("../../"); err != nil { | |
log.Printf("Unable to set working directory: %s", err) | |
return ctx, err | |
} |
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.
@ahrtr, I did manually test using go test ./test/e2e
from the root directory, the tests fail if I do not move out of the directory. The go test ./test/e2e/
makes them start from the directory test/e2e.
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.
Again, why the existing e2e test work without this?
config/manager/manager.yaml
Outdated
@@ -63,7 +63,7 @@ spec: | |||
args: | |||
- --leader-elect | |||
- --health-probe-bind-address=:8081 | |||
image: controller:latest | |||
image: etcd-operator-controller:v0.1 |
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.
You change "latest" to "v0.1.0", it means that we will have to maintain it each time when we bump the version. Suggest not to change it, and let's always add tag "latest" for the image as well.
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.
@ahrtr we are building the image locally. If I put the tag latest, it for some reason defaults to trying to pull the image from a registry (the default one being DockerHub). I used the tag current
and it works. Sounds good?
Signed-off-by: Abdur Rehman <[email protected]>
112a460
to
0f69247
Compare
Signed-off-by: Abdur Rehman <[email protected]>
go.uber.org/zap v1.27.0 | ||
k8s.io/api v0.32.1 | ||
k8s.io/apimachinery v0.32.1 | ||
k8s.io/client-go v0.32.1 | ||
k8s.io/klog/v2 v2.130.1 | ||
k8s.io/utils v0.0.0-20241104100929-3ea5e8cea738 | ||
sigs.k8s.io/controller-runtime v0.20.1 | ||
sigs.k8s.io/e2e-framework v0.5.0 |
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.
Can we maintain a separate go.mod for test/e2e ...similar to etcd:https://github.com/etcd-io/etcd/tree/main/tests ?
Also, a newer v0.6.0 is available, can we use that?
|
||
"go.etcd.io/etcd-operator/test/utils" | ||
kubebuilder_utils "go.etcd.io/etcd-operator/test/utils" |
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.
Does it make more sense to name it as e2e_utils
or test_utils
?
func TestMain(m *testing.M) { | ||
testEnv = env.New() | ||
kindClusterName := "etcd-cluster" | ||
kindCluster := kind.NewCluster(kindClusterName) |
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 keep the option for which version of Kubernetes the kind cluster should spin up with? Default can use the latest available.
Ref: https://github.com/kubernetes-sigs/e2e-framework/blob/main/support/kind/kind.go#L28
I suggest to add a very simple e2e test to do some simple sanity test to ensure the environment is healthy. |
return ctx, nil | ||
}, | ||
|
||
// set up environment |
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.
// set up environment | |
// create namespace and deploy the etcd-operator |
The above adds the default e2e tests written using the e2e framework. These were earlier written in Gingko. The PR creates a Kind Cluster and installs Prometheus, Cert Manager and Controller manager.
The e2e_test.go file is left empty so I can include tests in it. Most of the work done in Gingko earlier has been replicated in the e2e_suite_test.go.
There are a couple things such as displaying logs at the end of each test (AfterAll() in Gingko) which I cannot add in e2e framework until we begin writing the tests. I have a few more tests ready, and we can begin on them once this PR is merged.