Search in sources :

Example 6 with ManagedKafkaStatus

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());
}
Also used : ManagedKafkaList(org.bf2.operator.resources.v1alpha1.ManagedKafkaList) ManagedKafka(org.bf2.operator.resources.v1alpha1.ManagedKafka) Map(java.util.Map) ManagedKafkaStatus(org.bf2.operator.resources.v1alpha1.ManagedKafkaStatus) QuarkusTest(io.quarkus.test.junit.QuarkusTest) Test(org.junit.jupiter.api.Test)

Example 7 with ManagedKafkaStatus

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());
}
Also used : ManagedKafka(org.bf2.operator.resources.v1alpha1.ManagedKafka) ManagedKafkaStatusBuilder(org.bf2.operator.resources.v1alpha1.ManagedKafkaStatusBuilder) Map(java.util.Map) QuarkusTest(io.quarkus.test.junit.QuarkusTest) Test(org.junit.jupiter.api.Test)

Aggregations

ManagedKafka (org.bf2.operator.resources.v1alpha1.ManagedKafka)6 ManagedKafkaStatus (org.bf2.operator.resources.v1alpha1.ManagedKafkaStatus)5 ManagedKafkaStatusBuilder (org.bf2.operator.resources.v1alpha1.ManagedKafkaStatusBuilder)3 Test (org.junit.jupiter.api.Test)3 NamespaceBuilder (io.fabric8.kubernetes.api.model.NamespaceBuilder)2 QuarkusTest (io.quarkus.test.junit.QuarkusTest)2 Map (java.util.Map)2 Objects (java.util.Objects)2 ManagedKafkaAgentStatus (org.bf2.operator.resources.v1alpha1.ManagedKafkaAgentStatus)2 SequentialTest (org.bf2.systemtest.framework.SequentialTest)2 Context (io.javaoperatorsdk.operator.api.Context)1 Controller (io.javaoperatorsdk.operator.api.Controller)1 DeleteControl (io.javaoperatorsdk.operator.api.DeleteControl)1 ResourceController (io.javaoperatorsdk.operator.api.ResourceController)1 UpdateControl (io.javaoperatorsdk.operator.api.UpdateControl)1 EventSourceManager (io.javaoperatorsdk.operator.processing.event.EventSourceManager)1 Counted (io.micrometer.core.annotation.Counted)1 Timed (io.micrometer.core.annotation.Timed)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1