-
Notifications
You must be signed in to change notification settings - Fork 521
CLOUDP-81150: Replace operator-sdk test with envtest #315
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
Conversation
| - update | ||
| - watch | ||
| - apiGroups: | ||
| - rbac.authorization.k8s.io |
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.
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 |
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.
It looks like the operator-sdk test code was the only dependency on operator-sdk.
| ], | ||
| "command": [ | ||
| "/bin/operator-sdk", | ||
| "go", |
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.
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()) |
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.
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 ( | |||
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.
This file essentially replaces f.MainEntry, f.Context, and f.Global.
| postfix, err := generate.RandomValidDNS1123Label(5) | ||
| if err != nil { | ||
| t.Fatal() | ||
| t.Fatal(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.
Flyby fix: I neglected to report errors in this file when I first committed it.
561027e to
a4ac714
Compare
|
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 |
Done in previous commit! I removed mention of |
4fd082d to
1429588
Compare
chatton
left a comment
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.
This is looking great, massive work so far! Just had a few questions.
deploy/e2e/operator.yaml
Outdated
| @@ -0,0 +1,40 @@ | |||
| apiVersion: apps/v1 | |||
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.
[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?
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.
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.
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.
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.
deploy/e2e/operator.yaml
Outdated
| labels: | ||
| name: mongodb-kubernetes-operator | ||
| spec: | ||
| serviceAccountName: e2e-test |
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.
is this the only difference in this deployment?
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.
I believe so
| code := m.Run() | ||
|
|
||
| err = testEnv.Stop() | ||
| if err != nil { |
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.
[nit] same comment as above
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.
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.
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.
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.
|
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. |
chatton
left a comment
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.
LGTM! Thanks for all the great work with this refactor 🥇
| code := m.Run() | ||
|
|
||
| err = testEnv.Stop() | ||
| if err != nil { |
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.
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.
dc49ca3 to
630009e
Compare
All Submissions:
closes #XXXXin your comment to auto-close the issue that your PR fixes (if such).This PR removes
operator-sdk testfrom our e2e tests. It switches to usinggo testto run the test andenvtestto 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.