diff --git a/operator/src/main/java/org/bf2/operator/managers/IngressControllerManager.java b/operator/src/main/java/org/bf2/operator/managers/IngressControllerManager.java index cef34df75..5f8e7bf14 100644 --- a/operator/src/main/java/org/bf2/operator/managers/IngressControllerManager.java +++ b/operator/src/main/java/org/bf2/operator/managers/IngressControllerManager.java @@ -6,6 +6,8 @@ import io.fabric8.kubernetes.api.model.GenericKubernetesResource; import io.fabric8.kubernetes.api.model.HasMetadata; import io.fabric8.kubernetes.api.model.LabelSelector; +import io.fabric8.kubernetes.api.model.LoadBalancerIngress; +import io.fabric8.kubernetes.api.model.LoadBalancerStatus; import io.fabric8.kubernetes.api.model.Node; import io.fabric8.kubernetes.api.model.NodeList; import io.fabric8.kubernetes.api.model.Pod; @@ -14,6 +16,7 @@ import io.fabric8.kubernetes.api.model.ResourceRequirements; import io.fabric8.kubernetes.api.model.ResourceRequirementsBuilder; import io.fabric8.kubernetes.api.model.Service; +import io.fabric8.kubernetes.api.model.ServiceStatus; import io.fabric8.kubernetes.api.model.TolerationBuilder; import io.fabric8.kubernetes.api.model.apps.Deployment; import io.fabric8.kubernetes.client.dsl.FilterWatchListDeletable; @@ -109,12 +112,6 @@ public class IngressControllerManager { protected static final String WORKER_NODE_LABEL = "node-role.kubernetes.io/worker"; - /** - * Domain part prefixed to domain reported on IngressController status. The CNAME DNS records - * need to point to a sub-domain on the IngressController domain, so we just add this. - */ - private static final String ROUTER_SUBDOMAIN = "ingresscontroller."; - /** * Predicate that will return true if the input string looks like a broker resource name. */ @@ -656,11 +653,13 @@ private int numReplicasForConnectionDemand(double connectionDemand) { } private String getIngressControllerDomain(String ingressControllerName) { - return ingressControllerInformer.getList().stream() - .filter(ic -> ic.getMetadata().getName().equals(ingressControllerName)) - .map(ic -> ROUTER_SUBDOMAIN + (ic.getStatus() != null ? ic.getStatus().getDomain() : ic.getSpec().getDomain())) - .findFirst() - .orElse(""); + return Optional.ofNullable(informerManager.getLocalService(INGRESS_ROUTER_NAMESPACE, "router-" + ingressControllerName)) + .map(Service::getStatus) + .map(ServiceStatus::getLoadBalancer) + .map(LoadBalancerStatus::getIngress) + .flatMap(l -> l.stream().findFirst()) + .map(LoadBalancerIngress::getHostname) + .orElse(null); } private Stream routesFor(ManagedKafka managedKafka) { diff --git a/operator/src/test/java/org/bf2/operator/managers/IngressControllerManagerTest.java b/operator/src/test/java/org/bf2/operator/managers/IngressControllerManagerTest.java index 699fd06ff..4602d38f0 100644 --- a/operator/src/test/java/org/bf2/operator/managers/IngressControllerManagerTest.java +++ b/operator/src/test/java/org/bf2/operator/managers/IngressControllerManagerTest.java @@ -1,5 +1,6 @@ package org.bf2.operator.managers; +import io.fabric8.kubernetes.api.model.LoadBalancerIngressBuilder; import io.fabric8.kubernetes.api.model.Node; import io.fabric8.kubernetes.api.model.NodeBuilder; import io.fabric8.kubernetes.api.model.Pod; @@ -336,7 +337,28 @@ void testGetManagedKafkaRoutesFor() { suffixes.stream().map(suffixToPod).forEach(pod -> openShiftClient.pods().inNamespace(mkName).createOrReplace(pod)); suffixes.stream().map(suffixToNode).forEach(node -> openShiftClient.nodes().createOrReplace(node)); + final Function suffixToRouterService = suffix -> new ServiceBuilder() + .withNewMetadata() + .withName("router-" + suffix) + .endMetadata() + .withNewStatus() + .withNewLoadBalancer() + .withIngress(new LoadBalancerIngressBuilder() + .withHostname(suffix + "-loadbalancer.provider.com") + .build()) + .endLoadBalancer() + .endStatus() + .build(); + + List.of("kas", "kas-zone-broker-0", "kas-zone-broker-1", "kas-zone-broker-2") + .stream() + .map(suffixToRouterService) + .forEach(svc -> openShiftClient.services() + .inNamespace(IngressControllerManager.INGRESS_ROUTER_NAMESPACE) + .createOrReplace(svc)); + ingressControllerManager.reconcileIngressControllers(); + List managedKafkaRoutes = ingressControllerManager.getManagedKafkaRoutesFor(mk); assertEquals(5, managedKafkaRoutes.size()); @@ -348,23 +370,23 @@ void testGetManagedKafkaRoutesFor() { assertEquals("admin-server", managedKafkaRoutes.get(0).getName()); assertEquals("admin-server", managedKafkaRoutes.get(0).getPrefix()); - assertEquals("ingresscontroller.kas.testing.domain.tld", managedKafkaRoutes.get(0).getRouter()); + assertEquals("kas-loadbalancer.provider.com", managedKafkaRoutes.get(0).getRouter()); assertEquals("bootstrap", managedKafkaRoutes.get(1).getName()); assertEquals("", managedKafkaRoutes.get(1).getPrefix()); - assertEquals("ingresscontroller.kas.testing.domain.tld", managedKafkaRoutes.get(1).getRouter()); + assertEquals("kas-loadbalancer.provider.com", managedKafkaRoutes.get(1).getRouter()); assertEquals("broker-0", managedKafkaRoutes.get(2).getName()); assertEquals("broker-0", managedKafkaRoutes.get(2).getPrefix()); - assertEquals("ingresscontroller.kas-zone-broker-0.testing.domain.tld", managedKafkaRoutes.get(2).getRouter()); + assertEquals("kas-zone-broker-0-loadbalancer.provider.com", managedKafkaRoutes.get(2).getRouter()); assertEquals("broker-1", managedKafkaRoutes.get(3).getName()); assertEquals("broker-1", managedKafkaRoutes.get(3).getPrefix()); - assertEquals("ingresscontroller.kas-zone-broker-1.testing.domain.tld", managedKafkaRoutes.get(3).getRouter()); + assertEquals("kas-zone-broker-1-loadbalancer.provider.com", managedKafkaRoutes.get(3).getRouter()); assertEquals("broker-2", managedKafkaRoutes.get(4).getName()); assertEquals("broker-2", managedKafkaRoutes.get(4).getPrefix()); - assertEquals("ingresscontroller.kas-zone-broker-2.testing.domain.tld", managedKafkaRoutes.get(4).getRouter()); + assertEquals("kas-zone-broker-2-loadbalancer.provider.com", managedKafkaRoutes.get(4).getRouter()); } @Test