use of com.marcnuri.yakc.model.io.k8s.api.networking.v1.Ingress in project strimzi by strimzi.
the class KafkaClusterTest method testExternalIngressClass.
@ParallelTest
public void testExternalIngressClass() {
GenericKafkaListenerConfigurationBroker broker0 = new GenericKafkaListenerConfigurationBrokerBuilder().withHost("my-broker-kafka-0.com").withBroker(0).build();
GenericKafkaListenerConfigurationBroker broker1 = new GenericKafkaListenerConfigurationBrokerBuilder().withHost("my-broker-kafka-1.com").withBroker(1).build();
GenericKafkaListenerConfigurationBroker broker2 = new GenericKafkaListenerConfigurationBrokerBuilder().withHost("my-broker-kafka-2.com").withBroker(2).build();
Kafka kafkaAssembly = new KafkaBuilder(ResourceUtils.createKafka(namespace, cluster, replicas, image, healthDelay, healthTimeout, jmxMetricsConfig, configuration, emptyMap())).editSpec().editKafka().withListeners(new GenericKafkaListenerBuilder().withName("external").withPort(9094).withType(KafkaListenerType.INGRESS).withTls(true).withNewConfiguration().withIngressClass("nginx-internal").withNewBootstrap().withHost("my-kafka-bootstrap.com").withAnnotations(Collections.singletonMap("dns-annotation", "my-kafka-bootstrap.com")).endBootstrap().withBrokers(broker0, broker1, broker2).endConfiguration().build()).endKafka().endSpec().build();
KafkaCluster kc = KafkaCluster.fromCrd(Reconciliation.DUMMY_RECONCILIATION, kafkaAssembly, VERSIONS);
// Check bootstrap ingress
Ingress bing = kc.generateExternalBootstrapIngresses().get(0);
assertThat(bing.getSpec().getIngressClassName(), is("nginx-internal"));
io.fabric8.kubernetes.api.model.networking.v1beta1.Ingress bingV1Beta1 = kc.generateExternalBootstrapIngressesV1Beta1().get(0);
assertThat(bingV1Beta1.getSpec().getIngressClassName(), is("nginx-internal"));
// Check per pod ingress
for (int i = 0; i < replicas; i++) {
Ingress ing = kc.generateExternalIngresses(i).get(0);
assertThat(ing.getSpec().getIngressClassName(), is("nginx-internal"));
io.fabric8.kubernetes.api.model.networking.v1beta1.Ingress ingV1Beta1 = kc.generateExternalIngressesV1Beta1(i).get(0);
assertThat(ingV1Beta1.getSpec().getIngressClassName(), is("nginx-internal"));
}
}
use of com.marcnuri.yakc.model.io.k8s.api.networking.v1.Ingress in project strimzi by strimzi.
the class IngressOperator method isIngressAddressReady.
/**
* Checks if the Ingress already has assigned ingress address.
*
* @param namespace The namespace.
* @param name The route name.
* @return Whether the Ingress already has assigned ingress address.
*/
public boolean isIngressAddressReady(String namespace, String name) {
Resource<Ingress> resourceOp = operation().inNamespace(namespace).withName(name);
Ingress resource = resourceOp.get();
if (resource != null && resource.getStatus() != null && resource.getStatus().getLoadBalancer() != null && resource.getStatus().getLoadBalancer().getIngress() != null && resource.getStatus().getLoadBalancer().getIngress().size() > 0) {
if (resource.getStatus().getLoadBalancer().getIngress().get(0).getHostname() != null || resource.getStatus().getLoadBalancer().getIngress().get(0).getIp() != null) {
return true;
}
}
return false;
}
use of com.marcnuri.yakc.model.io.k8s.api.networking.v1.Ingress in project strimzi-kafka-operator by strimzi.
the class KafkaListenersReconciler method ingressesReady.
/**
* Makes sure all ingresses are ready and collects their addresses for Statuses,
* certificates and advertised addresses. This method for all ingresses:
* 1) Checks if the bootstrap ingress has been provisioned (has a loadbalancer address)
* 2) Collects the relevant addresses and stores them for use in certificates and in CR status
* 3) Checks it the broker ingresses have been provisioned (have an address)
* 4) Collects the route addresses for certificates and advertised hostnames
*
* @return Future which completes when all Ingresses are ready and their addresses are collected
*/
protected Future<Void> ingressesReady() {
if (!pfa.hasIngressV1()) {
return Future.succeededFuture();
}
List<GenericKafkaListener> ingressListeners = ListenersUtils.ingressListeners(kafka.getListeners());
// Has to use Raw type because of the CompositeFuture
@SuppressWarnings({ "rawtypes" }) List<Future> listenerFutures = new ArrayList<>(ingressListeners.size());
for (GenericKafkaListener listener : ingressListeners) {
String bootstrapIngressName = ListenersUtils.backwardsCompatibleBootstrapRouteOrIngressName(reconciliation.name(), listener);
Future<Void> perListenerFut = ingressOperator.hasIngressAddress(reconciliation, reconciliation.namespace(), bootstrapIngressName, 1_000, operationTimeoutMs).compose(res -> {
String bootstrapAddress = listener.getConfiguration().getBootstrap().getHost();
LOGGER.debugCr(reconciliation, "Using address {} for Ingress {}", bootstrapAddress, bootstrapIngressName);
result.bootstrapDnsNames.add(bootstrapAddress);
ListenerStatus ls = new ListenerStatusBuilder().withName(listener.getName()).withAddresses(new ListenerAddressBuilder().withHost(bootstrapAddress).withPort(KafkaCluster.ROUTE_PORT).build()).build();
result.listenerStatuses.add(ls);
// Check if broker ingresses are ready
// Has to use Raw type because of the CompositeFuture
@SuppressWarnings({ "rawtypes" }) List<Future> perPodFutures = new ArrayList<>(kafka.getReplicas());
for (int pod = 0; pod < kafka.getReplicas(); pod++) {
perPodFutures.add(ingressOperator.hasIngressAddress(reconciliation, reconciliation.namespace(), ListenersUtils.backwardsCompatibleBrokerServiceName(reconciliation.name(), pod, listener), 1_000, operationTimeoutMs));
}
return CompositeFuture.join(perPodFutures);
}).compose(res -> {
for (int brokerId = 0; brokerId < kafka.getReplicas(); brokerId++) {
final int finalBrokerId = brokerId;
String brokerAddress = listener.getConfiguration().getBrokers().stream().filter(broker -> broker.getBroker() == finalBrokerId).map(GenericKafkaListenerConfigurationBroker::getHost).findAny().orElse(null);
LOGGER.debugCr(reconciliation, "Using address {} for Ingress {}", brokerAddress, ListenersUtils.backwardsCompatibleBrokerServiceName(reconciliation.name(), brokerId, listener));
result.brokerDnsNames.computeIfAbsent(brokerId, k -> new HashSet<>(2)).add(brokerAddress);
String advertisedHostname = ListenersUtils.brokerAdvertisedHost(listener, finalBrokerId);
if (advertisedHostname != null) {
result.brokerDnsNames.get(finalBrokerId).add(ListenersUtils.brokerAdvertisedHost(listener, finalBrokerId));
}
registerAdvertisedHostname(finalBrokerId, listener, brokerAddress);
registerAdvertisedPort(finalBrokerId, listener, KafkaCluster.INGRESS_PORT);
}
return Future.succeededFuture();
});
listenerFutures.add(perListenerFut);
}
return CompositeFuture.join(listenerFutures).map((Void) null);
}
use of com.marcnuri.yakc.model.io.k8s.api.networking.v1.Ingress in project strimzi-kafka-operator by strimzi.
the class KafkaCluster method generateExternalIngresses.
/**
* Generates list of ingress for pod. This ingress is used for exposing it externally using Nginx Ingress.
*
* @param pod Number of the pod for which this ingress should be generated
* @return The list of generated Ingresses
*/
public List<Ingress> generateExternalIngresses(int pod) {
List<GenericKafkaListener> ingressListeners = ListenersUtils.ingressListeners(listeners);
List<Ingress> ingresses = new ArrayList<>(ingressListeners.size());
for (GenericKafkaListener listener : ingressListeners) {
String ingressName = ListenersUtils.backwardsCompatibleBrokerServiceName(cluster, pod, listener);
String host = ListenersUtils.brokerHost(listener, pod);
String ingressClass = ListenersUtils.ingressClass(listener);
HTTPIngressPath path = new HTTPIngressPathBuilder().withPath("/").withPathType("Prefix").withNewBackend().withNewService().withName(ingressName).withNewPort().withNumber(listener.getPort()).endPort().endService().endBackend().build();
IngressRule rule = new IngressRuleBuilder().withHost(host).withNewHttp().withPaths(path).endHttp().build();
IngressTLS tls = new IngressTLSBuilder().withHosts(host).build();
Ingress ingress = new IngressBuilder().withNewMetadata().withName(ingressName).withLabels(getLabelsWithStrimziName(name, Util.mergeLabelsOrAnnotations(templatePerPodIngressLabels, ListenersUtils.brokerLabels(listener, pod))).toMap()).withAnnotations(Util.mergeLabelsOrAnnotations(generateInternalIngressAnnotations(), templatePerPodIngressAnnotations, ListenersUtils.brokerAnnotations(listener, pod))).withNamespace(namespace).withOwnerReferences(createOwnerReference()).endMetadata().withNewSpec().withIngressClassName(ingressClass).withRules(rule).withTls(tls).endSpec().build();
ingresses.add(ingress);
}
return ingresses;
}
use of com.marcnuri.yakc.model.io.k8s.api.networking.v1.Ingress in project strimzi-kafka-operator by strimzi.
the class KafkaListenerReconcilerIngressV1Beta1Test method testIngressV1.
@Test
public void testIngressV1(VertxTestContext context) {
Kafka kafka = new KafkaBuilder().withNewMetadata().withName(NAME).withNamespace(NAMESPACE).endMetadata().withNewSpec().withNewKafka().withReplicas(3).withListeners(new GenericKafkaListenerBuilder().withName("ingress").withPort(9094).withTls(true).withType(KafkaListenerType.INGRESS).withNewConfiguration().withNewBootstrap().withHost("bootstrap.mydomain.tld").endBootstrap().withBrokers(new GenericKafkaListenerConfigurationBrokerBuilder().withBroker(0).withHost("broker-0.mydomain.tld").build(), new GenericKafkaListenerConfigurationBrokerBuilder().withBroker(1).withHost("broker-1.mydomain.tld").build(), new GenericKafkaListenerConfigurationBrokerBuilder().withBroker(2).withHost("broker-2.mydomain.tld").build()).endConfiguration().build()).withNewEphemeralStorage().endEphemeralStorage().endKafka().withNewZookeeper().withReplicas(3).withNewEphemeralStorage().endEphemeralStorage().endZookeeper().withNewEntityOperator().withNewUserOperator().endUserOperator().withNewTopicOperator().endTopicOperator().endEntityOperator().endSpec().build();
KafkaCluster kafkaCluster = KafkaCluster.fromCrd(Reconciliation.DUMMY_RECONCILIATION, kafka, VERSIONS);
ResourceOperatorSupplier supplier = ResourceUtils.supplierWithMocks(false);
// Mock ingress v1beta1 ops
IngressV1Beta1Operator mockIngressV1Beta1ops = supplier.ingressV1Beta1Operations;
ArgumentCaptor<io.fabric8.kubernetes.api.model.networking.v1beta1.Ingress> ingressV1Beta1Captor = ArgumentCaptor.forClass(io.fabric8.kubernetes.api.model.networking.v1beta1.Ingress.class);
when(mockIngressV1Beta1ops.listAsync(eq(NAMESPACE), any(Labels.class))).thenReturn(Future.succeededFuture(emptyList()));
when(mockIngressV1Beta1ops.reconcile(any(), anyString(), anyString(), ingressV1Beta1Captor.capture())).thenReturn(Future.succeededFuture(ReconcileResult.created(new io.fabric8.kubernetes.api.model.networking.v1beta1.Ingress())));
when(mockIngressV1Beta1ops.hasIngressAddress(any(), eq(NAMESPACE), any(), anyLong(), anyLong())).thenReturn(Future.succeededFuture());
// Mock ingress v1 ops
IngressOperator mockIngressOps = supplier.ingressOperations;
ArgumentCaptor<Ingress> ingressCaptor = ArgumentCaptor.forClass(Ingress.class);
when(mockIngressOps.listAsync(eq(NAMESPACE), any(Labels.class))).thenReturn(Future.succeededFuture(emptyList()));
when(mockIngressOps.reconcile(any(), anyString(), anyString(), ingressCaptor.capture())).thenReturn(Future.succeededFuture(ReconcileResult.created(new Ingress())));
when(mockIngressOps.hasIngressAddress(any(), eq(NAMESPACE), any(), anyLong(), anyLong())).thenReturn(Future.succeededFuture());
MockKafkaListenersReconciler reconciler = new MockKafkaListenersReconciler(new Reconciliation("test-trigger", Kafka.RESOURCE_KIND, NAMESPACE, NAME), kafkaCluster, new PlatformFeaturesAvailability(false, KubernetesVersion.V1_22), supplier.secretOperations, supplier.serviceOperations, supplier.routeOperations, supplier.ingressOperations, supplier.ingressV1Beta1Operations);
Checkpoint async = context.checkpoint();
reconciler.reconcile().onComplete(context.succeeding(v -> context.verify(() -> {
assertThat(ingressCaptor.getAllValues().size(), is(4));
assertThat(ingressV1Beta1Captor.getAllValues().size(), is(0));
verify(mockIngressV1Beta1ops, never()).list(any(), any());
verify(mockIngressV1Beta1ops, never()).reconcile(any(), any(), any(), any());
verify(mockIngressV1Beta1ops, never()).hasIngressAddress(any(), any(), any(), anyLong(), anyLong());
async.flag();
})));
}
Aggregations