use of com.marcnuri.yakc.model.io.k8s.api.networking.v1.Ingress in project strimzi-kafka-operator by strimzi.
the class KafkaListenerReconcilerIngressV1Beta1Test method testIngressV1Beta1.
@Test
public void testIngressV1Beta1(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_16), 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(0));
assertThat(ingressV1Beta1Captor.getAllValues().size(), is(4));
verify(mockIngressOps, never()).list(any(), any());
verify(mockIngressOps, never()).reconcile(any(), any(), any(), any());
verify(mockIngressOps, never()).hasIngressAddress(any(), any(), any(), anyLong(), anyLong());
async.flag();
})));
}
use of com.marcnuri.yakc.model.io.k8s.api.networking.v1.Ingress in project strimzi-kafka-operator 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 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-kafka-operator by strimzi.
the class KafkaClusterTest method testExternalIngress.
@ParallelTest
public void testExternalIngress() {
GenericKafkaListenerConfigurationBroker broker0 = new GenericKafkaListenerConfigurationBrokerBuilder().withHost("my-broker-kafka-0.com").withLabels(Collections.singletonMap("label", "label-value")).withAnnotations(Collections.singletonMap("dns-annotation", "my-kafka-broker.com")).withBroker(0).build();
GenericKafkaListenerConfigurationBroker broker1 = new GenericKafkaListenerConfigurationBrokerBuilder().withHost("my-broker-kafka-1.com").withLabels(Collections.singletonMap("label", "label-value")).withAnnotations(Collections.singletonMap("dns-annotation", "my-kafka-broker.com")).withBroker(1).build();
GenericKafkaListenerConfigurationBroker broker2 = new GenericKafkaListenerConfigurationBrokerBuilder().withHost("my-broker-kafka-2.com").withLabels(Collections.singletonMap("label", "label-value")).withAnnotations(Collections.singletonMap("dns-annotation", "my-kafka-broker.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().withNewBootstrap().withHost("my-kafka-bootstrap.com").withAnnotations(Collections.singletonMap("dns-annotation", "my-kafka-bootstrap.com")).withLabels(Collections.singletonMap("label", "label-value")).endBootstrap().withBrokers(broker0, broker1, broker2).endConfiguration().build()).endKafka().endSpec().build();
KafkaCluster kc = KafkaCluster.fromCrd(Reconciliation.DUMMY_RECONCILIATION, kafkaAssembly, VERSIONS);
assertThat(kc.isExposedWithIngress(), is(true));
// Check StatefulSet changes
StatefulSet sts = kc.generateStatefulSet(true, null, null, null);
List<ContainerPort> ports = sts.getSpec().getTemplate().getSpec().getContainers().get(0).getPorts();
assertThat(ports.contains(kc.createContainerPort(ListenersUtils.BACKWARDS_COMPATIBLE_EXTERNAL_PORT_NAME, 9094, "TCP")), is(true));
// Check external bootstrap service
Service ext = kc.generateExternalBootstrapServices().get(0);
assertThat(ext.getMetadata().getName(), is(KafkaResources.externalBootstrapServiceName(cluster)));
assertThat(ext.getSpec().getType(), is("ClusterIP"));
assertThat(ext.getSpec().getSelector(), is(kc.getSelectorLabels().toMap()));
assertThat(ext.getSpec().getPorts(), is(Collections.singletonList(kc.createServicePort(ListenersUtils.BACKWARDS_COMPATIBLE_EXTERNAL_PORT_NAME, 9094, 9094, "TCP"))));
checkOwnerReference(kc.createOwnerReference(), ext);
// Check per pod services
for (int i = 0; i < replicas; i++) {
Service srv = kc.generateExternalServices(i).get(0);
assertThat(srv.getMetadata().getName(), is(KafkaResources.kafkaStatefulSetName(cluster) + "-" + i));
assertThat(srv.getSpec().getType(), is("ClusterIP"));
assertThat(srv.getSpec().getSelector().get(Labels.KUBERNETES_STATEFULSET_POD_LABEL), is(KafkaResources.kafkaPodName(cluster, i)));
assertThat(srv.getSpec().getPorts(), is(Collections.singletonList(kc.createServicePort(ListenersUtils.BACKWARDS_COMPATIBLE_EXTERNAL_PORT_NAME, 9094, 9094, "TCP"))));
checkOwnerReference(kc.createOwnerReference(), srv);
}
// Check bootstrap ingress
Ingress bing = kc.generateExternalBootstrapIngresses().get(0);
assertThat(bing.getMetadata().getName(), is(KafkaResources.bootstrapServiceName(cluster)));
assertThat(bing.getSpec().getIngressClassName(), is(nullValue()));
assertThat(bing.getMetadata().getAnnotations().get("dns-annotation"), is("my-kafka-bootstrap.com"));
assertThat(bing.getMetadata().getLabels().get("label"), is("label-value"));
assertThat(bing.getSpec().getTls().size(), is(1));
assertThat(bing.getSpec().getTls().get(0).getHosts().size(), is(1));
assertThat(bing.getSpec().getTls().get(0).getHosts().get(0), is("my-kafka-bootstrap.com"));
assertThat(bing.getSpec().getRules().size(), is(1));
assertThat(bing.getSpec().getRules().get(0).getHost(), is("my-kafka-bootstrap.com"));
assertThat(bing.getSpec().getRules().get(0).getHttp().getPaths().size(), is(1));
assertThat(bing.getSpec().getRules().get(0).getHttp().getPaths().get(0).getPath(), is("/"));
assertThat(bing.getSpec().getRules().get(0).getHttp().getPaths().get(0).getBackend().getService().getName(), is(KafkaResources.externalBootstrapServiceName(cluster)));
assertThat(bing.getSpec().getRules().get(0).getHttp().getPaths().get(0).getBackend().getService().getPort().getNumber(), is(9094));
checkOwnerReference(kc.createOwnerReference(), bing);
io.fabric8.kubernetes.api.model.networking.v1beta1.Ingress bingV1Beta1 = kc.generateExternalBootstrapIngressesV1Beta1().get(0);
assertThat(bingV1Beta1.getMetadata().getName(), is(KafkaResources.bootstrapServiceName(cluster)));
assertThat(bingV1Beta1.getSpec().getIngressClassName(), is(nullValue()));
assertThat(bingV1Beta1.getMetadata().getAnnotations().get("dns-annotation"), is("my-kafka-bootstrap.com"));
assertThat(bingV1Beta1.getMetadata().getLabels().get("label"), is("label-value"));
assertThat(bingV1Beta1.getSpec().getTls().size(), is(1));
assertThat(bingV1Beta1.getSpec().getTls().get(0).getHosts().size(), is(1));
assertThat(bingV1Beta1.getSpec().getTls().get(0).getHosts().get(0), is("my-kafka-bootstrap.com"));
assertThat(bingV1Beta1.getSpec().getRules().size(), is(1));
assertThat(bingV1Beta1.getSpec().getRules().get(0).getHost(), is("my-kafka-bootstrap.com"));
assertThat(bingV1Beta1.getSpec().getRules().get(0).getHttp().getPaths().size(), is(1));
assertThat(bingV1Beta1.getSpec().getRules().get(0).getHttp().getPaths().get(0).getPath(), is("/"));
assertThat(bingV1Beta1.getSpec().getRules().get(0).getHttp().getPaths().get(0).getBackend().getServiceName(), is(KafkaResources.externalBootstrapServiceName(cluster)));
assertThat(bingV1Beta1.getSpec().getRules().get(0).getHttp().getPaths().get(0).getBackend().getServicePort(), is(new IntOrString(9094)));
checkOwnerReference(kc.createOwnerReference(), bingV1Beta1);
// Check per pod ingress
for (int i = 0; i < replicas; i++) {
Ingress ing = kc.generateExternalIngresses(i).get(0);
assertThat(ing.getMetadata().getName(), is(KafkaResources.kafkaStatefulSetName(cluster) + "-" + i));
assertThat(ing.getSpec().getIngressClassName(), is(nullValue()));
assertThat(ing.getMetadata().getAnnotations().get("dns-annotation"), is("my-kafka-broker.com"));
assertThat(ing.getMetadata().getLabels().get("label"), is("label-value"));
assertThat(ing.getSpec().getTls().size(), is(1));
assertThat(ing.getSpec().getTls().get(0).getHosts().size(), is(1));
assertThat(ing.getSpec().getTls().get(0).getHosts().get(0), is(String.format("my-broker-kafka-%d.com", i)));
assertThat(ing.getSpec().getRules().size(), is(1));
assertThat(ing.getSpec().getRules().get(0).getHost(), is(String.format("my-broker-kafka-%d.com", i)));
assertThat(ing.getSpec().getRules().get(0).getHttp().getPaths().size(), is(1));
assertThat(ing.getSpec().getRules().get(0).getHttp().getPaths().get(0).getPath(), is("/"));
assertThat(ing.getSpec().getRules().get(0).getHttp().getPaths().get(0).getBackend().getService().getName(), is(KafkaResources.kafkaStatefulSetName(cluster) + "-" + i));
assertThat(ing.getSpec().getRules().get(0).getHttp().getPaths().get(0).getBackend().getService().getPort().getNumber(), is(9094));
checkOwnerReference(kc.createOwnerReference(), ing);
io.fabric8.kubernetes.api.model.networking.v1beta1.Ingress ingV1Beta1 = kc.generateExternalIngressesV1Beta1(i).get(0);
assertThat(ingV1Beta1.getMetadata().getName(), is(KafkaResources.kafkaStatefulSetName(cluster) + "-" + i));
assertThat(ingV1Beta1.getSpec().getIngressClassName(), is(nullValue()));
assertThat(ingV1Beta1.getMetadata().getAnnotations().get("dns-annotation"), is("my-kafka-broker.com"));
assertThat(ingV1Beta1.getMetadata().getLabels().get("label"), is("label-value"));
assertThat(ingV1Beta1.getSpec().getTls().size(), is(1));
assertThat(ingV1Beta1.getSpec().getTls().get(0).getHosts().size(), is(1));
assertThat(ingV1Beta1.getSpec().getTls().get(0).getHosts().get(0), is(String.format("my-broker-kafka-%d.com", i)));
assertThat(ingV1Beta1.getSpec().getRules().size(), is(1));
assertThat(ingV1Beta1.getSpec().getRules().get(0).getHost(), is(String.format("my-broker-kafka-%d.com", i)));
assertThat(ingV1Beta1.getSpec().getRules().get(0).getHttp().getPaths().size(), is(1));
assertThat(ingV1Beta1.getSpec().getRules().get(0).getHttp().getPaths().get(0).getPath(), is("/"));
assertThat(ingV1Beta1.getSpec().getRules().get(0).getHttp().getPaths().get(0).getBackend().getServiceName(), is(KafkaResources.kafkaStatefulSetName(cluster) + "-" + i));
assertThat(ingV1Beta1.getSpec().getRules().get(0).getHttp().getPaths().get(0).getBackend().getServicePort(), is(new IntOrString(9094)));
checkOwnerReference(kc.createOwnerReference(), ingV1Beta1);
}
}
use of com.marcnuri.yakc.model.io.k8s.api.networking.v1.Ingress in project flink-kubernetes-operator by apache.
the class IngressUtilsTest method testIngress.
@Test
public void testIngress() {
FlinkDeployment appCluster = TestUtils.buildApplicationCluster();
Configuration config = new FlinkConfigManager(new Configuration()).getDeployConfig(appCluster.getMetadata(), appCluster.getSpec());
// no ingress when ingressDomain is empty
IngressUtils.updateIngressRules(appCluster.getMetadata(), appCluster.getSpec(), config, client);
assertNull(client.network().v1().ingresses().inNamespace(appCluster.getMetadata().getNamespace()).withName(appCluster.getMetadata().getName()).get());
// host based routing
IngressSpec.IngressSpecBuilder builder = IngressSpec.builder();
builder.template("{{name}}.{{namespace}}.example.com");
appCluster.getSpec().setIngress(builder.build());
IngressUtils.updateIngressRules(appCluster.getMetadata(), appCluster.getSpec(), config, client);
Ingress ingress = client.network().v1().ingresses().inNamespace(appCluster.getMetadata().getNamespace()).withName(appCluster.getMetadata().getName()).get();
List<IngressRule> rules = ingress.getSpec().getRules();
assertEquals(1, rules.size());
assertEquals(appCluster.getMetadata().getName() + "." + appCluster.getMetadata().getNamespace() + ".example.com", rules.get(0).getHost());
assertNull(rules.get(0).getHttp().getPaths().get(0).getPath());
// path based routing
builder.template("/{{namespace}}/{{name}}(/|$)(.*)");
builder.className("nginx");
builder.annotations(Map.of("nginx.ingress.kubernetes.io/rewrite-target", "/$2"));
appCluster.getSpec().setIngress(builder.build());
IngressUtils.updateIngressRules(appCluster.getMetadata(), appCluster.getSpec(), config, client);
ingress = client.network().v1().ingresses().inNamespace(appCluster.getMetadata().getNamespace()).withName(appCluster.getMetadata().getName()).get();
rules = ingress.getSpec().getRules();
assertEquals(1, rules.size());
assertNull(rules.get(0).getHost());
assertEquals(1, rules.get(0).getHttp().getPaths().size());
assertEquals("/" + appCluster.getMetadata().getNamespace() + "/" + appCluster.getMetadata().getName() + "(/|$)(.*)", rules.get(0).getHttp().getPaths().get(0).getPath());
assertEquals(Map.of("nginx.ingress.kubernetes.io/rewrite-target", "/$2"), ingress.getMetadata().getAnnotations());
assertEquals("nginx", ingress.getSpec().getIngressClassName());
// host + path based routing
builder.template("example.com/{{namespace}}/{{name}}(/|$)(.*)");
builder.className("nginx");
appCluster.getSpec().setIngress(builder.build());
IngressUtils.updateIngressRules(appCluster.getMetadata(), appCluster.getSpec(), config, client);
ingress = client.network().v1().ingresses().inNamespace(appCluster.getMetadata().getNamespace()).withName(appCluster.getMetadata().getName()).get();
rules = ingress.getSpec().getRules();
assertEquals(1, rules.size());
assertEquals(1, rules.get(0).getHttp().getPaths().size());
assertEquals("/" + appCluster.getMetadata().getNamespace() + "/" + appCluster.getMetadata().getName() + "(/|$)(.*)", rules.get(0).getHttp().getPaths().get(0).getPath());
assertEquals(Map.of("nginx.ingress.kubernetes.io/rewrite-target", "/$2"), ingress.getMetadata().getAnnotations());
assertEquals("nginx", ingress.getSpec().getIngressClassName());
}
Aggregations