Skip to content

Commit

Permalink
Ensure that k8s client created from quarkus-kubernetes-config
Browse files Browse the repository at this point in the history
Relates to: quarkusio#18973
  • Loading branch information
geoand committed Mar 21, 2023
1 parent 187ca4b commit da29dd5
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import io.quarkus.deployment.annotations.Record;
import io.quarkus.deployment.builditem.LogCategoryBuildItem;
import io.quarkus.deployment.builditem.RunTimeConfigurationSourceValueBuildItem;
import io.quarkus.deployment.builditem.ShutdownContextBuildItem;
import io.quarkus.kubernetes.client.runtime.KubernetesClientBuildConfig;
import io.quarkus.kubernetes.config.runtime.KubernetesConfigBuildTimeConfig;
import io.quarkus.kubernetes.config.runtime.KubernetesConfigRecorder;
Expand All @@ -35,9 +36,10 @@ public class KubernetesConfigProcessor {
public RunTimeConfigurationSourceValueBuildItem configure(KubernetesConfigRecorder recorder,
KubernetesConfigSourceConfig config, KubernetesConfigBuildTimeConfig buildTimeConfig,
KubernetesClientBuildConfig clientConfig,
ShutdownContextBuildItem shutdownContextBuildItem,
TlsConfig tlsConfig) {
return new RunTimeConfigurationSourceValueBuildItem(
recorder.configSources(config, buildTimeConfig, clientConfig, tlsConfig));
recorder.configSources(config, buildTimeConfig, clientConfig, tlsConfig, shutdownContextBuildItem));
}

@BuildStep
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,11 @@
import org.eclipse.microprofile.config.spi.ConfigSourceProvider;
import org.jboss.logging.Logger;

import io.fabric8.kubernetes.client.KubernetesClient;
import io.quarkus.kubernetes.client.runtime.KubernetesClientBuildConfig;
import io.quarkus.kubernetes.client.runtime.KubernetesClientUtils;
import io.quarkus.runtime.RuntimeValue;
import io.quarkus.runtime.ShutdownContext;
import io.quarkus.runtime.TlsConfig;
import io.quarkus.runtime.annotations.Recorder;
import io.quarkus.runtime.configuration.AbstractRawDefaultConfigSource;
Expand All @@ -26,15 +28,23 @@ public class KubernetesConfigRecorder {
public RuntimeValue<ConfigSourceProvider> configSources(KubernetesConfigSourceConfig kubernetesConfigSourceConfig,
KubernetesConfigBuildTimeConfig buildTimeConfig,
KubernetesClientBuildConfig clientConfig,
TlsConfig tlsConfig) {
TlsConfig tlsConfig,
ShutdownContext context) {
if ((!kubernetesConfigSourceConfig.enabled && !buildTimeConfig.secretsEnabled) || isExplicitlyDisabled()) {
log.debug(
"No attempt will be made to obtain configuration from the Kubernetes API server because the functionality has been disabled via configuration");
return emptyRuntimeValue();
}

KubernetesClient client = KubernetesClientUtils.createClient(clientConfig, tlsConfig);
context.addShutdownTask(new Runnable() {
@Override
public void run() {
client.close();
}
});
return new RuntimeValue<>(new KubernetesConfigSourceProvider(kubernetesConfigSourceConfig, buildTimeConfig,
KubernetesClientUtils.createClient(clientConfig, tlsConfig)));
client));
}

private boolean isExplicitlyDisabled() {
Expand Down

0 comments on commit da29dd5

Please sign in to comment.