Skip to content

Commit

Permalink
Merge pull request #18066 from geoand/#16682
Browse files Browse the repository at this point in the history
Fail to start when service binding is enabled and Kafka boostrap servers not set
  • Loading branch information
geoand authored Jun 22, 2021
2 parents 86fdbe1 + 274dfdf commit b89c9db
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -53,15 +53,18 @@
import io.quarkus.deployment.Capabilities;
import io.quarkus.deployment.Capability;
import io.quarkus.deployment.Feature;
import io.quarkus.deployment.IsNormal;
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.Record;
import io.quarkus.deployment.builditem.AdditionalIndexedClassesBuildItem;
import io.quarkus.deployment.builditem.CombinedIndexBuildItem;
import io.quarkus.deployment.builditem.ExtensionSslNativeSupportBuildItem;
import io.quarkus.deployment.builditem.FeatureBuildItem;
import io.quarkus.deployment.builditem.IndexDependencyBuildItem;
import io.quarkus.deployment.builditem.RuntimeConfigSetupCompleteBuildItem;
import io.quarkus.deployment.builditem.nativeimage.NativeImageProxyDefinitionBuildItem;
import io.quarkus.deployment.builditem.nativeimage.NativeImageResourceBuildItem;
import io.quarkus.deployment.builditem.nativeimage.ReflectiveClassBuildItem;
Expand Down Expand Up @@ -230,6 +233,15 @@ void loadSnappyIfEnabled(KafkaRecorder recorder, KafkaBuildTimeConfig config) {
}
}

@Consume(RuntimeConfigSetupCompleteBuildItem.class)
@BuildStep(onlyIf = IsNormal.class)
@Record(ExecutionTime.RUNTIME_INIT)
void checkBoostrapServers(KafkaRecorder recorder, Capabilities capabilities) {
if (capabilities.isPresent(Capability.KUBERNETES_SERVICE_BINDING)) {
recorder.checkBoostrapServers();
}
}

private void handleOpenTracing(BuildProducer<ReflectiveClassBuildItem> reflectiveClass, Capabilities capabilities) {
//opentracing contrib kafka interceptors: https://github.com/opentracing-contrib/java-kafka-client
if (capabilities.isPresent(Capability.OPENTRACING)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@
import java.io.IOException;
import java.io.UncheckedIOException;
import java.net.URL;
import java.util.Optional;

import org.eclipse.microprofile.config.Config;
import org.eclipse.microprofile.config.ConfigProvider;
import org.xerial.snappy.OSInfo;
import org.xerial.snappy.SnappyError;
import org.xerial.snappy.SnappyErrorCode;
Expand Down Expand Up @@ -71,4 +74,16 @@ private static File extractLibraryFile(URL library, String name) {
return extractedLibFile;
}

public void checkBoostrapServers() {
Config config = ConfigProvider.getConfig();
Boolean serviceBindingEnabled = config.getValue("quarkus.kubernetes-service-binding.enabled", Boolean.class);
if (!serviceBindingEnabled) {
return;
}
Optional<String> boostrapServersOptional = config.getOptionalValue("kafka.bootstrap.servers", String.class);
if (boostrapServersOptional.isEmpty()) {
throw new IllegalStateException(
"The property 'kafka.bootstrap.servers' must be set when 'quarkus.kubernetes-service-binding.enabled' has been set to 'true'");
}
}
}

0 comments on commit b89c9db

Please sign in to comment.