From 71198a26728a33475cc6af233a64925ff2116b4c Mon Sep 17 00:00:00 2001 From: Steve Hawkins Date: Thu, 20 Jul 2023 14:06:35 -0400 Subject: [PATCH] adds a method to customize KubernetesMockServer clients More completely addresses #5293 --- .../client/server/mock/KubernetesMockServer.java | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/junit/kubernetes-server-mock/src/main/java/io/fabric8/kubernetes/client/server/mock/KubernetesMockServer.java b/junit/kubernetes-server-mock/src/main/java/io/fabric8/kubernetes/client/server/mock/KubernetesMockServer.java index 690f5fc2ff5..33cebdf1a79 100644 --- a/junit/kubernetes-server-mock/src/main/java/io/fabric8/kubernetes/client/server/mock/KubernetesMockServer.java +++ b/junit/kubernetes-server-mock/src/main/java/io/fabric8/kubernetes/client/server/mock/KubernetesMockServer.java @@ -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 { @@ -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 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. *