Skip to content

Surprising closing of caller-supplied clients #2562

Closed
@tombentley

Description

@tombentley

Bug Report

What did you do?

I wrote a test class with 2 @Test methods using a LocallyRunOperatorExtension with an externally-given kubernetes client:

    @RegisterExtension
    LocallyRunOperatorExtension extension = LocallyRunOperatorExtension.builder()
            .withKubernetesClient(client)
            .withReconciler(ProxyReconciler.class)
            .build();

What did you expect to see?

Both test methods to be executed

What did you see instead? Under which circumstances?

The first-executed @Test method worked fine, but the second failed in AbstractOperatorExtension.beforeEach() because the previously-executed afterEach closed the kubernetes client given to the extension via Operator.stop.

Here's the stack where the client gets closed:

doClose:254, OkHttpClientImpl (io.fabric8.kubernetes.client.okhttp)
close:300, StandardHttpClient (io.fabric8.kubernetes.client.http)
close:160, BaseClient (io.fabric8.kubernetes.client.impl)
stop:181, Operator (io.javaoperatorsdk.operator)
stop:189, Operator (io.javaoperatorsdk.operator)
after:201, LocallyRunOperatorExtension (io.javaoperatorsdk.operator.junit)
afterEachImpl:178, AbstractOperatorExtension (io.javaoperatorsdk.operator.junit)
afterEach:89, AbstractOperatorExtension (io.javaoperatorsdk.operator.junit)

This is surprising to me because my default assumption (when passing a client instance which I've instantiated to some API) is that I remain responsible for closing that client. There is no javadoc to say exactly what the contract of the withKubernetesClient(client) method actually is.

Environment

N/A

Possible Solution

Either:

  • Don't close the client passed via withKubernetesClient, and document the expectation that it's the callers job to close it.
  • Or document that responsibility for closing the client passes to the extension when withKubernetesClient is called.

Additional context

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions