use of io.strimzi.controller.cluster.Reconciliation in project strimzi by strimzi.
the class KafkaConnectAssemblyOperatorTest method testUpdateCluster.
@Test
public void testUpdateCluster(TestContext context) {
ConfigMapOperator mockCmOps = mock(ConfigMapOperator.class);
ServiceOperator mockServiceOps = mock(ServiceOperator.class);
DeploymentOperator mockDcOps = mock(DeploymentOperator.class);
String clusterCmName = "foo";
String clusterCmNamespace = "test";
ConfigMap clusterCm = ResourceUtils.createEmptyKafkaConnectClusterConfigMap(clusterCmNamespace, clusterCmName);
KafkaConnectCluster connect = KafkaConnectCluster.fromConfigMap(clusterCm);
// Change the image to generate some diff
clusterCm.getData().put("image", "some/different:image");
when(mockCmOps.get(clusterCmNamespace, clusterCmName)).thenReturn(clusterCm);
when(mockServiceOps.get(clusterCmNamespace, connect.getName())).thenReturn(connect.generateService());
when(mockDcOps.get(clusterCmNamespace, connect.getName())).thenReturn(connect.generateDeployment());
ArgumentCaptor<String> serviceNameCaptor = ArgumentCaptor.forClass(String.class);
ArgumentCaptor<Service> serviceCaptor = ArgumentCaptor.forClass(Service.class);
when(mockServiceOps.reconcile(eq(clusterCmNamespace), serviceNameCaptor.capture(), serviceCaptor.capture())).thenReturn(Future.succeededFuture());
ArgumentCaptor<String> dcNameCaptor = ArgumentCaptor.forClass(String.class);
ArgumentCaptor<Deployment> dcCaptor = ArgumentCaptor.forClass(Deployment.class);
when(mockDcOps.reconcile(eq(clusterCmNamespace), dcNameCaptor.capture(), dcCaptor.capture())).thenReturn(Future.succeededFuture());
ArgumentCaptor<String> dcScaleUpNameCaptor = ArgumentCaptor.forClass(String.class);
ArgumentCaptor<Integer> dcScaleUpReplicasCaptor = ArgumentCaptor.forClass(Integer.class);
when(mockDcOps.scaleUp(eq(clusterCmNamespace), dcScaleUpNameCaptor.capture(), dcScaleUpReplicasCaptor.capture())).thenReturn(Future.succeededFuture());
ArgumentCaptor<String> dcScaleDownNameCaptor = ArgumentCaptor.forClass(String.class);
ArgumentCaptor<Integer> dcScaleDownReplicasCaptor = ArgumentCaptor.forClass(Integer.class);
when(mockDcOps.scaleDown(eq(clusterCmNamespace), dcScaleDownNameCaptor.capture(), dcScaleDownReplicasCaptor.capture())).thenReturn(Future.succeededFuture());
KafkaConnectAssemblyOperator ops = new KafkaConnectAssemblyOperator(vertx, true, mockCmOps, mockDcOps, mockServiceOps);
Async async = context.async();
ops.createOrUpdate(new Reconciliation("test-trigger", AssemblyType.CONNECT, clusterCmNamespace, clusterCmName), clusterCm, createResult -> {
context.assertTrue(createResult.succeeded());
KafkaConnectCluster compareTo = KafkaConnectCluster.fromConfigMap(clusterCm);
// Vertify service
List<Service> capturedServices = serviceCaptor.getAllValues();
context.assertEquals(1, capturedServices.size());
Service service = capturedServices.get(0);
context.assertEquals(compareTo.getName(), service.getMetadata().getName());
context.assertEquals(compareTo.generateService(), service, "Services are not equal");
// Verify Deployment
List<Deployment> capturedDc = dcCaptor.getAllValues();
context.assertEquals(1, capturedDc.size());
Deployment dc = capturedDc.get(0);
context.assertEquals(compareTo.getName(), dc.getMetadata().getName());
context.assertEquals(compareTo.generateDeployment(), dc, "Deployments are not equal");
// Verify scaleDown / scaleUp were not called
context.assertEquals(1, dcScaleDownNameCaptor.getAllValues().size());
context.assertEquals(1, dcScaleUpNameCaptor.getAllValues().size());
async.complete();
});
}
use of io.strimzi.controller.cluster.Reconciliation in project strimzi by strimzi.
the class KafkaConnectAssemblyOperatorTest method testReconcile.
@Test
public void testReconcile(TestContext context) {
ConfigMapOperator mockCmOps = mock(ConfigMapOperator.class);
ServiceOperator mockServiceOps = mock(ServiceOperator.class);
DeploymentOperator mockDcOps = mock(DeploymentOperator.class);
String clusterCmNamespace = "test";
ConfigMap foo = ResourceUtils.createEmptyKafkaConnectClusterConfigMap(clusterCmNamespace, "foo");
ConfigMap bar = ResourceUtils.createEmptyKafkaConnectClusterConfigMap(clusterCmNamespace, "bar");
ConfigMap baz = ResourceUtils.createEmptyKafkaConnectClusterConfigMap(clusterCmNamespace, "baz");
when(mockCmOps.list(eq(clusterCmNamespace), any())).thenReturn(asList(foo, bar));
// when requested ConfigMap for a specific Kafka Connect cluster
when(mockCmOps.get(eq(clusterCmNamespace), eq("foo"))).thenReturn(foo);
when(mockCmOps.get(eq(clusterCmNamespace), eq("bar"))).thenReturn(bar);
// providing the list of ALL Deployments for all the Kafka Connect clusters
Labels newLabels = Labels.forType(AssemblyType.CONNECT);
when(mockDcOps.list(eq(clusterCmNamespace), eq(newLabels))).thenReturn(asList(KafkaConnectCluster.fromConfigMap(bar).generateDeployment(), KafkaConnectCluster.fromConfigMap(baz).generateDeployment()));
// providing the list Deployments for already "existing" Kafka Connect clusters
Labels barLabels = Labels.forCluster("bar");
when(mockDcOps.list(eq(clusterCmNamespace), eq(barLabels))).thenReturn(asList(KafkaConnectCluster.fromConfigMap(bar).generateDeployment()));
Labels bazLabels = Labels.forCluster("baz");
when(mockDcOps.list(eq(clusterCmNamespace), eq(bazLabels))).thenReturn(asList(KafkaConnectCluster.fromConfigMap(baz).generateDeployment()));
Set<String> createdOrUpdated = new HashSet<>();
Set<String> deleted = new HashSet<>();
Async async = context.async(3);
KafkaConnectAssemblyOperator ops = new KafkaConnectAssemblyOperator(vertx, true, mockCmOps, mockDcOps, mockServiceOps) {
@Override
public void createOrUpdate(Reconciliation reconciliation, ConfigMap assemblyCm, Handler h) {
createdOrUpdated.add(assemblyCm.getMetadata().getName());
async.countDown();
h.handle(Future.succeededFuture());
}
@Override
public void delete(Reconciliation reconciliation, Handler h) {
deleted.add(reconciliation.assemblyName());
async.countDown();
h.handle(Future.succeededFuture());
}
};
// Now try to reconcile all the Kafka Connect clusters
ops.reconcileAll("test", clusterCmNamespace, Labels.EMPTY);
async.await();
context.assertEquals(new HashSet(asList("foo", "bar")), createdOrUpdated);
context.assertEquals(singleton("baz"), deleted);
}
use of io.strimzi.controller.cluster.Reconciliation in project strimzi by strimzi.
the class KafkaConnectAssemblyOperatorTest method testUpdateClusterScaleDown.
@Test
public void testUpdateClusterScaleDown(TestContext context) {
int scaleTo = 2;
String newReplicas = String.valueOf(scaleTo);
ConfigMapOperator mockCmOps = mock(ConfigMapOperator.class);
ServiceOperator mockServiceOps = mock(ServiceOperator.class);
DeploymentOperator mockDcOps = mock(DeploymentOperator.class);
String clusterCmName = "foo";
String clusterCmNamespace = "test";
ConfigMap clusterCm = ResourceUtils.createEmptyKafkaConnectClusterConfigMap(clusterCmNamespace, clusterCmName);
KafkaConnectCluster connect = KafkaConnectCluster.fromConfigMap(clusterCm);
// Change replicas to create ScaleDown
clusterCm.getData().put(KafkaConnectCluster.KEY_REPLICAS, newReplicas);
when(mockCmOps.get(clusterCmNamespace, clusterCmName)).thenReturn(clusterCm);
when(mockServiceOps.get(clusterCmNamespace, connect.getName())).thenReturn(connect.generateService());
when(mockDcOps.get(clusterCmNamespace, connect.getName())).thenReturn(connect.generateDeployment());
when(mockServiceOps.reconcile(eq(clusterCmNamespace), any(), any())).thenReturn(Future.succeededFuture());
when(mockDcOps.reconcile(eq(clusterCmNamespace), any(), any())).thenReturn(Future.succeededFuture());
doAnswer(i -> Future.succeededFuture(scaleTo)).when(mockDcOps).scaleUp(clusterCmNamespace, connect.getName(), scaleTo);
doAnswer(i -> Future.succeededFuture(scaleTo)).when(mockDcOps).scaleDown(clusterCmNamespace, connect.getName(), scaleTo);
KafkaConnectAssemblyOperator ops = new KafkaConnectAssemblyOperator(vertx, true, mockCmOps, mockDcOps, mockServiceOps);
Async async = context.async();
ops.createOrUpdate(new Reconciliation("test-trigger", AssemblyType.CONNECT, clusterCmNamespace, clusterCmName), clusterCm, createResult -> {
context.assertTrue(createResult.succeeded());
verify(mockDcOps).scaleUp(clusterCmNamespace, connect.getName(), scaleTo);
async.complete();
});
}
use of io.strimzi.controller.cluster.Reconciliation in project strimzi by strimzi.
the class KafkaAssemblyOperatorMockIT method deleteClusterWithoutServices.
private void deleteClusterWithoutServices(TestContext context, String... services) {
KafkaAssemblyOperator kco = createCluster(context);
Set<String> ssNames = mockClient.apps().statefulSets().inNamespace(NAMESPACE).list().getItems().stream().map(r -> r.getMetadata().getName()).collect(Collectors.toSet());
Set<String> deploymentNames = mockClient.extensions().deployments().inNamespace(NAMESPACE).list().getItems().stream().map(r -> r.getMetadata().getName()).collect(Collectors.toSet());
Set<String> cmNames = new HashSet<>(mockClient.configMaps().inNamespace(NAMESPACE).list().getItems().stream().map(r -> r.getMetadata().getName()).collect(Collectors.toSet()));
cmNames.remove(CLUSTER_NAME);
Set<String> pvcNames = mockClient.persistentVolumeClaims().inNamespace(NAMESPACE).list().getItems().stream().map(r -> r.getMetadata().getName()).collect(Collectors.toSet());
for (String service : services) {
mockClient.services().inNamespace(NAMESPACE).withName(service).delete();
assertNull("Expected service " + service + " to be not exist", mockClient.services().inNamespace(NAMESPACE).withName(service).get());
}
LOGGER.info("Deleting");
mockClient.configMaps().inNamespace(NAMESPACE).withName(CLUSTER_NAME).delete();
Async updateAsync = context.async();
kco.reconcileAssembly(new Reconciliation("test-trigger", AssemblyType.KAFKA, NAMESPACE, CLUSTER_NAME), ar -> {
if (ar.failed())
ar.cause().printStackTrace();
context.assertTrue(ar.succeeded());
for (String service : services) {
assertNull("Expected service " + service + " to still not exist", mockClient.services().inNamespace(NAMESPACE).withName(service).get());
}
for (String ss : ssNames) {
assertNull("Expected ss " + ss + " to still not exist", mockClient.apps().statefulSets().inNamespace(NAMESPACE).withName(ss).get());
}
// assert other resources do not exist either
for (String r : ssNames) {
assertNull("Expected r " + r + " to still not exist", mockClient.apps().statefulSets().inNamespace(NAMESPACE).withName(r).get());
}
for (String r : deploymentNames) {
assertNull("Expected r " + r + " to still not exist", mockClient.extensions().deployments().inNamespace(NAMESPACE).withName(r).get());
}
for (String r : cmNames) {
assertNull("Expected r " + r + " to still not exist", mockClient.configMaps().inNamespace(NAMESPACE).withName(r).get());
}
for (String r : pvcNames) {
assertNull("Expected r " + r + " to still not exist", mockClient.persistentVolumeClaims().inNamespace(NAMESPACE).withName(r).get());
}
updateAsync.complete();
});
}
use of io.strimzi.controller.cluster.Reconciliation in project strimzi by strimzi.
the class KafkaAssemblyOperatorMockIT method deleteClusterWithoutStatefulSet.
private void deleteClusterWithoutStatefulSet(TestContext context, String... statefulSets) {
KafkaAssemblyOperator kco = createCluster(context);
Set<String> ssNames = mockClient.apps().statefulSets().inNamespace(NAMESPACE).list().getItems().stream().map(r -> r.getMetadata().getName()).collect(Collectors.toSet());
Set<String> serviceNames = mockClient.services().inNamespace(NAMESPACE).list().getItems().stream().map(r -> r.getMetadata().getName()).collect(Collectors.toSet());
Set<String> deploymentNames = mockClient.extensions().deployments().inNamespace(NAMESPACE).list().getItems().stream().map(r -> r.getMetadata().getName()).collect(Collectors.toSet());
Set<String> cmNames = new HashSet<>(mockClient.configMaps().inNamespace(NAMESPACE).list().getItems().stream().map(r -> r.getMetadata().getName()).collect(Collectors.toSet()));
cmNames.remove(CLUSTER_NAME);
Set<String> pvcNames = mockClient.persistentVolumeClaims().inNamespace(NAMESPACE).list().getItems().stream().map(r -> r.getMetadata().getName()).collect(Collectors.toSet());
for (String ss : statefulSets) {
mockClient.apps().statefulSets().inNamespace(NAMESPACE).withName(ss).delete();
assertNull("Expected ss " + ss + " to be not exist", mockClient.apps().statefulSets().inNamespace(NAMESPACE).withName(ss).get());
}
LOGGER.info("Deleting");
mockClient.configMaps().inNamespace(NAMESPACE).withName(CLUSTER_NAME).delete();
Async updateAsync = context.async();
kco.reconcileAssembly(new Reconciliation("test-trigger", AssemblyType.KAFKA, NAMESPACE, CLUSTER_NAME), ar -> {
if (ar.failed())
ar.cause().printStackTrace();
context.assertTrue(ar.succeeded());
for (String ss : statefulSets) {
assertNull("Expected ss " + ss + " to still not exist", mockClient.apps().statefulSets().inNamespace(NAMESPACE).withName(ss).get());
}
// assert other resources do not exist either
for (String r : ssNames) {
assertNull("Expected r " + r + " to still not exist", mockClient.apps().statefulSets().inNamespace(NAMESPACE).withName(r).get());
}
for (String r : serviceNames) {
assertNull("Expected r " + r + " to still not exist", mockClient.services().inNamespace(NAMESPACE).withName(r).get());
}
for (String r : deploymentNames) {
assertNull("Expected r " + r + " to still not exist", mockClient.extensions().deployments().inNamespace(NAMESPACE).withName(r).get());
}
for (String r : cmNames) {
assertNull("Expected r " + r + " to still not exist", mockClient.configMaps().inNamespace(NAMESPACE).withName(r).get());
}
for (String r : pvcNames) {
assertNull("Expected r " + r + " to still not exist", mockClient.persistentVolumeClaims().inNamespace(NAMESPACE).withName(r).get());
}
updateAsync.complete();
});
}
Aggregations