-
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
⚠️ Fakeclient: Add apply support #2981
base: main
Are you sure you want to change the base?
Conversation
Skipping CI for Draft Pull Request. |
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: alvaroaleman 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 |
The Kubernetes project currently lacks enough contributors to adequately respond to all PRs. This bot triages PRs according to the following rules:
You can:
Please send feedback to sig-contributor-experience at kubernetes/community. /lifecycle stale |
/lifecycle frozen |
@alvaroaleman: The In response to this:
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. |
The This bot removes
You can:
Please send feedback to sig-contributor-experience at kubernetes/community. /remove-lifecycle frozen |
ac5705d
to
b8202b9
Compare
This change adds apply support into the fake client. This relies on the upstream support for this which is implemented in a new [FieldManagedObjectTracker][0]. In order to support many types, a custom `multiTypeConverter` is added. [0]: https://github.com/kubernetes/kubernetes/blob/4dc7a48ac6fb631a84e1974772bf7b8fd0bb9c59/staging/src/k8s.io/client-go/testing/fixture.go#L643
b8202b9
to
71e305a
Compare
type multiTypeConverter struct { | ||
upstream []managedfields.TypeConverter | ||
} |
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.
Providing this composite type converter seems fine.
We have a different use case for a composite type converter in the apiserver for admission: https://github.com/kubernetes/kubernetes/blob/25e11cd1c143ef136418c33bfbbbd4f24e32e529/staging/src/k8s.io/apiserver/pkg/admission/plugin/policy/mutating/patch/typeconverter.go#L37. But the use case is different, it takes a single static type converter and an openapi client, instead of multiple underlying type converters, so it is not useful here.
I'd like to ensure we keep this implementation unexported. Maybe add some godoc to that effect?
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.
Yep makes sense, will do that
@@ -119,6 +123,7 @@ type ClientBuilder struct { | |||
withStatusSubresource []client.Object | |||
objectTracker testing.ObjectTracker | |||
interceptorFuncs *interceptor.Funcs | |||
typeConverters []managedfields.TypeConverter |
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: Can this simply be typeConverter managedfields.TypeConverter
? When multiTypeConverter
is needed, it should implement the managedfields.TypeConverter
interface and so can be initialized and used here?
@@ -160,6 +165,8 @@ func (f *ClientBuilder) WithRuntimeObjects(initRuntimeObjs ...runtime.Object) *C | |||
} | |||
|
|||
// WithObjectTracker can be optionally used to initialize this fake client with testing.ObjectTracker. | |||
// Setting this is incompatible with setting WithTypeConverters, as they are a setting on the |
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.
Enforce this in code with an assertion?
@@ -216,6 +223,18 @@ func (f *ClientBuilder) WithInterceptorFuncs(interceptorFuncs interceptor.Funcs) | |||
return f | |||
} | |||
|
|||
// WithTypeConverters sets the type converters for the fake client. The list is ordered and the first | |||
// non-erroring converter is used. | |||
// This setting is incompatible with WithObjectTracker, as the type converters are a setting on the tracker. |
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.
Enforce this in code with an assertion?
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 looks like a good approach. Left some minor feedback then LGTM.
This change adds apply support into the fake client.
This relies on the upstream support for this which is implemented in a
new FieldManagedObjectTracker. In order to support many types, a
custom
multiTypeConverter
is added.Fixes #2341