Skip to content

Commit

Permalink
feat: preserve static KubernetesSerialization instance
Browse files Browse the repository at this point in the history
Signed-off-by: Marc Nuri <[email protected]>
  • Loading branch information
manusa committed Jun 2, 2023
1 parent e44baba commit e7ad0b7
Showing 1 changed file with 18 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,31 @@

import org.eclipse.microprofile.config.ConfigProvider;

import com.fasterxml.jackson.databind.ObjectMapper;

import io.fabric8.kubernetes.client.Config;
import io.fabric8.kubernetes.client.ConfigBuilder;
import io.fabric8.kubernetes.client.KubernetesClient;
import io.fabric8.kubernetes.client.KubernetesClientBuilder;
import io.fabric8.kubernetes.client.utils.KubernetesSerialization;
import io.quarkus.runtime.TlsConfig;

public class KubernetesClientUtils {

private static final String PREFIX = "quarkus.kubernetes-client.";
private static final KubernetesSerialization SERIALIZATION = new KubernetesSerialization(new ObjectMapper(), true);
static {
// TODO: dirty workaround to register KubernetesResource classes for deserialization during class loading
//Further refinements to be implemented in Kubernetes Client to allow for a more elegant solution
SERIALIZATION.getRegisteredKubernetesResource("", "");
}

private KubernetesClientUtils() {
}

private static KubernetesClientBuilder kubernetesClientBuilder() {
return new KubernetesClientBuilder().withKubernetesSerialization(SERIALIZATION);
}

public static Config createConfig(KubernetesClientBuildConfig buildConfig, TlsConfig tlsConfig) {
Config base = Config.autoConfigure(null);
Expand Down Expand Up @@ -48,13 +64,13 @@ public static Config createConfig(KubernetesClientBuildConfig buildConfig, TlsCo
}

public static KubernetesClient createClient(KubernetesClientBuildConfig buildConfig, TlsConfig tlsConfig) {
return new KubernetesClientBuilder().withConfig(createConfig(buildConfig, tlsConfig)).build();
return kubernetesClientBuilder().withConfig(createConfig(buildConfig, tlsConfig)).build();
}

public static KubernetesClient createClient() {
org.eclipse.microprofile.config.Config config = ConfigProvider.getConfig();
Config base = Config.autoConfigure(null);
return new KubernetesClientBuilder().withConfig(new ConfigBuilder()
return kubernetesClientBuilder().withConfig(new ConfigBuilder()
.withTrustCerts(config.getOptionalValue(PREFIX + "trust-certs", Boolean.class).orElse(base.isTrustCerts()))
.withWatchReconnectLimit(config.getOptionalValue(PREFIX + "watch-reconnect-limit", Integer.class)
.orElse(base.getWatchReconnectLimit()))
Expand Down

0 comments on commit e7ad0b7

Please sign in to comment.