Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Print a Warning when the kubernetes service discovery is used without the kubernetes client #25374

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ public interface Capability {

String QUARTZ = QUARKUS_PREFIX + "quartz";
String KUBERNETES_SERVICE_BINDING = QUARKUS_PREFIX + "kubernetes.service.binding";
String KUBERNETES_CLIENT = QUARKUS_PREFIX + "kubernetes.client";

/**
* @deprecated
Expand Down
5 changes: 5 additions & 0 deletions extensions/kubernetes-client/runtime/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,11 @@
<plugin>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-bootstrap-maven-plugin</artifactId>
<configuration>
<capabilities>
<provides>io.quarkus.kubernetes.client</provides>
</capabilities>
</configuration>
</plugin>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,18 @@

import static java.util.Arrays.asList;

import org.jboss.logging.Logger;

import io.quarkus.arc.deployment.SyntheticBeansRuntimeInitBuildItem;
import io.quarkus.bootstrap.classloading.QuarkusClassLoader;
import io.quarkus.builder.item.EmptyBuildItem;
import io.quarkus.deployment.Capabilities;
import io.quarkus.deployment.Capability;
import io.quarkus.deployment.annotations.BuildProducer;
import io.quarkus.deployment.annotations.BuildStep;
import io.quarkus.deployment.annotations.Consume;
import io.quarkus.deployment.annotations.ExecutionTime;
import io.quarkus.deployment.annotations.Produce;
import io.quarkus.deployment.annotations.Record;
import io.quarkus.deployment.builditem.RuntimeConfigSetupCompleteBuildItem;
import io.quarkus.deployment.builditem.ShutdownContextBuildItem;
Expand All @@ -20,23 +27,55 @@

public class SmallRyeStorkProcessor {

private static final String KUBERNETES_SERVICE_DISCOVERY_PROVIDER = "io.smallrye.stork.servicediscovery.kubernetes.KubernetesServiceDiscoveryProvider";
private static final Logger LOGGER = Logger.getLogger(SmallRyeStorkProcessor.class.getName());

@BuildStep
void registerServiceProviders(BuildProducer<ServiceProviderBuildItem> services) {
void registerServiceProviders(BuildProducer<ServiceProviderBuildItem> services, Capabilities capabilities) {
services.produce(new ServiceProviderBuildItem(io.smallrye.stork.spi.config.ConfigProvider.class.getName(),
StorkConfigProvider.class.getName()));

for (Class<?> providerClass : asList(LoadBalancerLoader.class, ServiceDiscoveryLoader.class)) {
services.produce(ServiceProviderBuildItem.allProvidersFromClassPath(providerClass.getName()));
}
}

/**
* This build step is the fix for https://github.com/quarkusio/quarkus/issues/24444.
* Because Stork itself cannot depend on Quarkus, and we do not want to have extensions for all the service
* discovery and load-balancer providers, we work around the issue by detecting when the kubernetes service
* discovery is used and if the kubernetes extension is used.
*/
@BuildStep
@Produce(AlwaysBuildItem.class)
void checkThatTheKubernetesExtensionIsUsedWhenKubernetesServiceDiscoveryInOnTheClasspath(Capabilities capabilities) {
if (QuarkusClassLoader.isClassPresentAtRuntime(KUBERNETES_SERVICE_DISCOVERY_PROVIDER)) {
if (!capabilities.isPresent(Capability.KUBERNETES_CLIENT)) {
LOGGER.warn(
"The application is using the Stork Kubernetes Service Discovery provider but does not depend on the `quarkus-kubernetes-client` extension. "
+
"It is highly recommended to use the `io.quarkus:quarkus-kubernetes-client` extension with the Kubernetes service discovery. \n"
+
"To add this extension:" +
"\n - with the quarkus CLI, run: `quarkus ext add io.quarkus:quarkus-kubernetes-client`" +
"\n - with Apache Maven, run: `./mvnw quarkus:add-extension -Dextensions=\"io.quarkus:quarkus-kubernetes-client\"`"
+
"\n - or just add the `io.quarkus:quarkus-kubernetes-client` dependency to the project");
}
}
}

@BuildStep
@Record(ExecutionTime.RUNTIME_INIT)
@Consume(AlwaysBuildItem.class)
@Consume(RuntimeConfigSetupCompleteBuildItem.class)
@Consume(SyntheticBeansRuntimeInitBuildItem.class)
void initializeStork(SmallRyeStorkRecorder storkRecorder, ShutdownContextBuildItem shutdown, VertxBuildItem vertx,
StorkConfiguration configuration) {
storkRecorder.initialize(shutdown, vertx.getVertx(), configuration);
}

private static final class AlwaysBuildItem extends EmptyBuildItem {
// Just here to be sure we run the `checkThatTheKubernetesExtensionIsUsedWhenKubernetesServiceDiscoveryInOnTheClasspath` build step.
}

}