use of io.fabric8.kubernetes.assertions.Assertions in project strimzi by strimzi.
the class OpenShiftTemplatesTest method testStrimziPersistentWithCustomParameters.
@Test
public void testStrimziPersistentWithCustomParameters() throws IOException {
String clusterName = "test-persistent-with-custom-parameters";
oc.newApp("strimzi-persistent", map("CLUSTER_NAME", clusterName, "ZOOKEEPER_HEALTHCHECK_DELAY", "30", "ZOOKEEPER_HEALTHCHECK_TIMEOUT", "10", "KAFKA_HEALTHCHECK_DELAY", "30", "KAFKA_HEALTHCHECK_TIMEOUT", "10", "KAFKA_DEFAULT_REPLICATION_FACTOR", "2", "KAFKA_OFFSETS_TOPIC_REPLICATION_FACTOR", "5", "KAFKA_TRANSACTION_STATE_LOG_REPLICATION_FACTOR", "5", "ZOOKEEPER_VOLUME_CAPACITY", "2Gi", "KAFKA_VOLUME_CAPACITY", "2Gi"));
// TODO Add assertions to check that Kafka brokers have a custom configuration
ConfigMap cm = client.configMaps().inNamespace(NAMESPACE).withName(clusterName).get();
assertNotNull(cm);
Map<String, String> cmData = cm.getData();
assertEquals("30", cmData.get("zookeeper-healthcheck-delay"));
assertEquals("10", cmData.get("zookeeper-healthcheck-timeout"));
assertEquals("30", cmData.get("kafka-healthcheck-delay"));
assertEquals("10", cmData.get("kafka-healthcheck-timeout"));
assertEquals("2", cmData.get("KAFKA_DEFAULT_REPLICATION_FACTOR"));
assertEquals("5", cmData.get("KAFKA_OFFSETS_TOPIC_REPLICATION_FACTOR"));
assertEquals("5", cmData.get("KAFKA_TRANSACTION_STATE_LOG_REPLICATION_FACTOR"));
assertEquals("2Gi", mapper.readTree(cmData.get("kafka-storage")).get("size").asText());
assertEquals("2Gi", mapper.readTree(cmData.get("zookeeper-storage")).get("size").asText());
}
use of io.fabric8.kubernetes.assertions.Assertions in project fabric8 by fabric8io.
the class KubernetesAssert method deployments.
/**
* Finds all the resources that create pod selections (Deployment, DeploymentConfig, ReplicaSet, ReplicationController)
* and create a {@link HasPodSelectionAssert} to make assertions on their pods that they startup etc.
*
* @return the assertion object for the deployment
*/
public HasPodSelectionAssert deployments() {
List<HasPodSelectionAssert> asserters = new ArrayList<>();
List<HasMetadata> resources = new ArrayList<>();
try {
resources = KubernetesHelper.findKubernetesResourcesOnClasspath(new Controller(client));
} catch (IOException e) {
fail("Failed to load kubernetes resources on the classpath: " + e, e);
}
for (HasMetadata resource : resources) {
HasPodSelectionAssert asserter = createPodSelectionAssert(resource);
if (asserter != null) {
asserters.add(asserter);
}
}
String message = "No pod selection kinds found on the classpath such as Deployment, DeploymentConfig, ReplicaSet, ReplicationController";
// TODO we don't yet support size > 1
assertThat(asserters).describedAs(message).isNotEmpty();
if (asserters.size() == 1) {
return asserters.get(0);
}
return new MultiHasPodSelectionAssert(asserters);
}
use of io.fabric8.kubernetes.assertions.Assertions in project strimzi by strimzi.
the class KafkaAssemblyOperatorTest method createCluster.
private void createCluster(TestContext context, ConfigMap clusterCm) {
// create CM, Service, headless service, statefulset and so on
ConfigMapOperator mockCmOps = mock(ConfigMapOperator.class);
ServiceOperator mockServiceOps = mock(ServiceOperator.class);
ZookeeperSetOperator mockZsOps = mock(ZookeeperSetOperator.class);
KafkaSetOperator mockKsOps = mock(KafkaSetOperator.class);
PvcOperator mockPvcOps = mock(PvcOperator.class);
DeploymentOperator mockDepOps = mock(DeploymentOperator.class);
// Create a CM
String clusterCmName = clusterCm.getMetadata().getName();
String clusterCmNamespace = clusterCm.getMetadata().getNamespace();
when(mockCmOps.get(clusterCmNamespace, clusterCmName)).thenReturn(clusterCm);
ArgumentCaptor<Service> serviceCaptor = ArgumentCaptor.forClass(Service.class);
when(mockServiceOps.reconcile(anyString(), anyString(), serviceCaptor.capture())).thenReturn(Future.succeededFuture(ReconcileResult.created()));
when(mockServiceOps.endpointReadiness(anyString(), any(), anyLong(), anyLong())).thenReturn(Future.succeededFuture());
ArgumentCaptor<StatefulSet> ssCaptor = ArgumentCaptor.forClass(StatefulSet.class);
when(mockZsOps.reconcile(anyString(), anyString(), ssCaptor.capture())).thenReturn(Future.succeededFuture(ReconcileResult.created()));
when(mockZsOps.scaleDown(anyString(), anyString(), anyInt())).thenReturn(Future.succeededFuture(null));
when(mockZsOps.rollingUpdate(anyString(), anyString())).thenReturn(Future.succeededFuture());
when(mockZsOps.scaleUp(anyString(), anyString(), anyInt())).thenReturn(Future.succeededFuture(42));
when(mockKsOps.reconcile(anyString(), anyString(), ssCaptor.capture())).thenReturn(Future.succeededFuture(ReconcileResult.created()));
when(mockKsOps.scaleDown(anyString(), anyString(), anyInt())).thenReturn(Future.succeededFuture(null));
when(mockKsOps.rollingUpdate(anyString(), anyString())).thenReturn(Future.succeededFuture());
when(mockKsOps.scaleUp(anyString(), anyString(), anyInt())).thenReturn(Future.succeededFuture(42));
ArgumentCaptor<Deployment> depCaptor = ArgumentCaptor.forClass(Deployment.class);
when(mockDepOps.reconcile(anyString(), anyString(), depCaptor.capture())).thenReturn(Future.succeededFuture(ReconcileResult.created()));
// when(mockSsOps.readiness(any(), any(), anyLong(), anyLong())).thenReturn(Future.succeededFuture());
// when(mockPodOps.readiness(any(), any(), anyLong(), anyLong())).thenReturn(Future.succeededFuture());
// when(mockEndpointOps.readiness(any(), any(), anyLong(), anyLong())).thenReturn(Future.succeededFuture());
KafkaCluster kafkaCluster = KafkaCluster.fromConfigMap(clusterCm);
ZookeeperCluster zookeeperCluster = ZookeeperCluster.fromConfigMap(clusterCm);
TopicController topicController = TopicController.fromConfigMap(clusterCm);
ArgumentCaptor<ConfigMap> metricsCaptor = ArgumentCaptor.forClass(ConfigMap.class);
ArgumentCaptor<String> metricsNameCaptor = ArgumentCaptor.forClass(String.class);
when(mockCmOps.reconcile(anyString(), metricsNameCaptor.capture(), metricsCaptor.capture())).thenReturn(Future.succeededFuture(ReconcileResult.created()));
KafkaAssemblyOperator ops = new KafkaAssemblyOperator(vertx, openShift, ClusterControllerConfig.DEFAULT_OPERATION_TIMEOUT_MS, mockCmOps, mockServiceOps, mockZsOps, mockKsOps, mockPvcOps, mockDepOps);
// Now try to create a KafkaCluster based on this CM
Async async = context.async();
ops.createOrUpdate(new Reconciliation("test-trigger", AssemblyType.KAFKA, clusterCmNamespace, clusterCmName), clusterCm, createResult -> {
if (createResult.failed()) {
createResult.cause().printStackTrace();
}
context.assertTrue(createResult.succeeded());
// No metrics config => no CMs created
Set<String> metricsNames = new HashSet<>();
if (kafkaCluster.isMetricsEnabled()) {
metricsNames.add(KafkaCluster.metricConfigsName(clusterCmName));
}
if (zookeeperCluster.isMetricsEnabled()) {
metricsNames.add(ZookeeperCluster.zookeeperMetricsName(clusterCmName));
}
/*
Map<String, ConfigMap> cmsByName = new HashMap<>();
Iterator<ConfigMap> it2 = metricsCaptor.getAllValues().iterator();
for (Iterator<String> it = metricsNameCaptor.getAllValues().iterator(); it.hasNext(); ) {
cmsByName.put(it.next(), it2.next());
}
context.assertEquals(metricsNames, cmsByName.keySet(),
"Unexpected metrics ConfigMaps");
if (kafkaCluster.isMetricsEnabled()) {
ConfigMap kafkaMetricsCm = cmsByName.get(KafkaCluster.metricConfigsName(clusterCmName));
context.assertEquals(ResourceUtils.labels(Labels.STRIMZI_TYPE_LABEL, "kafka",
Labels.STRIMZI_CLUSTER_LABEL, clusterCmName,
"my-user-label", "cromulent"), kafkaMetricsCm.getMetadata().getLabels());
}
if (zookeeperCluster.isMetricsEnabled()) {
ConfigMap zookeeperMetricsCm = cmsByName.get(ZookeeperCluster.zookeeperMetricsName(clusterCmName));
context.assertEquals(ResourceUtils.labels(Labels.STRIMZI_TYPE_LABEL, "zookeeper",
Labels.STRIMZI_CLUSTER_LABEL, clusterCmName,
"my-user-label", "cromulent"), zookeeperMetricsCm.getMetadata().getLabels());
}*/
// We expect a headless and headful service
List<Service> capturedServices = serviceCaptor.getAllValues();
context.assertEquals(4, capturedServices.size());
context.assertEquals(set(KafkaCluster.kafkaClusterName(clusterCmName), KafkaCluster.headlessName(clusterCmName), ZookeeperCluster.zookeeperClusterName(clusterCmName), ZookeeperCluster.zookeeperHeadlessName(clusterCmName)), capturedServices.stream().map(svc -> svc.getMetadata().getName()).collect(Collectors.toSet()));
// Assertions on the statefulset
List<StatefulSet> capturedSs = ssCaptor.getAllValues();
// We expect a statefulSet for kafka and zookeeper...
context.assertEquals(set(KafkaCluster.kafkaClusterName(clusterCmName), ZookeeperCluster.zookeeperClusterName(clusterCmName)), capturedSs.stream().map(ss -> ss.getMetadata().getName()).collect(Collectors.toSet()));
// if topic controller configuration was defined in the CM
if (topicController != null) {
List<Deployment> capturedDeps = depCaptor.getAllValues();
context.assertEquals(1, capturedDeps.size());
context.assertEquals(TopicController.topicControllerName(clusterCmName), capturedDeps.get(0).getMetadata().getName());
}
// PvcOperations only used for deletion
verifyNoMoreInteractions(mockPvcOps);
async.complete();
});
}
use of io.fabric8.kubernetes.assertions.Assertions in project strimzi by strimzi.
the class OpenShiftTemplatesTest method testStrimziEphemeralWithCustomParameters.
@Test
public void testStrimziEphemeralWithCustomParameters() {
String clusterName = "test-ephemeral-with-custom-parameters";
oc.newApp("strimzi-ephemeral", map("CLUSTER_NAME", clusterName, "ZOOKEEPER_HEALTHCHECK_DELAY", "30", "ZOOKEEPER_HEALTHCHECK_TIMEOUT", "10", "KAFKA_HEALTHCHECK_DELAY", "30", "KAFKA_HEALTHCHECK_TIMEOUT", "10", "KAFKA_DEFAULT_REPLICATION_FACTOR", "2", "KAFKA_OFFSETS_TOPIC_REPLICATION_FACTOR", "5", "KAFKA_TRANSACTION_STATE_LOG_REPLICATION_FACTOR", "5"));
// TODO Add assertions to check that Kafka brokers have a custom configuration
ConfigMap cm = client.configMaps().inNamespace(NAMESPACE).withName(clusterName).get();
assertNotNull(cm);
Map<String, String> cmData = cm.getData();
assertEquals("30", cmData.get("zookeeper-healthcheck-delay"));
assertEquals("10", cmData.get("zookeeper-healthcheck-timeout"));
assertEquals("30", cmData.get("kafka-healthcheck-delay"));
assertEquals("10", cmData.get("kafka-healthcheck-timeout"));
assertEquals("2", cmData.get("KAFKA_DEFAULT_REPLICATION_FACTOR"));
assertEquals("5", cmData.get("KAFKA_OFFSETS_TOPIC_REPLICATION_FACTOR"));
assertEquals("5", cmData.get("KAFKA_TRANSACTION_STATE_LOG_REPLICATION_FACTOR"));
}
Aggregations