use of org.bf2.operator.resources.v1alpha1.ManagedKafkaStatus in project kas-fleetshard by bf2fc6cc711aee1a0c2a.
the class PollerTest method testAddDelete.
@Test
public void testAddDelete() {
ManagedKafka managedKafka = exampleManagedKafka();
List<ManagedKafka> items = lookup.getLocalManagedKafkas();
assertEquals(0, items.size());
assertNull(controlPlane.getDesiredState(ControlPlane.managedKafkaKey(managedKafka)));
Mockito.when(controlPlaneRestClient.getKafkaClusters(CLUSTER_ID)).thenReturn(new ManagedKafkaList(Collections.singletonList(managedKafka)));
managedKafkaSync.syncKafkaClusters();
items = lookup.getLocalManagedKafkas();
assertEquals(1, items.size());
assertFalse(items.get(0).getSpec().isDeleted());
// should do nothing
managedKafkaSync.syncKafkaClusters();
items = lookup.getLocalManagedKafkas();
assertEquals(1, items.size());
// make sure the remote tracking is there and not marked as deleted
assertFalse(controlPlane.getDesiredState(ControlPlane.managedKafkaKey(managedKafka)).getSpec().isDeleted());
// try another placement - this shouldn't actually happen, should reject first and the original won't be there
ManagedKafka nextPlacement = exampleManagedKafka();
nextPlacement.setPlacementId("xyz");
nextPlacement.getSpec().getVersions().setStrimzi("?");
Mockito.when(controlPlaneRestClient.getKafkaClusters(CLUSTER_ID)).thenReturn(new ManagedKafkaList(Arrays.asList(managedKafka, nextPlacement)));
managedKafkaSync.syncKafkaClusters();
// should still be a single placement, and it should be the old one
items = lookup.getLocalManagedKafkas();
assertEquals(1, items.size());
assertNotEquals("?", items.get(0).getSpec().getVersions().getStrimzi());
// try to remove before marked as deleted, should not be successful
Mockito.when(controlPlaneRestClient.getKafkaClusters(CLUSTER_ID)).thenReturn(new ManagedKafkaList());
managedKafkaSync.syncKafkaClusters();
items = lookup.getLocalManagedKafkas();
assertEquals(1, items.size());
Mockito.when(controlPlaneRestClient.getKafkaClusters(CLUSTER_ID)).thenReturn(new ManagedKafkaList(Arrays.asList(managedKafka, nextPlacement)));
managedKafka.getSpec().setDeleted(true);
managedKafkaSync.syncKafkaClusters();
items = lookup.getLocalManagedKafkas();
assertTrue(items.get(0).getSpec().isDeleted());
// now the remote tracking should be marked as deleted
assertTrue(controlPlane.getDesiredState(ControlPlane.managedKafkaKey(managedKafka)).getSpec().isDeleted());
// final removal
Mockito.when(controlPlaneRestClient.getKafkaClusters(CLUSTER_ID)).thenReturn(new ManagedKafkaList());
managedKafkaSync.syncKafkaClusters();
items = lookup.getLocalManagedKafkas();
assertEquals(0, items.size());
// remote tracking should be gone
assertNull(controlPlane.getDesiredState(ControlPlane.managedKafkaKey(managedKafka)));
// if it shows up again need to inform the control plane delete is still needed
Mockito.when(controlPlaneRestClient.getKafkaClusters(CLUSTER_ID)).thenReturn(new ManagedKafkaList(Collections.singletonList(managedKafka)));
managedKafkaSync.syncKafkaClusters();
// expect there to be a status about the deletion
ArgumentCaptor<Map<String, ManagedKafkaStatus>> statusCaptor = ArgumentCaptor.forClass(Map.class);
Mockito.verify(controlPlaneRestClient).updateKafkaClustersStatus(Mockito.eq(CLUSTER_ID), statusCaptor.capture());
Map<String, ManagedKafkaStatus> status = statusCaptor.getValue();
assertEquals(1, status.size());
assertEquals(1, status.get(ID).getConditions().size());
}
use of org.bf2.operator.resources.v1alpha1.ManagedKafkaStatus in project kas-fleetshard by bf2fc6cc711aee1a0c2a.
the class UpdateTest method testControlPlaneUpdates.
@Test
public void testControlPlaneUpdates() {
ManagedKafka managedKafka = PollerTest.exampleManagedKafka();
managedKafka.getMetadata().setNamespace(managedKafka.getId());
managedKafka.setStatus(new ManagedKafkaStatusBuilder().addNewCondition().withStatus("Installed").endCondition().build());
managedKafkaClient.create(managedKafka);
controlPlane.updateKafkaClusterStatus(PollerTest.exampleManagedKafka(), managedKafka);
assertEquals("Installed", getUpdates().getValue().get(PollerTest.ID).getConditions().get(0).getStatus());
// simulate a resync
// for now we're just looking for equality
Mockito.clearInvocations(controlPlaneRestClient);
controlPlane.updateKafkaClusterStatus(managedKafka, managedKafka);
// should not be sent
Mockito.verifyNoInteractions(controlPlaneRestClient);
// send everything
controlPlane.sendResync();
ArgumentCaptor<Map<String, ManagedKafkaStatus>> statusCaptor = getUpdates();
assertEquals("Installed", statusCaptor.getValue().get(PollerTest.ID).getConditions().get(0).getStatus());
}
Aggregations