Skip to content

Commit

Permalink
adds a method to customize KubernetesMockServer clients
Browse files Browse the repository at this point in the history
More completely addresses #5293
  • Loading branch information
shawkins authored and manusa committed Jul 21, 2023
1 parent efece3a commit 71198a2
Showing 1 changed file with 11 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
import java.util.Map;
import java.util.Objects;
import java.util.Queue;
import java.util.function.Consumer;
import java.util.regex.Pattern;

public class KubernetesMockServer extends DefaultMockServer implements Resetable, CustomResourceAware {
Expand Down Expand Up @@ -120,17 +121,23 @@ public String[] getRootPaths() {
}

public NamespacedKubernetesClient createClient() {
return createClient(null);
return createClient(ignored -> {
});
}

public NamespacedKubernetesClient createClient(HttpClient.Factory factory) {
KubernetesClient client = new KubernetesClientBuilder().withConfig(getMockConfiguration()).withHttpClientFactory(factory)
.build();
public NamespacedKubernetesClient createClient(Consumer<KubernetesClientBuilder> customizer) {
KubernetesClientBuilder builder = new KubernetesClientBuilder().withConfig(getMockConfiguration());
customizer.accept(builder);
KubernetesClient client = builder.build();
client.adapt(BaseClient.class)
.setMatchingGroupPredicate(s -> unsupportedPatterns.stream().noneMatch(p -> p.matcher(s).find()));
return client.adapt(NamespacedKubernetesClient.class);
}

public NamespacedKubernetesClient createClient(HttpClient.Factory factory) {
return createClient(builder -> builder.withHttpClientFactory(factory));
}

/**
* Replace the current {@link VersionInfo} instance.
*
Expand Down

0 comments on commit 71198a2

Please sign in to comment.