use of io.strimzi.api.kafka.model.status.ListenerStatus in project strimzi by strimzi.
the class KafkaAssemblyOperatorLoadBalancerKafkaListenerTest method testLoadBalancerWithBootstrapService.
@Test
public void testLoadBalancerWithBootstrapService(VertxTestContext context) {
Kafka kafka = new KafkaBuilder().withNewMetadata().withName(NAME).withNamespace(NAMESPACE).endMetadata().withNewSpec().withNewKafka().withReplicas(3).withListeners(new GenericKafkaListenerBuilder().withName("external").withPort(LISTENER_PORT).withTls(true).withType(KafkaListenerType.LOADBALANCER).withNewConfiguration().withCreateBootstrapService(true).endConfiguration().build()).withNewEphemeralStorage().endEphemeralStorage().endKafka().withNewZookeeper().withReplicas(3).withNewEphemeralStorage().endEphemeralStorage().endZookeeper().withNewEntityOperator().withNewUserOperator().endUserOperator().withNewTopicOperator().endTopicOperator().endEntityOperator().endSpec().build();
ResourceOperatorSupplier supplier = prepareResourceOperatorSupplier(kafka);
KafkaAssemblyOperator op = new MockKafkaAssemblyOperatorForLoadBalancerTests(vertx, new PlatformFeaturesAvailability(false, KubernetesVersion.V1_16), certManager, passwordGenerator, supplier, ResourceUtils.dummyClusterOperatorConfig(KafkaVersionTestUtils.getKafkaVersionLookup()));
Reconciliation reconciliation = new Reconciliation("test-trigger", Kafka.RESOURCE_KIND, NAMESPACE, NAME);
Checkpoint async = context.checkpoint();
op.reconcile(reconciliation).onComplete(context.succeeding(v -> context.verify(() -> {
assertThat(kafka.getStatus().getListeners().size(), is(1));
ListenerStatus listenerStatus = kafka.getStatus().getListeners().get(0);
assertThat(listenerStatus.getBootstrapServers(), is("bootstrap-broker.test.dns.name:9094"));
assertThat(listenerStatus.getAddresses().size(), is(1));
assertThat(listenerStatus.getAddresses().get(0).getHost(), is(DNS_NAME_FOR_BOOTSTRAP_SERVICE));
assertThat(listenerStatus.getAddresses().get(0).getPort(), is(LISTENER_PORT));
async.flag();
})));
}
use of io.strimzi.api.kafka.model.status.ListenerStatus in project strimzi by strimzi.
the class KafkaAssemblyOperatorLoadBalancerKafkaListenerTest method testLoadBalancer.
@Test
public void testLoadBalancer(VertxTestContext context) {
Kafka kafka = new KafkaBuilder().withNewMetadata().withName(NAME).withNamespace(NAMESPACE).endMetadata().withNewSpec().withNewKafka().withReplicas(3).withListeners(new GenericKafkaListenerBuilder().withName("external").withPort(LISTENER_PORT).withTls(true).withType(KafkaListenerType.LOADBALANCER).build()).withNewEphemeralStorage().endEphemeralStorage().endKafka().withNewZookeeper().withReplicas(3).withNewEphemeralStorage().endEphemeralStorage().endZookeeper().withNewEntityOperator().withNewUserOperator().endUserOperator().withNewTopicOperator().endTopicOperator().endEntityOperator().endSpec().build();
ResourceOperatorSupplier supplier = prepareResourceOperatorSupplier(kafka);
KafkaAssemblyOperator op = new MockKafkaAssemblyOperatorForLoadBalancerTests(vertx, new PlatformFeaturesAvailability(false, KubernetesVersion.V1_16), certManager, passwordGenerator, supplier, ResourceUtils.dummyClusterOperatorConfig(KafkaVersionTestUtils.getKafkaVersionLookup()));
Reconciliation reconciliation = new Reconciliation("test-trigger", Kafka.RESOURCE_KIND, NAMESPACE, NAME);
Checkpoint async = context.checkpoint();
op.reconcile(reconciliation).onComplete(context.succeeding(v -> context.verify(() -> {
assertThat(kafka.getStatus().getListeners().size(), is(1));
ListenerStatus listenerStatus = kafka.getStatus().getListeners().get(0);
assertThat(listenerStatus.getBootstrapServers(), is("bootstrap-broker.test.dns.name:9094"));
assertThat(listenerStatus.getAddresses().size(), is(1));
assertThat(listenerStatus.getAddresses().get(0).getHost(), is(DNS_NAME_FOR_BOOTSTRAP_SERVICE));
assertThat(listenerStatus.getAddresses().get(0).getPort(), is(LISTENER_PORT));
async.flag();
})));
}
use of io.strimzi.api.kafka.model.status.ListenerStatus in project strimzi by strimzi.
the class StatusDiffTest method testTimestampDiff.
@ParallelTest
public void testTimestampDiff() throws ParseException {
ListenerStatus ls1 = new ListenerStatusBuilder().withName("plain").withAddresses(new ListenerAddressBuilder().withHost("my-service.my-namespace.svc").withPort(9092).build()).build();
ListenerStatus ls2 = new ListenerStatusBuilder().withName("tls").withAddresses(new ListenerAddressBuilder().withHost("my-service.my-namespace.svc").withPort(9093).build()).build();
Condition condition1 = new ConditionBuilder().withLastTransitionTime(StatusUtils.iso8601(new Date())).withType("Ready").withStatus("True").build();
Condition condition2 = new ConditionBuilder().withLastTransitionTime(StatusUtils.iso8601(new SimpleDateFormat("yyyy-MM-dd hh:mm:ss").parse("2011-01-01 00:00:00"))).withType("Ready").withStatus("True").build();
KafkaStatus status1 = new KafkaStatusBuilder().withConditions(condition1).withListeners(ls1, ls2).build();
KafkaStatus status2 = new KafkaStatusBuilder().withConditions(condition2).withListeners(ls1, ls2).build();
StatusDiff diff = new StatusDiff(status1, status2);
assertThat(diff.isEmpty(), is(true));
}
use of io.strimzi.api.kafka.model.status.ListenerStatus in project strimzi by strimzi.
the class CustomResourceStatusIsolatedST method assertKafkaStatus.
void assertKafkaStatus(long expectedObservedGeneration, String internalAddress) {
KafkaStatus kafkaStatus = KafkaResource.kafkaClient().inNamespace(Constants.INFRA_NAMESPACE).withName(CUSTOM_RESOURCE_STATUS_CLUSTER_NAME).get().getStatus();
assertThat("Kafka cluster status has incorrect Observed Generation", kafkaStatus.getObservedGeneration(), is(expectedObservedGeneration));
for (ListenerStatus listener : kafkaStatus.getListeners()) {
switch(listener.getType()) {
case Constants.TLS_LISTENER_DEFAULT_NAME:
assertThat("TLS bootstrap has incorrect port", listener.getAddresses().get(0).getPort(), is(9093));
assertThat("TLS bootstrap has incorrect host", listener.getAddresses().get(0).getHost(), is(internalAddress));
break;
case Constants.PLAIN_LISTENER_DEFAULT_NAME:
assertThat("Plain bootstrap has incorrect port", listener.getAddresses().get(0).getPort(), is(9092));
assertThat("Plain bootstrap has incorrect host", listener.getAddresses().get(0).getHost(), is(internalAddress));
break;
case Constants.EXTERNAL_LISTENER_DEFAULT_NAME:
Service extBootstrapService = kubeClient(Constants.INFRA_NAMESPACE).getClient().services().inNamespace(Constants.INFRA_NAMESPACE).withName(externalBootstrapServiceName(CUSTOM_RESOURCE_STATUS_CLUSTER_NAME)).get();
assertThat("External bootstrap has incorrect port", listener.getAddresses().get(0).getPort(), is(extBootstrapService.getSpec().getPorts().get(0).getNodePort()));
assertThat("External bootstrap has incorrect host", listener.getAddresses().get(0).getHost() != null);
break;
}
}
}
use of io.strimzi.api.kafka.model.status.ListenerStatus in project strimzi by strimzi.
the class ListenersST method testNodePort.
@ParallelNamespaceTest
@Tag(NODEPORT_SUPPORTED)
@Tag(EXTERNAL_CLIENTS_USED)
void testNodePort(ExtensionContext extensionContext) {
final String namespaceName = StUtils.getNamespaceBasedOnRbac(INFRA_NAMESPACE, extensionContext);
final String clusterName = mapWithClusterNames.get(extensionContext.getDisplayName());
final String topicName = mapWithTestTopics.get(extensionContext.getDisplayName());
final Map<String, String> label = Collections.singletonMap("my-label", "value");
final Map<String, String> anno = Collections.singletonMap("my-annotation", "value");
resourceManager.createResource(extensionContext, KafkaTemplates.kafkaEphemeral(clusterName, 3, 1).editSpec().editKafka().withListeners(new GenericKafkaListenerBuilder().withType(KafkaListenerType.INTERNAL).withName(Constants.TLS_LISTENER_DEFAULT_NAME).withPort(9097).withTls(true).build(), new GenericKafkaListenerBuilder().withType(KafkaListenerType.NODEPORT).withName(Constants.EXTERNAL_LISTENER_DEFAULT_NAME).withPort(9098).withTls(false).build()).withConfig(Collections.singletonMap("default.replication.factor", 3)).editOrNewTemplate().withNewClusterRoleBinding().withNewMetadata().withAnnotations(anno).withLabels(label).endMetadata().endClusterRoleBinding().endTemplate().endKafka().endSpec().build());
ExternalKafkaClient externalKafkaClient = new ExternalKafkaClient.Builder().withTopicName(topicName).withNamespaceName(namespaceName).withClusterName(clusterName).withMessageCount(MESSAGE_COUNT).withListenerName(Constants.EXTERNAL_LISTENER_DEFAULT_NAME).build();
externalKafkaClient.verifyProducedAndConsumedMessages(externalKafkaClient.sendMessagesPlain(), externalKafkaClient.receiveMessagesPlain());
// Check that Kafka status has correct addresses in NodePort external listener part
for (ListenerStatus listenerStatus : KafkaResource.getKafkaStatus(clusterName, namespaceName).getListeners()) {
if (listenerStatus.getType().equals(Constants.EXTERNAL_LISTENER_DEFAULT_NAME)) {
List<String> listStatusAddresses = listenerStatus.getAddresses().stream().map(ListenerAddress::getHost).collect(Collectors.toList());
listStatusAddresses.sort(Comparator.comparing(String::toString));
List<Integer> listStatusPorts = listenerStatus.getAddresses().stream().map(ListenerAddress::getPort).collect(Collectors.toList());
Integer nodePort = kubeClient(namespaceName).getService(namespaceName, KafkaResources.externalBootstrapServiceName(clusterName)).getSpec().getPorts().get(0).getNodePort();
List<String> nodeIps = kubeClient(namespaceName).listPods(KafkaResource.getLabelSelector(clusterName, KafkaResources.kafkaStatefulSetName(clusterName))).stream().map(pods -> pods.getStatus().getHostIP()).distinct().collect(Collectors.toList());
nodeIps.sort(Comparator.comparing(String::toString));
assertThat(listStatusAddresses, is(nodeIps));
for (Integer port : listStatusPorts) {
assertThat(port, is(nodePort));
}
}
}
// check the ClusterRoleBinding annotations and labels in Kafka cluster
Map<String, String> actualLabel = KafkaResource.kafkaClient().inNamespace(namespaceName).withName(clusterName).get().getSpec().getKafka().getTemplate().getClusterRoleBinding().getMetadata().getLabels();
Map<String, String> actualAnno = KafkaResource.kafkaClient().inNamespace(namespaceName).withName(clusterName).get().getSpec().getKafka().getTemplate().getClusterRoleBinding().getMetadata().getAnnotations();
assertThat(actualLabel, is(label));
assertThat(actualAnno, is(anno));
}
Aggregations