From e1f1c6565d0ce4ed4df473f3e1072ea2047555d3 Mon Sep 17 00:00:00 2001 From: Georgios Andrianakis Date: Tue, 7 Feb 2023 15:24:00 +0200 Subject: [PATCH 1/2] Disable Vertx DNS resolver when deploying to kubernetes Fixes: #30951 --- .../runtime/QuarkusHttpClientFactory.java | 26 ++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/extensions/kubernetes-client/runtime/src/main/java/io/quarkus/kubernetes/client/runtime/QuarkusHttpClientFactory.java b/extensions/kubernetes-client/runtime/src/main/java/io/quarkus/kubernetes/client/runtime/QuarkusHttpClientFactory.java index 383a736a0d417..799fcddde8c45 100644 --- a/extensions/kubernetes-client/runtime/src/main/java/io/quarkus/kubernetes/client/runtime/QuarkusHttpClientFactory.java +++ b/extensions/kubernetes-client/runtime/src/main/java/io/quarkus/kubernetes/client/runtime/QuarkusHttpClientFactory.java @@ -1,11 +1,14 @@ package io.quarkus.kubernetes.client.runtime; +import static io.vertx.core.spi.resolver.ResolverProvider.DISABLE_DNS_RESOLVER_PROP_NAME; + import jakarta.enterprise.inject.spi.CDI; import io.fabric8.kubernetes.client.Config; import io.fabric8.kubernetes.client.http.HttpClient; import io.fabric8.kubernetes.client.vertx.VertxHttpClientBuilder; import io.vertx.core.Vertx; +import io.vertx.core.VertxOptions; public class QuarkusHttpClientFactory implements io.fabric8.kubernetes.client.http.HttpClient.Factory { @@ -17,8 +20,29 @@ public QuarkusHttpClientFactory() { try { this.vertx = CDI.current().select(Vertx.class).get(); } catch (Exception e) { - this.vertx = Vertx.vertx(); + this.vertx = createVertxInstance(); + } + } + + private Vertx createVertxInstance() { + // We must disable the async DNS resolver as it can cause issues when resolving the Vault instance. + // This is done using the DISABLE_DNS_RESOLVER_PROP_NAME system property. + // The DNS resolver used by vert.x is configured during the (synchronous) initialization. + // So, we just need to disable the async resolver around the Vert.x instance creation. + String originalValue = System.getProperty(DISABLE_DNS_RESOLVER_PROP_NAME); + Vertx vertx; + try { + System.setProperty(DISABLE_DNS_RESOLVER_PROP_NAME, "true"); + vertx = Vertx.vertx(new VertxOptions()); + } finally { + // Restore the original value + if (originalValue == null) { + System.clearProperty(DISABLE_DNS_RESOLVER_PROP_NAME); + } else { + System.setProperty(DISABLE_DNS_RESOLVER_PROP_NAME, originalValue); + } } + return vertx; } @Override From 6cac46217788347ae8cbdea539c63cd5c6c5c391 Mon Sep 17 00:00:00 2001 From: Georgios Andrianakis Date: Tue, 7 Feb 2023 17:14:29 +0200 Subject: [PATCH 2/2] Move QuarkusHttpClientFactory to internal k8s client module This ensures that the client will always use our factory, whether it's being used in deployment or runtime code. --- .../kubernetes/client/runtime/QuarkusHttpClientFactory.java | 2 +- .../io.fabric8.kubernetes.client.http.HttpClient$Factory | 0 2 files changed, 1 insertion(+), 1 deletion(-) rename extensions/kubernetes-client/{runtime => runtime-internal}/src/main/java/io/quarkus/kubernetes/client/runtime/QuarkusHttpClientFactory.java (95%) rename extensions/kubernetes-client/{runtime => runtime-internal}/src/main/resources/META-INF/services/io.fabric8.kubernetes.client.http.HttpClient$Factory (100%) diff --git a/extensions/kubernetes-client/runtime/src/main/java/io/quarkus/kubernetes/client/runtime/QuarkusHttpClientFactory.java b/extensions/kubernetes-client/runtime-internal/src/main/java/io/quarkus/kubernetes/client/runtime/QuarkusHttpClientFactory.java similarity index 95% rename from extensions/kubernetes-client/runtime/src/main/java/io/quarkus/kubernetes/client/runtime/QuarkusHttpClientFactory.java rename to extensions/kubernetes-client/runtime-internal/src/main/java/io/quarkus/kubernetes/client/runtime/QuarkusHttpClientFactory.java index 799fcddde8c45..a02f597c89bdf 100644 --- a/extensions/kubernetes-client/runtime/src/main/java/io/quarkus/kubernetes/client/runtime/QuarkusHttpClientFactory.java +++ b/extensions/kubernetes-client/runtime-internal/src/main/java/io/quarkus/kubernetes/client/runtime/QuarkusHttpClientFactory.java @@ -10,7 +10,7 @@ import io.vertx.core.Vertx; import io.vertx.core.VertxOptions; -public class QuarkusHttpClientFactory implements io.fabric8.kubernetes.client.http.HttpClient.Factory { +public class QuarkusHttpClientFactory implements HttpClient.Factory { private Vertx vertx; diff --git a/extensions/kubernetes-client/runtime/src/main/resources/META-INF/services/io.fabric8.kubernetes.client.http.HttpClient$Factory b/extensions/kubernetes-client/runtime-internal/src/main/resources/META-INF/services/io.fabric8.kubernetes.client.http.HttpClient$Factory similarity index 100% rename from extensions/kubernetes-client/runtime/src/main/resources/META-INF/services/io.fabric8.kubernetes.client.http.HttpClient$Factory rename to extensions/kubernetes-client/runtime-internal/src/main/resources/META-INF/services/io.fabric8.kubernetes.client.http.HttpClient$Factory