Skip to content

Allow injection of java.time.Clock in KubernetesMockServer #7019

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

Open
KasperWolsink99 opened this issue Apr 23, 2025 · 0 comments
Open

Allow injection of java.time.Clock in KubernetesMockServer #7019

KasperWolsink99 opened this issue Apr 23, 2025 · 0 comments
Labels
component/kubernetes-server-mock Deals with the kubernetes-server-mock directory mainly enhancement

Comments

@KasperWolsink99
Copy link

Is your enhancement related to a problem? Please describe

When running KubernetesMockServer in crud mode it depends directly on the system time. For example, in junit/kubernetes-server-mock/src/main/java/io/fabric8/kubernetes/client/server/mock/crud/PostHandler.java at line 88-89 we set the creationTimestamp of a resource:

    resource.getMetadata().setCreationTimestamp(
  ZonedDateTime.now(ZoneOffset.UTC).truncatedTo(ChronoUnit.SECONDS).format(DateTimeFormatter.ISO_INSTANT));

As you can see this depends directly on the system time, which you have little control over in your tests.
This is just an example, but this direct dependency on the system time happens on more occasions.

Describe the solution you'd like

It would be great if we could inject an instance of java.time.Clock somehow and use that to generate timestamps so that we have total control over it in our tests instead of depending on the system time.

I think this change shouldn't be too complex. I am open to contributing it myself if others agree.

Describe alternatives you've considered

No response

Additional context

No response

@manusa manusa added enhancement component/kubernetes-server-mock Deals with the kubernetes-server-mock directory mainly labels Apr 23, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component/kubernetes-server-mock Deals with the kubernetes-server-mock directory mainly enhancement
Projects
None yet
Development

No branches or pull requests

2 participants