controller-runtime icon indicating copy to clipboard operation
controller-runtime copied to clipboard

Make fakeClient set `metadata.UID` and `metadata.creationTimestamp` when objects are created?

Open matteoolivi opened this issue 2 years ago • 0 comments

Me and @pleic have a reconciler that relies on metadata.UID being set on the API objects it manages, and soon we'll also need metadata.CreationTimestamp.

We are writing unit tests that use the fake client, but the fake client doesn't set metadata.UID and metadata.CreationTimestamp when objects are created, so we can't actually use it.

Spinning up a real API server and etcd via envtest is not an option for us because it's slow and makes the tests non-deterministic (more details are given in this comment).

The goal of this issue is to assess whether the controller-runtime maintainers would accept a PR to make the fake client set metadata.UID and metadata.CreationTimestamp when API objects are created. If that's the case, we'd be happy to implement said features and open the relevant PRs.

We know that we can get the behavior we want by wrapping the fake client with our own fake client implementation, but we'd rather not maintain that code in our codebase, and metadata.UID and metadata.CreationTimestamp are ubiquitous metadata fields, so in our opinion it makes sense (besides being convenient) that the fake client sets them. Moreover, intuitively I'd say that setting them is much easier than setting other fields that the fake client already handles (such as metadata.ResourceVersion which needs to be parsed and increased on every update), so the added complexity would be minimal.

matteoolivi avatar Oct 11 '22 18:10 matteoolivi