-
Notifications
You must be signed in to change notification settings - Fork 83
Update golden test framework #418
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
Update golden test framework #418
Conversation
I'm not sure whether anyone is using this framework, I suspect not because it is tied to mock-kubeapiserver. I think it's easier to just offer envtest by default, and there are a few other simplifications and requirements that brings (e.g. starting the manager). If we can, I'd also like to change the directory from These are breaking, but they are test code and I can't imagine people are using this outside of this repo (based on my experience trying to use it!). But if anyone knows of any usage, we can always do a v2 or just iterate on this externally. But because this is breaking (albeit test code) I think we should do it after updating the version. cc @tomasaschan |
I'm fine with the breaking change. Re: updating the version, I need access if you want help :) #407 (comment) |
35b6b37
to
c4ee825
Compare
69e95b9
to
1574649
Compare
/lgtm Marking this ready-to-go, but let's hold it until we have #417 done and a new tag available for folks who want a slower migration path (if there are any 🙃). I don't mind this breakage making it into |
1574649
to
e53951c
Compare
41cf5c3
to
a1604de
Compare
A massive diff, the majority of which is because I switched from json.Marshal to json.MarshalIndent. I could easily split that out into a separate PR though ... or just not do it at all. There will be changes to most golden-test-data lines (because of UID and resourceVersion simplification) which is why I thought it might be worth doing it in this PR. |
ab7c46b
to
63262a9
Compare
@@ -27,6 +27,9 @@ cd "${REPO_ROOT}" | |||
|
|||
set -x | |||
|
|||
# Download the kubebuilder assets for envtest | |||
export KUBEBUILDER_ASSETS=$(go run sigs.k8s.io/controller-runtime/tools/setup-envtest@latest use -p path) |
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.
As of kubernetes-sigs/controller-runtime#3135 this isn't really strictly necessary anymore. Would be worthwhile getting rid of while we're doing an overhaul, imo!
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.
OK that is very cool. I don't think it is released yet on a controller-runtime tag (at least not that I could see). We could keep our main/master branch close to the upstream controller-runtime main/master branch, now that we have branches!
ktest/testharness/kubeapiserver.go
Outdated
}) | ||
} else { | ||
// Removed for now... | ||
t.Fatalf("mockkubeapiserver is not supported with this test harness") |
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.
Are you planning to add this back? If not, I suggest making the parameter non-nil and just getting rid of the branch here.
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.
Pondering.... :-)
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 added it back. The output is slightly different because of the api discovery v2 features added in k/k, but I figure we can tackle that separately (if we choose to)
@@ -2,6 +2,7 @@ apiVersion: addons.example.org/v1alpha1 | |||
kind: Guestbook | |||
metadata: | |||
name: guestbook-sample | |||
namespace: default |
This comment was marked as resolved.
This comment was marked as resolved.
Sorry, something went wrong.
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.
So with envtest we need to create the objects for real, and kube-apiserver rejects the namespace-scoped object without a namespace. (We're not using kubectl, which would apply the default namespace for us)
We might be able to get away with not creating the object, but where there are "side objects" / dependencies those do need to created. I personally see this as the test suite now catching an invalid object.
63262a9
to
4faf744
Compare
4faf744
to
e3ab3cc
Compare
34e0281
to
75d3d2f
Compare
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
Great work on this! Are you happy enough with it that we should remove the hold and get it in, or should we publish a non-beta 0.20 first?
ktest/httprecorder/kube_normalize.go
Outdated
// rewriteAPIV3Hashes removes some semi-random hashes from the api discovery response. | ||
// It is semi-random because these are the hashes of all the types in that group, | ||
// so should be stable for a single k8s patch release. | ||
func rewriteAPIV3Hashes(t *testing.T, body map[string]any) { |
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.
Given that discovery requests are omitted, this should be unnecessary, right?
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.
Hmmm good question. So I did it because the hashes appear in the URL and they were appearing (and changing on patch kube version bumps). I think for discovery requests we only replace the body, but let me check.
(I think it's important that the discovery requests have a footprint because one of the problems we had in the past was that we were doing discovery every time. That's less important now that discovery is much more efficient, but I want to avoid regression there and on similar inefficiencies that don't change the outcome)
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 were spot on. I added openapi/v3 to the list of endpoints which should be removed for length, and that let me remove this function entirely. There are a few remaining discovery queries with hashes in the URL, but query parameters are much easier to replace so I did that.
* Add support for envtest (instead of mock-kubeapiserver) * Create shared code for capturing requests / normalization. * Use a more conventional env var WRITE_GOLDEN_OUTPUT * Support object rewriting
75d3d2f
to
7c8ce69
Compare
Personally I think we should merge this, because I think it's only going to touch test code and not the most widely used test code at that... If anything we want the envtest support because without the tests will use mockkubeapiserver, which does not accurately reflect modern kube. (I would like to fix that too, but not in this PR!) |
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.
Sweet!
/lgtm
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: justinsb, tomasaschan The full list of commands accepted by this bot can be found here. The pull request process is described here
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
/hold cancel |
Uh oh!
There was an error while loading. Please reload this page.