use of io.strimzi.api.kafka.model.status.KafkaStatus in project strimzi by strimzi.
the class KafkaReconcilerStatusTest method testKafkaReconcilerStatusWithNodePortsWithPreferredAddressType.
@Test
public void testKafkaReconcilerStatusWithNodePortsWithPreferredAddressType(VertxTestContext context) {
Kafka kafka = new KafkaBuilder(KAFKA).editOrNewSpec().editOrNewKafka().withListeners(new GenericKafkaListenerBuilder().withName("external").withPort(9094).withType(KafkaListenerType.NODEPORT).withTls(true).withNewConfiguration().withPreferredNodePortAddressType(NodeAddressType.INTERNAL_DNS).endConfiguration().build()).endKafka().endSpec().build();
ResourceOperatorSupplier supplier = ResourceUtils.supplierWithMocks(false);
// Mock the secrets needed for Kafka client
SecretOperator mockSecretOps = supplier.secretOperations;
Secret secret = new Secret();
when(mockSecretOps.getAsync(eq(NAMESPACE), eq(KafkaResources.clusterCaCertificateSecretName(CLUSTER_NAME)))).thenReturn(Future.succeededFuture(secret));
when(mockSecretOps.getAsync(eq(NAMESPACE), eq(ClusterOperator.secretName(CLUSTER_NAME)))).thenReturn(Future.succeededFuture(secret));
// Mock Kafka broker pods
Pod pod0 = new PodBuilder().withNewMetadata().withName(CLUSTER_NAME + "-kafka-" + 0).endMetadata().withNewStatus().withHostIP("10.0.0.1").endStatus().build();
Pod pod1 = new PodBuilder().withNewMetadata().withName(CLUSTER_NAME + "-kafka-" + 1).endMetadata().withNewStatus().withHostIP("10.0.0.25").endStatus().build();
Pod pod2 = new PodBuilder().withNewMetadata().withName(CLUSTER_NAME + "-kafka-" + 2).endMetadata().withNewStatus().withHostIP("10.0.0.13").endStatus().build();
List<Pod> pods = new ArrayList<>();
pods.add(pod0);
pods.add(pod1);
pods.add(pod2);
PodOperator mockPodOps = supplier.podOperations;
when(mockPodOps.listAsync(eq(NAMESPACE), any(Labels.class))).thenReturn(Future.succeededFuture(pods));
// Mock Kubernetes worker nodes
NodeOperator mockNodeOps = supplier.nodeOperator;
when(mockNodeOps.listAsync(any(Labels.class))).thenReturn(Future.succeededFuture(kubernetesWorkerNodes()));
// Run the test
KafkaReconciler reconciler = new MockKafkaReconcilerStatusTasks(new Reconciliation("test-trigger", Kafka.RESOURCE_KIND, NAMESPACE, CLUSTER_NAME), supplier, kafka);
KafkaStatus status = new KafkaStatus();
Checkpoint async = context.checkpoint();
reconciler.reconcile(status, Date::new).onComplete(res -> context.verify(() -> {
assertThat(res.succeeded(), is(true));
// Check listener status
assertThat(status.getListeners().size(), is(1));
assertThat(status.getListeners().get(0).getName(), is("external"));
assertThat(status.getListeners().get(0).getType(), is("external"));
assertThat(status.getListeners().get(0).getBootstrapServers(), is("node-0.my-kube:31234,node-1.my-kube:31234,node-3.my-kube:31234"));
assertThat(status.getListeners().get(0).getAddresses().size(), is(3));
assertThat(status.getListeners().get(0).getAddresses().get(0).getPort(), is(31234));
assertThat(status.getListeners().get(0).getAddresses().get(0).getHost(), is("node-0.my-kube"));
assertThat(status.getListeners().get(0).getAddresses().get(1).getPort(), is(31234));
assertThat(status.getListeners().get(0).getAddresses().get(1).getHost(), is("node-1.my-kube"));
assertThat(status.getListeners().get(0).getAddresses().get(2).getPort(), is(31234));
assertThat(status.getListeners().get(0).getAddresses().get(2).getHost(), is("node-3.my-kube"));
async.flag();
}));
}
use of io.strimzi.api.kafka.model.status.KafkaStatus in project strimzi by strimzi.
the class KafkaReconcilerStatusTest method testKafkaReconcilerStatusWithNodePortsAndMissingNode.
@Test
public void testKafkaReconcilerStatusWithNodePortsAndMissingNode(VertxTestContext context) {
Kafka kafka = new KafkaBuilder(KAFKA).editOrNewSpec().editOrNewKafka().withListeners(new GenericKafkaListenerBuilder().withName("external").withPort(9094).withType(KafkaListenerType.NODEPORT).withTls(true).build()).endKafka().endSpec().build();
ResourceOperatorSupplier supplier = ResourceUtils.supplierWithMocks(false);
// Mock the secrets needed for Kafka client
SecretOperator mockSecretOps = supplier.secretOperations;
Secret secret = new Secret();
when(mockSecretOps.getAsync(eq(NAMESPACE), eq(KafkaResources.clusterCaCertificateSecretName(CLUSTER_NAME)))).thenReturn(Future.succeededFuture(secret));
when(mockSecretOps.getAsync(eq(NAMESPACE), eq(ClusterOperator.secretName(CLUSTER_NAME)))).thenReturn(Future.succeededFuture(secret));
// Mock Kafka broker pods
Pod pod0 = new PodBuilder().withNewMetadata().withName(CLUSTER_NAME + "-kafka-" + 0).endMetadata().withNewStatus().withHostIP("10.0.0.5").endStatus().build();
Pod pod1 = new PodBuilder().withNewMetadata().withName(CLUSTER_NAME + "-kafka-" + 1).endMetadata().withNewStatus().withHostIP("10.0.0.5").endStatus().build();
Pod pod2 = new PodBuilder().withNewMetadata().withName(CLUSTER_NAME + "-kafka-" + 2).endMetadata().withNewStatus().withHostIP("10.0.0.5").endStatus().build();
List<Pod> pods = new ArrayList<>();
pods.add(pod0);
pods.add(pod1);
pods.add(pod2);
PodOperator mockPodOps = supplier.podOperations;
when(mockPodOps.listAsync(eq(NAMESPACE), any(Labels.class))).thenReturn(Future.succeededFuture(pods));
// Mock Kubernetes worker nodes
NodeOperator mockNodeOps = supplier.nodeOperator;
when(mockNodeOps.listAsync(any(Labels.class))).thenReturn(Future.succeededFuture(kubernetesWorkerNodes()));
// Run the test
KafkaReconciler reconciler = new MockKafkaReconcilerStatusTasks(new Reconciliation("test-trigger", Kafka.RESOURCE_KIND, NAMESPACE, CLUSTER_NAME), supplier, kafka);
KafkaStatus status = new KafkaStatus();
Checkpoint async = context.checkpoint();
reconciler.reconcile(status, Date::new).onComplete(res -> context.verify(() -> {
assertThat(res.succeeded(), is(true));
// Check listener status
assertThat(status.getListeners().size(), is(1));
assertThat(status.getListeners().get(0).getName(), is("external"));
assertThat(status.getListeners().get(0).getType(), is("external"));
assertThat(status.getListeners().get(0).getBootstrapServers(), is(nullValue()));
assertThat(status.getListeners().get(0).getAddresses(), is(List.of()));
async.flag();
}));
}
use of io.strimzi.api.kafka.model.status.KafkaStatus in project strimzi by strimzi.
the class KafkaReconcilerStatusTest method testKafkaReconcilerStatusWithNodePortsAndOverrides.
@Test
public void testKafkaReconcilerStatusWithNodePortsAndOverrides(VertxTestContext context) {
GenericKafkaListenerConfigurationBroker broker0 = new GenericKafkaListenerConfigurationBrokerBuilder().withBroker(0).withAdvertisedHost("my-address-0").build();
GenericKafkaListenerConfigurationBroker broker1 = new GenericKafkaListenerConfigurationBrokerBuilder().withBroker(1).withAdvertisedHost("my-address-1").build();
Kafka kafka = new KafkaBuilder(KAFKA).editOrNewSpec().editOrNewKafka().withListeners(new GenericKafkaListenerBuilder().withName("external").withPort(9094).withType(KafkaListenerType.NODEPORT).withTls(true).withNewConfiguration().withBrokers(broker0, broker1).endConfiguration().build()).endKafka().endSpec().build();
ResourceOperatorSupplier supplier = ResourceUtils.supplierWithMocks(false);
// Mock the secrets needed for Kafka client
SecretOperator mockSecretOps = supplier.secretOperations;
Secret secret = new Secret();
when(mockSecretOps.getAsync(eq(NAMESPACE), eq(KafkaResources.clusterCaCertificateSecretName(CLUSTER_NAME)))).thenReturn(Future.succeededFuture(secret));
when(mockSecretOps.getAsync(eq(NAMESPACE), eq(ClusterOperator.secretName(CLUSTER_NAME)))).thenReturn(Future.succeededFuture(secret));
// Mock Kafka broker pods
Pod pod0 = new PodBuilder().withNewMetadata().withName(CLUSTER_NAME + "-kafka-" + 0).endMetadata().withNewStatus().withHostIP("10.0.0.1").endStatus().build();
Pod pod1 = new PodBuilder().withNewMetadata().withName(CLUSTER_NAME + "-kafka-" + 1).endMetadata().withNewStatus().withHostIP("10.0.0.25").endStatus().build();
Pod pod2 = new PodBuilder().withNewMetadata().withName(CLUSTER_NAME + "-kafka-" + 2).endMetadata().withNewStatus().withHostIP("10.0.0.13").endStatus().build();
List<Pod> pods = new ArrayList<>();
pods.add(pod0);
pods.add(pod1);
pods.add(pod2);
PodOperator mockPodOps = supplier.podOperations;
when(mockPodOps.listAsync(eq(NAMESPACE), any(Labels.class))).thenReturn(Future.succeededFuture(pods));
// Mock Kubernetes worker nodes
NodeOperator mockNodeOps = supplier.nodeOperator;
when(mockNodeOps.listAsync(any(Labels.class))).thenReturn(Future.succeededFuture(kubernetesWorkerNodes()));
// Run the test
KafkaReconciler reconciler = new MockKafkaReconcilerStatusTasks(new Reconciliation("test-trigger", Kafka.RESOURCE_KIND, NAMESPACE, CLUSTER_NAME), supplier, kafka);
KafkaStatus status = new KafkaStatus();
Checkpoint async = context.checkpoint();
reconciler.reconcile(status, Date::new).onComplete(res -> context.verify(() -> {
assertThat(res.succeeded(), is(true));
// Check listener status
assertThat(status.getListeners().size(), is(1));
assertThat(status.getListeners().get(0).getName(), is("external"));
assertThat(status.getListeners().get(0).getType(), is("external"));
assertThat(status.getListeners().get(0).getBootstrapServers(), is("my-address-0:31234,5.124.16.8:31234,my-address-1:31234"));
assertThat(status.getListeners().get(0).getAddresses().size(), is(3));
assertThat(status.getListeners().get(0).getAddresses().get(0).getPort(), is(31234));
assertThat(status.getListeners().get(0).getAddresses().get(0).getHost(), is("my-address-0"));
assertThat(status.getListeners().get(0).getAddresses().get(1).getPort(), is(31234));
assertThat(status.getListeners().get(0).getAddresses().get(1).getHost(), is("5.124.16.8"));
assertThat(status.getListeners().get(0).getAddresses().get(2).getPort(), is(31234));
assertThat(status.getListeners().get(0).getAddresses().get(2).getHost(), is("my-address-1"));
async.flag();
}));
}
use of io.strimzi.api.kafka.model.status.KafkaStatus in project strimzi by strimzi.
the class KafkaStatusTest method testInitialStatusOnNewResource.
@Test
public void testInitialStatusOnNewResource() throws ParseException {
Kafka kafka = getKafkaCrd();
kafka.setStatus(null);
ResourceOperatorSupplier supplier = ResourceUtils.supplierWithMocks(false);
// Mock the Kafka Operator
CrdOperator<KubernetesClient, Kafka, KafkaList> 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());
MockInitialStatusKafkaAssemblyOperator kao = new MockInitialStatusKafkaAssemblyOperator(vertx, new PlatformFeaturesAvailability(false, kubernetesVersion), certManager, passwordGenerator, supplier, config);
kao.reconcile(new Reconciliation("test-trigger", Kafka.RESOURCE_KIND, namespace, clusterName)).onComplete(res -> {
assertThat(res.succeeded(), is(true));
assertThat(kafkaCaptor.getAllValues().size(), is(2));
assertThat(kafkaCaptor.getAllValues().get(0).getStatus(), is(notNullValue()));
KafkaStatus status = kafkaCaptor.getAllValues().get(0).getStatus();
assertThat(status.getListeners(), is(nullValue()));
assertThat(status.getConditions().size(), is(1));
assertThat(status.getConditions().get(0).getType(), is("NotReady"));
assertThat(status.getConditions().get(0).getStatus(), is("True"));
assertThat(status.getConditions().get(0).getReason(), is("Creating"));
assertThat(status.getConditions().get(0).getMessage(), is("Kafka cluster is being deployed"));
});
}
use of io.strimzi.api.kafka.model.status.KafkaStatus in project strimzi-kafka-operator by strimzi.
the class KafkaAssemblyOperatorTest method testReconcileAllNamespaces.
@SuppressWarnings("unchecked")
@ParameterizedTest
@MethodSource("data")
@Timeout(value = 2, timeUnit = TimeUnit.MINUTES)
public void testReconcileAllNamespaces(Params params, VertxTestContext context) {
setFields(params);
// create CM, Service, headless service, statefulset
ResourceOperatorSupplier supplier = ResourceUtils.supplierWithMocks(openShift);
ClusterOperatorConfig config = ResourceUtils.dummyClusterOperatorConfig(VERSIONS);
var mockKafkaOps = supplier.kafkaOperator;
StatefulSetOperator mockStsOps = supplier.stsOperations;
SecretOperator mockSecretOps = supplier.secretOperations;
Kafka foo = getKafkaAssembly("foo");
foo.getMetadata().setNamespace("namespace1");
Kafka bar = getKafkaAssembly("bar");
bar.getMetadata().setNamespace("namespace2");
when(mockKafkaOps.listAsync(eq("*"), any(Optional.class))).thenReturn(Future.succeededFuture(asList(foo, bar)));
// when requested Custom Resource for a specific Kafka cluster
when(mockKafkaOps.get(eq("namespace1"), eq("foo"))).thenReturn(foo);
when(mockKafkaOps.get(eq("namespace2"), eq("bar"))).thenReturn(bar);
when(mockKafkaOps.getAsync(eq("namespace1"), eq("foo"))).thenReturn(Future.succeededFuture(foo));
when(mockKafkaOps.getAsync(eq("namespace2"), eq("bar"))).thenReturn(Future.succeededFuture(bar));
when(mockKafkaOps.updateStatusAsync(any(), any(Kafka.class))).thenReturn(Future.succeededFuture());
// providing certificates Secrets for existing clusters
List<Secret> barSecrets = ResourceUtils.createKafkaSecretsWithReplicas("namespace2", "bar", bar.getSpec().getKafka().getReplicas(), bar.getSpec().getZookeeper().getReplicas());
ClusterCa barClusterCa = ResourceUtils.createInitialClusterCa(Reconciliation.DUMMY_RECONCILIATION, "bar", findSecretWithName(barSecrets, AbstractModel.clusterCaCertSecretName("bar")), findSecretWithName(barSecrets, AbstractModel.clusterCaKeySecretName("bar")));
ClientsCa barClientsCa = ResourceUtils.createInitialClientsCa(Reconciliation.DUMMY_RECONCILIATION, "bar", findSecretWithName(barSecrets, KafkaResources.clientsCaCertificateSecretName("bar")), findSecretWithName(barSecrets, KafkaResources.clientsCaKeySecretName("bar")));
// providing the list of ALL StatefulSets for all the Kafka clusters
Labels newLabels = Labels.forStrimziKind(Kafka.RESOURCE_KIND);
when(mockStsOps.list(eq("*"), eq(newLabels))).thenReturn(List.of(KafkaCluster.fromCrd(Reconciliation.DUMMY_RECONCILIATION, bar, VERSIONS).generateStatefulSet(openShift, null, null, null)));
// providing the list StatefulSets for already "existing" Kafka clusters
Labels barLabels = Labels.forStrimziCluster("bar");
KafkaCluster barCluster = KafkaCluster.fromCrd(Reconciliation.DUMMY_RECONCILIATION, bar, VERSIONS);
when(mockStsOps.list(eq("*"), eq(barLabels))).thenReturn(List.of(barCluster.generateStatefulSet(openShift, null, null, null)));
when(mockSecretOps.list(eq("*"), eq(barLabels))).thenAnswer(invocation -> new ArrayList<>(asList(barClientsCa.caKeySecret(), barClientsCa.caCertSecret(), barCluster.generateCertificatesSecret(barClusterCa, barClientsCa, Set.of(), Map.of(), true), barClusterCa.caCertSecret())));
Checkpoint fooAsync = context.checkpoint();
Checkpoint barAsync = context.checkpoint();
KafkaAssemblyOperator ops = new KafkaAssemblyOperator(vertx, new PlatformFeaturesAvailability(openShift, kubernetesVersion), certManager, passwordGenerator, supplier, config) {
@Override
public Future<KafkaStatus> createOrUpdate(Reconciliation reconciliation, Kafka kafkaAssembly) {
String name = kafkaAssembly.getMetadata().getName();
if ("foo".equals(name)) {
fooAsync.flag();
} else if ("bar".equals(name)) {
barAsync.flag();
} else {
context.failNow(new AssertionError("Unexpected name " + name));
}
return Future.succeededFuture();
}
};
Checkpoint async = context.checkpoint();
// Now try to reconcile all the Kafka clusters
ops.reconcileAll("test", "*", context.succeeding(v -> async.flag()));
}
Aggregations