-
Notifications
You must be signed in to change notification settings - Fork 2.7k
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
Add support for service registry service binding #21618
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package io.quarkus.apicurio.registry.avro.binding; | ||
|
||
import io.quarkus.apicurio.registry.binding.ServiceRegistryBindingConverter; | ||
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.builditem.nativeimage.ServiceProviderBuildItem; | ||
|
||
class ServiceRegistryBindingExtensionProcessor { | ||
|
||
@BuildStep | ||
void registerServiceBinding(Capabilities capabilities, | ||
BuildProducer<ServiceProviderBuildItem> serviceProvider) { | ||
if (capabilities.isPresent(Capability.KUBERNETES_SERVICE_BINDING)) { | ||
serviceProvider.produce( | ||
new ServiceProviderBuildItem("io.quarkus.apicurio.registry.binding.ServiceRegistryBindingConverter", | ||
ServiceRegistryBindingConverter.class.getName())); | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -28,7 +28,12 @@ | |
<groupId>io.apicurio</groupId> | ||
<artifactId>apicurio-common-rest-client-vertx</artifactId> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>io.quarkus</groupId> | ||
secondsun marked this conversation as resolved.
Show resolved
Hide resolved
|
||
<artifactId>quarkus-kubernetes-service-binding</artifactId> | ||
<optional>true</optional> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>io.quarkus</groupId> | ||
<artifactId>quarkus-core</artifactId> | ||
|
@@ -41,6 +46,11 @@ | |
<groupId>io.quarkus</groupId> | ||
<artifactId>quarkus-vertx</artifactId> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>org.apache.commons</groupId> | ||
<artifactId>commons-lang3</artifactId> | ||
</dependency> | ||
Comment on lines
+50
to
+53
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this now needed for some reason? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes. We use it to simplify parsing here : https://github.com/quarkusio/quarkus/pull/21618/files#diff-a5c8e493cddd3831ed7120b5c27d8f03412a724cb8ca09f0828a08d2c752012bR88 |
||
</dependencies> | ||
|
||
<build> | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
package io.quarkus.apicurio.registry.binding; | ||
|
||
import java.util.ArrayList; | ||
import java.util.HashMap; | ||
import java.util.List; | ||
import java.util.Map; | ||
import java.util.Optional; | ||
import java.util.logging.Logger; | ||
|
||
import org.apache.commons.lang3.StringUtils; | ||
import org.eclipse.microprofile.config.Config; | ||
import org.eclipse.microprofile.config.ConfigProvider; | ||
|
||
import io.quarkus.kubernetes.service.binding.runtime.ServiceBinding; | ||
import io.quarkus.kubernetes.service.binding.runtime.ServiceBindingConfigSource; | ||
import io.quarkus.kubernetes.service.binding.runtime.ServiceBindingConverter; | ||
|
||
public class ServiceRegistryBindingConverter implements ServiceBindingConverter { | ||
|
||
private static Logger LOG = Logger.getLogger(ServiceRegistryBindingConverter.class.getName()); | ||
|
||
private static final String INCOMING_PREFIX = "mp.messaging.incoming."; | ||
private static final String OUTGOING_PREFIX = "mp.messaging.outgoing."; | ||
|
||
@Override | ||
public Optional<ServiceBindingConfigSource> convert(List<ServiceBinding> serviceBindings) { | ||
var matchingByType = ServiceBinding.singleMatchingByType("serviceregistry", serviceBindings); | ||
Config config = ConfigProvider.getConfig(); | ||
if (matchingByType.isEmpty()) { | ||
return Optional.empty(); | ||
} | ||
|
||
var binding = matchingByType.get(); | ||
|
||
List<String> channels = extractChannels(config); | ||
|
||
Map<String, String> properties = new HashMap<>(); | ||
|
||
String registryUrl = binding.getProperties().get("registryUrl"); | ||
if (registryUrl == null) { | ||
registryUrl = binding.getProperties().get("registryurl"); | ||
} | ||
if (registryUrl != null) { | ||
properties.put("kafka.apicurio.registry.url", registryUrl); | ||
} | ||
|
||
for (String channel : channels) { | ||
|
||
String prefix = channel; | ||
|
||
String oauthTokenUrl = binding.getProperties().get("oauthTokenUrl"); | ||
if (oauthTokenUrl == null) { | ||
oauthTokenUrl = binding.getProperties().get("oauthtokenurl"); | ||
} | ||
if (oauthTokenUrl != null) { | ||
properties.put(prefix + "apicurio.auth.service.token.endpoint", oauthTokenUrl); | ||
} | ||
|
||
String clientId = binding.getProperties().get("clientId"); | ||
if (clientId == null) { | ||
clientId = binding.getProperties().get("clientid"); | ||
} | ||
if (clientId != null) { | ||
properties.put(prefix + "apicurio.auth.client.id", clientId); | ||
} | ||
|
||
String clientSecret = binding.getProperties().get("clientSecret"); | ||
if (clientSecret == null) { | ||
clientSecret = binding.getProperties().get("clientsecret"); | ||
} | ||
if (clientSecret != null) { | ||
properties.put(prefix + "apicurio.auth.client.secret", clientSecret); | ||
} | ||
if (registryUrl != null) { | ||
properties.put(prefix + "apicurio.registry.url", registryUrl); | ||
} | ||
} | ||
|
||
return Optional.of(new ServiceBindingConfigSource("serviceregistry-k8s-service-binding-source", properties)); | ||
} | ||
|
||
private List<String> extractChannels(Config configIn) { | ||
|
||
var list = new ArrayList<String>(); | ||
|
||
for (String propertyName : configIn.getPropertyNames()) { | ||
secondsun marked this conversation as resolved.
Show resolved
Hide resolved
|
||
if (propertyName.startsWith(INCOMING_PREFIX)) { | ||
var channelAndProp = StringUtils.substringAfter(propertyName, INCOMING_PREFIX); | ||
//remove property | ||
var channelName = StringUtils.substringBefore(channelAndProp, "."); | ||
if (!StringUtils.isBlank(channelName)) | ||
list.add(INCOMING_PREFIX + channelName + "."); | ||
} else if (propertyName.startsWith(OUTGOING_PREFIX)) { | ||
var channelAndProp = StringUtils.substringAfter(propertyName, OUTGOING_PREFIX); | ||
//remove property | ||
var channelName = StringUtils.substringBefore(channelAndProp, "."); | ||
if (!StringUtils.isBlank(channelName)) | ||
list.add(OUTGOING_PREFIX + channelName + "."); | ||
} | ||
} | ||
return list; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
io.quarkus.apicurio.registry.binding.ServiceRegistryBindingConverter |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not related to that PR, but maybe we should have an SPI in the service binding extension with a dedicated build item (which will also about the capability check)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am not sure what you mean here. Can you elaborate a bit please?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Imagine that instead to do:
You do:
Then the SBO processor would consumer this new build item and register the SPI provider.
Of course to avoid a dependency on the SBO extension deployment model, we would need to create an SPI module.