Skip to content

Commit

Permalink
Print a warning if the Stork Kubernetes service discovery is used wit…
Browse files Browse the repository at this point in the history
…hout the kubernetes client

Fix quarkusio#24444
  • Loading branch information
cescoffier committed May 4, 2022
1 parent 5bb5032 commit 4e71579
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 2 deletions.
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.
}

}

0 comments on commit 4e71579

Please sign in to comment.