-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
Add scheme support to fake client #213
Add scheme support to fake client #213
Conversation
Adds a NewFakeClientWithScheme function that takes a *runtime.Scheme as its first argument. NewFakeClient is now a wrapper around NewFakeClientWithScheme, passing it the default scheme.Scheme. As part of this, the scheme can now be used to derive the correct List GVK. This eliminates the need to use a metav1.List and opts.Raw.TypeMeta. Now it's possible to pass in a typed List, same as with the real client.
5ae1b29
to
8f3407b
Compare
This is enabled by new type support in fake client List. Other tests may also be updated to use this style.
As a bonus, I added the GVK support from https://github.com/kubernetes-sigs/controller-runtime/pull/106/files#diff-62fbcb10a0dc0bc5b0a1bba07b8eefb0R82 to this PR. This allows the fake client to work with typed Lists (e.g. |
metav1.List and corev1.List don't conform to the TypeList standard expected by getGVKFromList.
} | ||
|
||
if gvk.Kind == "List" { | ||
return schema.GroupVersionKind{}, fmt.Errorf("cannot derive GVK for generic List type %T (kind %q)", list, gvk) |
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 check is necessary to detect the corev1.List
and metav1.List
type, which don't conform to the SingularTypeList
format expected here. Without this check the returned GVK has an empty Kind
.
It seems worthwhile to consolidate this derivation into a single helper function, since it's also used in varying forms in these places:
if strings.HasSuffix(gvk.Kind, "List") && meta.IsListType(obj) { |
if strings.HasSuffix(gvk.Kind, "List") { |
if !strings.HasSuffix(gvk.Kind, "List") { |
Co-Authored-By: grantr <grantr@gmail.com>
[APPROVALNOTIFIER] This PR is APPROVED Approval requirements bypassed by manually added approval. This pull-request has been approved by: grantr 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 |
Add scheme support to fake client
* update generated code via bin/gen-kube This should help with * kubernetes-sigs/controller-runtime#168 * kubernetes-sigs/controller-runtime#213
* `go get -u ...@version` * `go mod tidy` * update generated code via bin/gen-kube This should help with * kubernetes-sigs/controller-runtime#168 * kubernetes-sigs/controller-runtime#213
* `go get -u ...@version` * `go mod tidy` * update generated code via bin/gen-kube This should help with * kubernetes-sigs/controller-runtime#168 * kubernetes-sigs/controller-runtime#213
* `go get -u ...@version` * `go mod tidy` * update generated code via bin/gen-kube This should help with * kubernetes-sigs/controller-runtime#168 * kubernetes-sigs/controller-runtime#213
Adds a
NewFakeClientWithScheme
function that takes a*runtime.Scheme
as its first argument.NewFakeClient
is now a wrapper aroundNewFakeClientWithScheme
, passing it the defaultscheme.Scheme
.Fixes #137.