use of io.strimzi.api.kafka.model.status.KafkaStatus in project strimzi-kafka-operator by strimzi.
the class CustomResourceStatusIsolatedST method assertKafkaStatus.
void assertKafkaStatus(long expectedObservedGeneration, String internalAddress) {
KafkaStatus kafkaStatus = KafkaResource.kafkaClient().inNamespace(clusterOperator.getDeploymentNamespace()).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(clusterOperator.getDeploymentNamespace()).getClient().services().inNamespace(clusterOperator.getDeploymentNamespace()).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.KafkaStatus in project strimzi-kafka-operator 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.KafkaStatus in project strimzi-kafka-operator by strimzi.
the class StatusDiffTest method testStatusDiff.
@ParallelTest
public void testStatusDiff() {
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();
ListenerStatus ls3 = new ListenerStatusBuilder().withName("tls").withAddresses(new ListenerAddressBuilder().withHost("my-service.my-namespace.svc").withPort(9094).build()).build();
Condition condition1 = new ConditionBuilder().withLastTransitionTime(StatusUtils.iso8601(new Date())).withType("Ready").withStatus("True").build();
Condition condition2 = new ConditionBuilder().withLastTransitionTime(StatusUtils.iso8601(new Date())).withType("Ready2").withStatus("True").build();
KafkaStatus status1 = new KafkaStatusBuilder().withConditions(condition1).withListeners(ls1).build();
KafkaStatus status2 = new KafkaStatusBuilder().withConditions(condition1).withListeners(ls1).build();
KafkaStatus status3 = new KafkaStatusBuilder().withConditions(condition1).withListeners(ls1, ls2).build();
KafkaStatus status4 = new KafkaStatusBuilder().withConditions(condition1, condition2).withListeners(ls1).build();
KafkaStatus status5 = new KafkaStatusBuilder().withConditions(condition1).withListeners(ls1, ls3).build();
KafkaStatus status6 = new KafkaStatusBuilder().withConditions(condition1).withListeners(ls3, ls1).build();
StatusDiff diff = new StatusDiff(status1, status2);
assertThat(diff.isEmpty(), is(true));
diff = new StatusDiff(status1, status3);
assertThat(diff.isEmpty(), is(false));
diff = new StatusDiff(status1, status4);
assertThat(diff.isEmpty(), is(false));
diff = new StatusDiff(status3, status4);
assertThat(diff.isEmpty(), is(false));
diff = new StatusDiff(status3, status5);
assertThat(diff.isEmpty(), is(false));
diff = new StatusDiff(status5, status6);
assertThat(diff.isEmpty(), is(false));
}
use of io.strimzi.api.kafka.model.status.KafkaStatus in project strimzi-kafka-operator by strimzi.
the class CruiseControlST method testCruiseControlWithSingleNodeKafka.
@ParallelNamespaceTest
void testCruiseControlWithSingleNodeKafka(ExtensionContext extensionContext) {
final String namespaceName = StUtils.getNamespaceBasedOnRbac(namespace, extensionContext);
final String clusterName = mapWithClusterNames.get(extensionContext.getDisplayName());
final String errMessage = "Kafka " + namespaceName + "/" + clusterName + " has invalid configuration." + " Cruise Control cannot be deployed with a single-node Kafka cluster. It requires " + "at least two Kafka nodes.";
LOGGER.info("Deploying single node Kafka with CruiseControl");
resourceManager.createResource(extensionContext, false, KafkaTemplates.kafkaWithCruiseControl(clusterName, 1, 1).build());
KafkaUtils.waitUntilKafkaStatusConditionContainsMessage(clusterName, namespaceName, errMessage, Duration.ofMinutes(6).toMillis());
KafkaStatus kafkaStatus = KafkaResource.kafkaClient().inNamespace(namespaceName).withName(clusterName).get().getStatus();
assertThat(kafkaStatus.getConditions().stream().filter(c -> "InvalidResourceException".equals(c.getReason())).findFirst().orElse(null), is(notNullValue()));
LOGGER.info("Increasing Kafka nodes to 3");
KafkaResource.replaceKafkaResourceInSpecificNamespace(clusterName, kafka -> kafka.getSpec().getKafka().setReplicas(3), namespaceName);
KafkaUtils.waitForKafkaReady(namespaceName, clusterName);
kafkaStatus = KafkaResource.kafkaClient().inNamespace(namespaceName).withName(clusterName).get().getStatus();
assertThat(kafkaStatus.getConditions().get(0).getMessage(), is(not(errMessage)));
}
use of io.strimzi.api.kafka.model.status.KafkaStatus in project strimzi-kafka-operator by strimzi.
the class KafkaStatusTest method testKafkaListenerNodePortAddressMissingNodes.
@Test
public void testKafkaListenerNodePortAddressMissingNodes(VertxTestContext context) throws ParseException {
Kafka kafka = new KafkaBuilder(getKafkaCrd()).editOrNewSpec().editOrNewKafka().withReplicas(1).withListeners(new GenericKafkaListenerBuilder().withName("external").withPort(9094).withType(KafkaListenerType.NODEPORT).withTls(true).build()).endKafka().endSpec().build();
KafkaCluster kafkaCluster = KafkaCluster.fromCrd(Reconciliation.DUMMY_RECONCILIATION, kafka, VERSIONS);
ResourceOperatorSupplier supplier = ResourceUtils.supplierWithMocks(false);
// Mock the CRD Operator for Kafka resources
CrdOperator mockKafkaOps = supplier.kafkaOperator;
when(mockKafkaOps.getAsync(eq(namespace), eq(clusterName))).thenReturn(Future.succeededFuture(kafka));
when(mockKafkaOps.get(eq(namespace), eq(clusterName))).thenReturn(kafka);
ArgumentCaptor<Kafka> kafkaCaptor = ArgumentCaptor.forClass(Kafka.class);
when(mockKafkaOps.updateStatusAsync(any(), kafkaCaptor.capture())).thenReturn(Future.succeededFuture());
// Mock the KafkaSetOperator
StatefulSetOperator mockStsOps = supplier.stsOperations;
when(mockStsOps.getAsync(eq(namespace), eq(KafkaCluster.kafkaClusterName(clusterName)))).thenReturn(Future.succeededFuture(kafkaCluster.generateStatefulSet(false, null, null, null)));
// Mock the StrimziPodSet operator
CrdOperator<KubernetesClient, StrimziPodSet, StrimziPodSetList> mockPodSetOps = supplier.strimziPodSetOperator;
when(mockPodSetOps.getAsync(any(), any())).thenReturn(Future.succeededFuture(null));
// Mock the ConfigMapOperator
ConfigMapOperator mockCmOps = supplier.configMapOperations;
when(mockCmOps.getAsync(eq(namespace), eq(clusterName))).thenReturn(Future.succeededFuture(kafkaCluster.generateMetricsAndLogConfigMap(new MetricsAndLogging(null, null))));
// Mock Pods Operator
Pod pod0 = new PodBuilder().withNewMetadata().withName(clusterName + "-kafka-" + 0).endMetadata().withNewStatus().withHostIP("10.0.0.5").endStatus().build();
List<Pod> pods = new ArrayList<>();
pods.add(pod0);
PodOperator mockPodOps = supplier.podOperations;
when(mockPodOps.listAsync(eq(namespace), any(Labels.class))).thenReturn(Future.succeededFuture(pods));
// Mock Node operator
NodeOperator mockNodeOps = supplier.nodeOperator;
when(mockNodeOps.listAsync(any(Labels.class))).thenReturn(Future.succeededFuture(getClusterNodes()));
MockNodePortStatusKafkaAssemblyOperator kao = new MockNodePortStatusKafkaAssemblyOperator(vertx, new PlatformFeaturesAvailability(false, kubernetesVersion), certManager, passwordGenerator, supplier, config);
Checkpoint async = context.checkpoint();
kao.reconcile(new Reconciliation("test-trigger", Kafka.RESOURCE_KIND, namespace, clusterName)).onComplete(res -> {
assertThat(res.succeeded(), is(true));
assertThat(kafkaCaptor.getValue(), is(notNullValue()));
assertThat(kafkaCaptor.getValue().getStatus(), is(notNullValue()));
KafkaStatus status = kafkaCaptor.getValue().getStatus();
assertThat(status.getListeners().size(), is(1));
assertThat(status.getListeners().get(0).getType(), is("external"));
assertThat(status.getListeners().get(0).getName(), is("external"));
assertThat(status.getListeners().get(0).getAddresses(), is(emptyList()));
assertThat(status.getListeners().get(0).getBootstrapServers(), is(nullValue()));
async.flag();
});
}
Aggregations