Skip to content

Commit

Permalink
Do not produce KubernetesClient if we have OpenShiftClient available
Browse files Browse the repository at this point in the history
  • Loading branch information
FroMage committed Feb 10, 2021
1 parent 30c0760 commit ada44ba
Show file tree
Hide file tree
Showing 6 changed files with 53 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,8 @@ public enum Capability {
*/
SMALLRYE_OPENTRACING,
SPRING_WEB,
SMALLRYE_OPENAPI;
SMALLRYE_OPENAPI,
OPENSHIFT_CLIENT;

/**
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
import org.jboss.logging.Logger;

import io.quarkus.arc.deployment.AdditionalBeanBuildItem;
import io.quarkus.deployment.Capabilities;
import io.quarkus.deployment.Capability;
import io.quarkus.deployment.Feature;
import io.quarkus.deployment.annotations.BuildProducer;
import io.quarkus.deployment.annotations.BuildStep;
Expand All @@ -24,6 +26,7 @@
import io.quarkus.deployment.util.JandexUtil;
import io.quarkus.jackson.deployment.IgnoreJsonDeserializeClassBuildItem;
import io.quarkus.kubernetes.client.runtime.KubernetesClientProducer;
import io.quarkus.kubernetes.client.runtime.KubernetesConfigProducer;
import io.quarkus.kubernetes.spi.KubernetesRoleBindingBuildItem;

public class KubernetesClientProcessor {
Expand All @@ -38,10 +41,21 @@ public class KubernetesClientProcessor {

private static final Logger log = Logger.getLogger(KubernetesClientProcessor.class.getName());

@BuildStep
public void registerBeanProducers(BuildProducer<AdditionalBeanBuildItem> additionalBeanBuildItemBuildItem,
Capabilities capabilities) {
// wire up the Config bean support
additionalBeanBuildItemBuildItem.produce(AdditionalBeanBuildItem.unremovableOf(KubernetesConfigProducer.class));
// do not register our client producer if the openshift client is present, because it provides it too
if (capabilities.isMissing(Capability.OPENSHIFT_CLIENT)) {
// wire up the KubernetesClient bean support
additionalBeanBuildItemBuildItem.produce(AdditionalBeanBuildItem.unremovableOf(KubernetesClientProducer.class));
}
}

@BuildStep
public void process(ApplicationIndexBuildItem applicationIndex, CombinedIndexBuildItem combinedIndexBuildItem,
BuildProducer<ExtensionSslNativeSupportBuildItem> sslNativeSupport,
BuildProducer<AdditionalBeanBuildItem> additionalBeanBuildItemBuildItem,
BuildProducer<FeatureBuildItem> featureProducer,
BuildProducer<ReflectiveClassBuildItem> reflectiveClasses,
BuildProducer<ReflectiveHierarchyBuildItem> reflectiveHierarchies,
Expand Down Expand Up @@ -125,9 +139,6 @@ public void process(ApplicationIndexBuildItem applicationIndex, CombinedIndexBui

// Enable SSL support by default
sslNativeSupport.produce(new ExtensionSslNativeSupportBuildItem(Feature.KUBERNETES_CLIENT));

// wire up the KubernetesClient bean support
additionalBeanBuildItemBuildItem.produce(AdditionalBeanBuildItem.unremovableOf(KubernetesClientProducer.class));
}

private void findWatchedClasses(final DotName implementor, final ApplicationIndexBuildItem applicationIndex,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,12 @@
import io.fabric8.kubernetes.client.DefaultKubernetesClient;
import io.fabric8.kubernetes.client.KubernetesClient;
import io.quarkus.arc.DefaultBean;
import io.quarkus.runtime.TlsConfig;

@Singleton
public class KubernetesClientProducer {

private KubernetesClient client;

@DefaultBean
@Singleton
@Produces
public Config config(KubernetesClientBuildConfig buildConfig, TlsConfig tlsConfig) {
return KubernetesClientUtils.createConfig(buildConfig, tlsConfig);
}

@DefaultBean
@Singleton
@Produces
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package io.quarkus.kubernetes.client.runtime;

import javax.enterprise.inject.Produces;
import javax.inject.Singleton;

import io.fabric8.kubernetes.client.Config;
import io.quarkus.arc.DefaultBean;
import io.quarkus.runtime.TlsConfig;

@Singleton
public class KubernetesConfigProducer {

@DefaultBean
@Singleton
@Produces
public Config config(KubernetesClientBuildConfig buildConfig, TlsConfig tlsConfig) {
return KubernetesClientUtils.createConfig(buildConfig, tlsConfig);
}
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
package io.quarkus.openshift.client.deployment;

import io.quarkus.arc.deployment.AdditionalBeanBuildItem;
import io.quarkus.deployment.Capability;
import io.quarkus.deployment.Feature;
import io.quarkus.deployment.annotations.BuildProducer;
import io.quarkus.deployment.annotations.BuildStep;
import io.quarkus.deployment.builditem.CapabilityBuildItem;
import io.quarkus.deployment.builditem.FeatureBuildItem;
import io.quarkus.it.openshift.client.runtime.OpenShiftClientProducer;

Expand All @@ -19,4 +21,9 @@ public void process(BuildProducer<AdditionalBeanBuildItem> additionalBeanBuildIt
public FeatureBuildItem feature() {
return new FeatureBuildItem(Feature.OPENSHIFT_CLIENT);
}

@BuildStep
public CapabilityBuildItem capability() {
return new CapabilityBuildItem(Capability.OPENSHIFT_CLIENT);
}
}
Original file line number Diff line number Diff line change
@@ -1,24 +1,30 @@
package io.quarkus.it.openshift.client;

import javax.inject.Inject;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.core.Response;

import io.fabric8.kubernetes.client.KubernetesClient;
import io.fabric8.openshift.client.OpenShiftClient;

@Path("/route")
public class Routes {

private final OpenShiftClient openshiftClient;
// make sure we can inject both aspects of it
@Inject
KubernetesClient kubernetesClient;

public Routes(OpenShiftClient openshiftClient) {
this.openshiftClient = openshiftClient;
}
@Inject
OpenShiftClient openshiftClient;

@GET
@Path("/{namespace}")
public Response routes(@PathParam("namespace") String namespace) {
if (kubernetesClient != openshiftClient) {
return Response.serverError().entity("The clients are different").build();
}
return Response.ok(openshiftClient.routes().inNamespace(namespace).list().getItems()).build();
}
}

0 comments on commit ada44ba

Please sign in to comment.