use of io.strimzi.operator.common.operator.resource.ConfigMapOperator in project strimzi by strimzi.
the class KafkaBridgeAssemblyOperatorTest method testCreateOrUpdateWithNoDiffCausesNoChanges.
@Test
public void testCreateOrUpdateWithNoDiffCausesNoChanges(VertxTestContext context) {
ResourceOperatorSupplier supplier = ResourceUtils.supplierWithMocks(true);
var mockBridgeOps = supplier.kafkaBridgeOperator;
DeploymentOperator mockDcOps = supplier.deploymentOperations;
PodDisruptionBudgetOperator mockPdbOps = supplier.podDisruptionBudgetOperator;
ConfigMapOperator mockCmOps = supplier.configMapOperations;
ServiceOperator mockServiceOps = supplier.serviceOperations;
String kbName = "foo";
String kbNamespace = "test";
KafkaBridge kb = ResourceUtils.createKafkaBridge(kbNamespace, kbName, image, 1, BOOTSTRAP_SERVERS, KAFKA_BRIDGE_PRODUCER_SPEC, KAFKA_BRIDGE_CONSUMER_SPEC, KAFKA_BRIDGE_HTTP_SPEC, true);
KafkaBridgeCluster bridge = KafkaBridgeCluster.fromCrd(Reconciliation.DUMMY_RECONCILIATION, kb, VERSIONS);
when(mockBridgeOps.get(kbNamespace, kbName)).thenReturn(kb);
when(mockBridgeOps.getAsync(anyString(), anyString())).thenReturn(Future.succeededFuture(kb));
when(mockBridgeOps.updateStatusAsync(any(), any(KafkaBridge.class))).thenReturn(Future.succeededFuture());
when(mockServiceOps.get(kbNamespace, bridge.getName())).thenReturn(bridge.generateService());
when(mockDcOps.get(kbNamespace, bridge.getName())).thenReturn(bridge.generateDeployment(Map.of(), true, null, null));
when(mockDcOps.readiness(any(), anyString(), anyString(), anyLong(), anyLong())).thenReturn(Future.succeededFuture());
when(mockDcOps.waitForObserved(any(), anyString(), anyString(), anyLong(), anyLong())).thenReturn(Future.succeededFuture());
ArgumentCaptor<String> serviceNameCaptor = ArgumentCaptor.forClass(String.class);
ArgumentCaptor<Service> serviceCaptor = ArgumentCaptor.forClass(Service.class);
when(mockServiceOps.reconcile(any(), eq(kbNamespace), serviceNameCaptor.capture(), serviceCaptor.capture())).thenReturn(Future.succeededFuture());
ArgumentCaptor<String> dcNameCaptor = ArgumentCaptor.forClass(String.class);
ArgumentCaptor<Deployment> dcCaptor = ArgumentCaptor.forClass(Deployment.class);
when(mockDcOps.reconcile(any(), eq(kbNamespace), dcNameCaptor.capture(), dcCaptor.capture())).thenReturn(Future.succeededFuture());
ArgumentCaptor<String> dcScaleUpNameCaptor = ArgumentCaptor.forClass(String.class);
ArgumentCaptor<Integer> dcScaleUpReplicasCaptor = ArgumentCaptor.forClass(Integer.class);
when(mockDcOps.scaleUp(any(), eq(kbNamespace), dcScaleUpNameCaptor.capture(), dcScaleUpReplicasCaptor.capture())).thenReturn(Future.succeededFuture());
ArgumentCaptor<String> dcScaleDownNameCaptor = ArgumentCaptor.forClass(String.class);
ArgumentCaptor<Integer> dcScaleDownReplicasCaptor = ArgumentCaptor.forClass(Integer.class);
when(mockDcOps.scaleDown(any(), eq(kbNamespace), dcScaleDownNameCaptor.capture(), dcScaleDownReplicasCaptor.capture())).thenReturn(Future.succeededFuture());
ArgumentCaptor<PodDisruptionBudget> pdbCaptor = ArgumentCaptor.forClass(PodDisruptionBudget.class);
when(mockPdbOps.reconcile(any(), anyString(), any(), pdbCaptor.capture())).thenReturn(Future.succeededFuture());
when(mockCmOps.reconcile(any(), anyString(), any(), any())).thenReturn(Future.succeededFuture(ReconcileResult.created(new ConfigMap())));
KafkaBridgeAssemblyOperator ops = new KafkaBridgeAssemblyOperator(vertx, new PlatformFeaturesAvailability(true, kubernetesVersion), new MockCertManager(), new PasswordGenerator(10, "a", "a"), supplier, ResourceUtils.dummyClusterOperatorConfig(VERSIONS));
Checkpoint async = context.checkpoint();
ops.createOrUpdate(new Reconciliation("test-trigger", KafkaBridge.RESOURCE_KIND, kbNamespace, kbName), kb).onComplete(context.succeeding(v -> context.verify(() -> {
// Verify service
List<Service> capturedServices = serviceCaptor.getAllValues();
assertThat(capturedServices, hasSize(1));
// Verify Deployment Config
List<Deployment> capturedDc = dcCaptor.getAllValues();
assertThat(capturedDc, hasSize(1));
// Verify PodDisruptionBudget
List<PodDisruptionBudget> capturedPdb = pdbCaptor.getAllValues();
assertThat(capturedPdb, hasSize(1));
PodDisruptionBudget pdb = capturedPdb.get(0);
assertThat(pdb.getMetadata().getName(), is(bridge.getName()));
assertThat(pdb, is(bridge.generatePodDisruptionBudget()));
// Verify scaleDown / scaleUp were not called
assertThat(dcScaleDownNameCaptor.getAllValues(), hasSize(1));
assertThat(dcScaleUpNameCaptor.getAllValues(), hasSize(1));
async.flag();
})));
}
use of io.strimzi.operator.common.operator.resource.ConfigMapOperator in project strimzi by strimzi.
the class KafkaMirrorMakerAssemblyOperatorTest method testUpdateClusterFailure.
@Test
public void testUpdateClusterFailure(VertxTestContext context) {
ResourceOperatorSupplier supplier = ResourceUtils.supplierWithMocks(true);
CrdOperator mockMirrorOps = supplier.mirrorMakerOperator;
DeploymentOperator mockDcOps = supplier.deploymentOperations;
PodDisruptionBudgetOperator mockPdbOps = supplier.podDisruptionBudgetOperator;
ConfigMapOperator mockCmOps = supplier.configMapOperations;
String kmmName = "foo";
String kmmNamespace = "test";
KafkaMirrorMakerConsumerSpec consumer = new KafkaMirrorMakerConsumerSpecBuilder().withBootstrapServers(consumerBootstrapServers).withGroupId(groupId).withNumStreams(numStreams).build();
KafkaMirrorMakerProducerSpec producer = new KafkaMirrorMakerProducerSpecBuilder().withBootstrapServers(producerBootstrapServers).build();
Map<String, Object> metricsCm = new HashMap<>();
metricsCm.put("foo", "bar");
KafkaMirrorMaker kmm = ResourceUtils.createKafkaMirrorMaker(kmmNamespace, kmmName, image, producer, consumer, include);
KafkaMirrorMakerCluster mirror = KafkaMirrorMakerCluster.fromCrd(Reconciliation.DUMMY_RECONCILIATION, kmm, VERSIONS);
// Change the image to generate some diff
kmm.getSpec().setImage("some/different:image");
when(mockMirrorOps.get(kmmNamespace, kmmName)).thenReturn(kmm);
when(mockDcOps.get(kmmNamespace, mirror.getName())).thenReturn(mirror.generateDeployment(new HashMap<String, String>(), true, null, null));
when(mockDcOps.readiness(any(), eq(kmmNamespace), eq(mirror.getName()), anyLong(), anyLong())).thenReturn(Future.succeededFuture());
when(mockDcOps.waitForObserved(any(), anyString(), anyString(), anyLong(), anyLong())).thenReturn(Future.succeededFuture());
ArgumentCaptor<String> dcNamespaceCaptor = ArgumentCaptor.forClass(String.class);
ArgumentCaptor<String> dcNameCaptor = ArgumentCaptor.forClass(String.class);
ArgumentCaptor<Deployment> dcCaptor = ArgumentCaptor.forClass(Deployment.class);
when(mockDcOps.reconcile(any(), dcNamespaceCaptor.capture(), dcNameCaptor.capture(), dcCaptor.capture())).thenReturn(Future.failedFuture("Failed"));
ArgumentCaptor<String> dcScaleUpNamespaceCaptor = ArgumentCaptor.forClass(String.class);
ArgumentCaptor<String> dcScaleUpNameCaptor = ArgumentCaptor.forClass(String.class);
ArgumentCaptor<Integer> dcScaleUpReplicasCaptor = ArgumentCaptor.forClass(Integer.class);
when(mockDcOps.scaleUp(any(), dcScaleUpNamespaceCaptor.capture(), dcScaleUpNameCaptor.capture(), dcScaleUpReplicasCaptor.capture())).thenReturn(Future.succeededFuture());
ArgumentCaptor<String> dcScaleDownNamespaceCaptor = ArgumentCaptor.forClass(String.class);
ArgumentCaptor<String> dcScaleDownNameCaptor = ArgumentCaptor.forClass(String.class);
ArgumentCaptor<Integer> dcScaleDownReplicasCaptor = ArgumentCaptor.forClass(Integer.class);
when(mockDcOps.scaleDown(any(), dcScaleDownNamespaceCaptor.capture(), dcScaleDownNameCaptor.capture(), dcScaleDownReplicasCaptor.capture())).thenReturn(Future.succeededFuture());
when(mockPdbOps.reconcile(any(), anyString(), any(), any())).thenReturn(Future.succeededFuture());
when(mockMirrorOps.reconcile(any(), anyString(), any(), any())).thenReturn(Future.succeededFuture(ReconcileResult.created(new KafkaMirrorMaker())));
when(mockMirrorOps.getAsync(anyString(), anyString())).thenReturn(Future.succeededFuture(kmm));
when(mockMirrorOps.updateStatusAsync(any(), any(KafkaMirrorMaker.class))).thenReturn(Future.succeededFuture());
when(mockCmOps.reconcile(any(), anyString(), any(), any())).thenReturn(Future.succeededFuture(ReconcileResult.created(new ConfigMap())));
KafkaMirrorMakerAssemblyOperator ops = new KafkaMirrorMakerAssemblyOperator(vertx, new PlatformFeaturesAvailability(true, kubernetesVersion), new MockCertManager(), new PasswordGenerator(10, "a", "a"), supplier, ResourceUtils.dummyClusterOperatorConfig(VERSIONS));
Checkpoint async = context.checkpoint();
ops.createOrUpdate(new Reconciliation("test-trigger", KafkaMirrorMaker.RESOURCE_KIND, kmmNamespace, kmmName), kmm).onComplete(context.failing(v -> context.verify(() -> async.flag())));
}
use of io.strimzi.operator.common.operator.resource.ConfigMapOperator in project strimzi by strimzi.
the class KafkaMirrorMakerAssemblyOperatorTest method testUpdateClusterScaleDown.
@Test
public void testUpdateClusterScaleDown(VertxTestContext context) {
int scaleTo = 2;
ResourceOperatorSupplier supplier = ResourceUtils.supplierWithMocks(true);
CrdOperator mockMirrorOps = supplier.mirrorMakerOperator;
DeploymentOperator mockDcOps = supplier.deploymentOperations;
PodDisruptionBudgetOperator mockPdbOps = supplier.podDisruptionBudgetOperator;
ConfigMapOperator mockCmOps = supplier.configMapOperations;
String kmmName = "foo";
String kmmNamespace = "test";
KafkaMirrorMakerConsumerSpec consumer = new KafkaMirrorMakerConsumerSpecBuilder().withBootstrapServers(consumerBootstrapServers).withGroupId(groupId).withNumStreams(numStreams).build();
KafkaMirrorMakerProducerSpec producer = new KafkaMirrorMakerProducerSpecBuilder().withBootstrapServers(producerBootstrapServers).build();
Map<String, Object> metricsCm = new HashMap<>();
metricsCm.put("foo", "bar");
KafkaMirrorMaker kmm = ResourceUtils.createKafkaMirrorMaker(kmmNamespace, kmmName, image, producer, consumer, include);
KafkaMirrorMakerCluster mirror = KafkaMirrorMakerCluster.fromCrd(Reconciliation.DUMMY_RECONCILIATION, kmm, VERSIONS);
// Change replicas to create ScaleDown
kmm.getSpec().setReplicas(scaleTo);
when(mockMirrorOps.get(kmmNamespace, kmmName)).thenReturn(kmm);
when(mockMirrorOps.getAsync(anyString(), anyString())).thenReturn(Future.succeededFuture(kmm));
when(mockMirrorOps.updateStatusAsync(any(), any(KafkaMirrorMaker.class))).thenReturn(Future.succeededFuture());
when(mockDcOps.get(kmmNamespace, mirror.getName())).thenReturn(mirror.generateDeployment(new HashMap<String, String>(), true, null, null));
when(mockDcOps.readiness(any(), eq(kmmNamespace), eq(mirror.getName()), anyLong(), anyLong())).thenReturn(Future.succeededFuture());
when(mockDcOps.waitForObserved(any(), anyString(), anyString(), anyLong(), anyLong())).thenReturn(Future.succeededFuture());
when(mockDcOps.reconcile(any(), eq(kmmNamespace), any(), any())).thenReturn(Future.succeededFuture());
doAnswer(i -> Future.succeededFuture(scaleTo)).when(mockDcOps).scaleUp(any(), eq(kmmNamespace), eq(mirror.getName()), eq(scaleTo));
doAnswer(i -> Future.succeededFuture(scaleTo)).when(mockDcOps).scaleDown(any(), eq(kmmNamespace), eq(mirror.getName()), eq(scaleTo));
when(mockMirrorOps.reconcile(any(), anyString(), any(), any())).thenReturn(Future.succeededFuture(ReconcileResult.created(new KafkaMirrorMaker())));
when(mockCmOps.reconcile(any(), anyString(), any(), any())).thenReturn(Future.succeededFuture(ReconcileResult.created(new ConfigMap())));
when(mockPdbOps.reconcile(any(), anyString(), any(), any())).thenReturn(Future.succeededFuture());
KafkaMirrorMakerAssemblyOperator ops = new KafkaMirrorMakerAssemblyOperator(vertx, new PlatformFeaturesAvailability(true, kubernetesVersion), new MockCertManager(), new PasswordGenerator(10, "a", "a"), supplier, ResourceUtils.dummyClusterOperatorConfig(VERSIONS));
Checkpoint async = context.checkpoint();
ops.createOrUpdate(new Reconciliation("test-trigger", KafkaMirrorMaker.RESOURCE_KIND, kmmNamespace, kmmName), kmm).onComplete(context.succeeding(v -> context.verify(() -> {
verify(mockDcOps).scaleUp(any(), eq(kmmNamespace), eq(mirror.getName()), eq(scaleTo));
async.flag();
})));
}
use of io.strimzi.operator.common.operator.resource.ConfigMapOperator in project strimzi by strimzi.
the class KafkaStatusTest method testKafkaListenerNodePortAddressInStatusWithOverrides.
@Test
public void testKafkaListenerNodePortAddressInStatusWithOverrides(VertxTestContext context) throws ParseException {
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(getKafkaCrd()).editOrNewSpec().editOrNewKafka().withListeners(new GenericKafkaListenerBuilder().withName("external").withPort(9094).withType(KafkaListenerType.NODEPORT).withTls(true).withNewConfiguration().withBrokers(broker0, broker1).endConfiguration().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.1").endStatus().build();
Pod pod1 = new PodBuilder().withNewMetadata().withName(clusterName + "-kafka-" + 1).endMetadata().withNewStatus().withHostIP("10.0.0.25").endStatus().build();
Pod pod2 = new PodBuilder().withNewMetadata().withName(clusterName + "-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 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"));
List<ListenerAddress> addresses = status.getListeners().get(0).getAddresses();
assertThat(addresses.size(), is(3));
List<ListenerAddress> expected = new ArrayList<>();
expected.add(new ListenerAddressBuilder().withHost("my-address-0").withPort(31234).build());
expected.add(new ListenerAddressBuilder().withHost("my-address-1").withPort(31234).build());
expected.add(new ListenerAddressBuilder().withHost("5.124.16.8").withPort(31234).build());
async.flag();
});
}
use of io.strimzi.operator.common.operator.resource.ConfigMapOperator in project strimzi by strimzi.
the class KafkaStatusTest method testKafkaListenerNodePortAddressInStatus.
@Test
public void testKafkaListenerNodePortAddressInStatus(VertxTestContext context) throws ParseException {
Kafka kafka = new KafkaBuilder(getKafkaCrd()).editOrNewSpec().editOrNewKafka().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.1").endStatus().build();
Pod pod1 = new PodBuilder().withNewMetadata().withName(clusterName + "-kafka-" + 1).endMetadata().withNewStatus().withHostIP("10.0.0.25").endStatus().build();
Pod pod2 = new PodBuilder().withNewMetadata().withName(clusterName + "-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 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"));
List<ListenerAddress> addresses = status.getListeners().get(0).getAddresses();
assertThat(addresses.size(), is(3));
List<ListenerAddress> expected = new ArrayList<>();
expected.add(new ListenerAddressBuilder().withHost("50.35.18.119").withPort(31234).build());
expected.add(new ListenerAddressBuilder().withHost("55.36.78.115").withPort(31234).build());
expected.add(new ListenerAddressBuilder().withHost("5.124.16.8").withPort(31234).build());
async.flag();
});
}
Aggregations