Skip to content

Conversation

@alyacb
Copy link
Contributor

@alyacb alyacb commented Feb 3, 2021

All Submissions:

  • Have you opened an Issue before filing this PR?
  • Have you signed our CLA?
  • Have you checked to ensure there aren't other open Pull Requests for the same update/change?
  • Put closes #XXXX in your comment to auto-close the issue that your PR fixes (if such).

This PR removes operator-sdk test from our e2e tests. It switches to using go test to run the test and envtest to configure the environment. Most changes to individual e2e tests are just to refactor them to rely on globals/ a new main entry function refactored to test/e2e/client.go.

The downside is that test cleanup no longer happens after tests, which will not affect evergreen runs but will make post-test cleanup a manual process when developing locally.

@alyacb alyacb added the wip label Feb 3, 2021
- update
- watch
- apiGroups:
- rbac.authorization.k8s.io
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Needed a new role to add these additional permissions so the test could create the operator role. Furthermore, this had to be a cluster role for the clusterwide test.

github.com/imdario/mergo v0.3.9
github.com/klauspost/compress v1.9.8 // indirect
github.com/konsorten/go-windows-terminal-sequences v1.0.3 // indirect
github.com/operator-framework/operator-sdk v0.19.4
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 looks like the operator-sdk test code was the only dependency on operator-sdk.

],
"command": [
"/bin/operator-sdk",
"go",
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Key change here: go test instead of operator-sdk test

print("Creating Role")
k8s_conditions.ignore_if_already_exists(
lambda: rbacv1.create_namespaced_role(dev_config.namespace, _load_test_role())
lambda: rbacv1.create_cluster_role(_load_test_role())
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Needed to use a cluster role to be able to create a cluster role for the clusterwide test.

@@ -0,0 +1,74 @@
package e2eutil

import (
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This file essentially replaces f.MainEntry, f.Context, and f.Global.

postfix, err := generate.RandomValidDNS1123Label(5)
if err != nil {
t.Fatal()
t.Fatal(err)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Flyby fix: I neglected to report errors in this file when I first committed it.

@alyacb alyacb force-pushed the CLOUDP-81150_switch_to_envtest branch from 561027e to a4ac714 Compare February 4, 2021 11:10
@alyacb alyacb marked this pull request as ready for review February 4, 2021 11:42
@alyacb alyacb requested a review from chatton February 4, 2021 11:42
@alyacb alyacb removed the wip label Feb 4, 2021
@bznein
Copy link
Contributor

bznein commented Feb 4, 2021

Can you also make sure that the parts about e2e tests here: https://github.com/mongodb/mongodb-kubernetes-operator/blob/master/docs/contributing.md are up-to-date? Maybe they already are but I remember writing them some time ago with references to operator-sdk test so maybe they need some tweaking

@alyacb
Copy link
Contributor Author

alyacb commented Feb 4, 2021

Can you also make sure that the parts about e2e tests here: https://github.com/mongodb/mongodb-kubernetes-operator/blob/master/docs/contributing.md are up-to-date? Maybe they already are but I remember writing them some time ago with references to operator-sdk test so maybe they need some tweaking

Done in previous commit! I removed mention of operator-sdk and added envtest.

@alyacb alyacb force-pushed the CLOUDP-81150_switch_to_envtest branch from 4fd082d to 1429588 Compare February 4, 2021 16:35
Copy link
Contributor

@chatton chatton left a comment

Choose a reason for hiding this comment

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

This is looking great, massive work so far! Just had a few questions.

@@ -0,0 +1,40 @@
apiVersion: apps/v1
Copy link
Contributor

Choose a reason for hiding this comment

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

[q] do we need to introduce another yaml definition? We would get more benefit out of testing deploy/operator.yaml in our tests. What do you think?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Makes sense! The e2e role.yaml has additional permissions so it can create the test environment. I needed a new operator.yaml and serviceaccount.yaml because I changed the name of the role from mongodb-kubernetes-operator, however I'll look into whether we can just have role and role binding in this directory while reusing deploy/operator.yaml.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Update: I removed operator.yaml from the new e2e directory, since we weren't using it anyway (the test deploys using deploy/operator). We do, however, need a new cluster role, cluster rolebinding, and serviceaccount to create the operator role and role binding in the test itself for the deploy. We also need these to be able to create a new namespace in the cross-namespace test.

labels:
name: mongodb-kubernetes-operator
spec:
serviceAccountName: e2e-test
Copy link
Contributor

Choose a reason for hiding this comment

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

is this the only difference in this deployment?

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 believe so

code := m.Run()

err = testEnv.Stop()
if err != nil {
Copy link
Contributor

Choose a reason for hiding this comment

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

[nit] same comment as above

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sorry, I'm not sure which comment this refers to. If it's the exit code one, I also refactored this function to return an error code for the test to handle instead.

Copy link
Contributor

Choose a reason for hiding this comment

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

ah I think this comment was regarding preferring

if err := fn(); err != nil {
   return err
}

over

err := fn()
if err != nil {
  return err
}

Definitely not a blocker.

@alyacb
Copy link
Contributor Author

alyacb commented Feb 5, 2021

I implemented cleanup logic so that the --preform-cleanup flag works with the new changes. My last commit also added comments/ reorganised setup.go slightly.

@alyacb alyacb requested a review from chatton February 5, 2021 16:54
Copy link
Contributor

@chatton chatton left a comment

Choose a reason for hiding this comment

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

LGTM! Thanks for all the great work with this refactor 🥇

code := m.Run()

err = testEnv.Stop()
if err != nil {
Copy link
Contributor

Choose a reason for hiding this comment

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

ah I think this comment was regarding preferring

if err := fn(); err != nil {
   return err
}

over

err := fn()
if err != nil {
  return err
}

Definitely not a blocker.

@alyacb alyacb force-pushed the CLOUDP-81150_switch_to_envtest branch from dc49ca3 to 630009e Compare February 8, 2021 10:58
@alyacb alyacb merged commit c4b20bb into master Feb 8, 2021
@alyacb alyacb deleted the CLOUDP-81150_switch_to_envtest branch February 8, 2021 12:08
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.

4 participants