Search in sources :

Example 1 with InformerManager

use of org.bf2.operator.managers.InformerManager in project kas-fleetshard by bf2fc6cc711aee1a0c2a.

the class KafkaClusterTest method storageCalculation.

@Test
void storageCalculation() throws InterruptedException {
    ManagedKafka mk = ManagedKafka.getDummyInstance(1);
    mk.getMetadata().setUid(UUID.randomUUID().toString());
    mk.getMetadata().setGeneration(1l);
    mk.getMetadata().setResourceVersion("1");
    InformerManager informerManager = Mockito.mock(InformerManager.class);
    QuarkusMock.installMockForType(informerManager, InformerManager.class);
    Mockito.when(informerManager.getPvcsInNamespace(Mockito.anyString())).thenReturn(List.of());
    // there's no pvcs, should be 0
    assertEquals("0", kafkaCluster.calculateRetentionSize(mk).getAmount());
    PersistentVolumeClaim pvc = new PersistentVolumeClaimBuilder().withNewStatus().addToCapacity("storage", Quantity.parse("344Gi")).endStatus().build();
    Mockito.when(informerManager.getPvcsInNamespace(Mockito.anyString())).thenReturn(List.of(pvc, pvc, pvc));
    // should be the sum in Gi, less the padding
    assertEquals("1000", kafkaCluster.calculateRetentionSize(mk).getAmount());
}
Also used : ManagedKafkaUtils.exampleManagedKafka(org.bf2.operator.utils.ManagedKafkaUtils.exampleManagedKafka) ManagedKafka(org.bf2.operator.resources.v1alpha1.ManagedKafka) PersistentVolumeClaimBuilder(io.fabric8.kubernetes.api.model.PersistentVolumeClaimBuilder) InformerManager(org.bf2.operator.managers.InformerManager) PersistentVolumeClaim(io.fabric8.kubernetes.api.model.PersistentVolumeClaim) QuarkusTest(io.quarkus.test.junit.QuarkusTest) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 2 with InformerManager

use of org.bf2.operator.managers.InformerManager in project kas-fleetshard by bf2fc6cc711aee1a0c2a.

the class KafkaClusterTest method pausedUnknownStatus.

@Test
void pausedUnknownStatus() throws InterruptedException {
    ManagedKafka mk = ManagedKafka.getDummyInstance(1);
    InformerManager informer = Mockito.mock(InformerManager.class);
    Kafka kafka = new KafkaBuilder(this.kafkaCluster.kafkaFrom(mk, null)).editMetadata().withAnnotations(Map.of(StrimziManager.STRIMZI_PAUSE_REASON_ANNOTATION, "custom")).endMetadata().withNewStatus().withConditions(new ConditionBuilder().withType("ReconciliationPaused").withStatus("True").build()).endStatus().build();
    Mockito.when(informer.getLocalKafka(Mockito.anyString(), Mockito.anyString())).thenReturn(kafka);
    QuarkusMock.installMockForType(informer, InformerManager.class);
    OperandReadiness readiness = this.kafkaCluster.getReadiness(mk);
    assertEquals(Status.Unknown, readiness.getStatus());
    assertEquals(Reason.Paused, readiness.getReason());
    assertEquals("Kafka mk-1 is paused for an unknown reason", readiness.getMessage());
}
Also used : ConditionBuilder(io.strimzi.api.kafka.model.status.ConditionBuilder) ManagedKafkaUtils.exampleManagedKafka(org.bf2.operator.utils.ManagedKafkaUtils.exampleManagedKafka) ManagedKafka(org.bf2.operator.resources.v1alpha1.ManagedKafka) ManagedKafkaUtils.exampleManagedKafka(org.bf2.operator.utils.ManagedKafkaUtils.exampleManagedKafka) Kafka(io.strimzi.api.kafka.model.Kafka) ManagedKafka(org.bf2.operator.resources.v1alpha1.ManagedKafka) InformerManager(org.bf2.operator.managers.InformerManager) KafkaBuilder(io.strimzi.api.kafka.model.KafkaBuilder) QuarkusTest(io.quarkus.test.junit.QuarkusTest) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 3 with InformerManager

use of org.bf2.operator.managers.InformerManager in project kas-fleetshard by bf2fc6cc711aee1a0c2a.

the class ObservabilityManagerTest method testObservabilitySecret.

@Test
public void testObservabilitySecret() {
    client.getConfiguration().setNamespace("test");
    ObservabilityConfiguration config = new ObservabilityConfigurationBuilder().withAccessToken("test-token").withChannel("test").withRepository("test-repo").withTag("tag").build();
    String ownerName = "SampleOwner";
    Secret owner = client.secrets().inNamespace(client.getNamespace()).withName(ownerName).create(new SecretBuilder().withNewMetadata().withNamespace(client.getNamespace()).withName(ownerName).endMetadata().addToData("key", "value").build());
    this.observabilityManager.createOrUpdateObservabilitySecret(config, owner);
    // lets call event handler
    Secret secret = observabilityManager.observabilitySecretResource().get();
    assertNotNull(secret);
    // the mock informermanager should be immediately updated, but it should
    // not be seen as running
    assertNotNull(observabilityManager.cachedObservabilitySecret());
    assertFalse(observabilityManager.isObservabilityRunning());
    assertFalse(secret.getMetadata().getOwnerReferences().isEmpty());
    ObservabilityConfiguration secretConfig = new ObservabilityConfigurationBuilder().withAccessToken(new String(decoder.decode(secret.getData().get(ObservabilityManager.OBSERVABILITY_ACCESS_TOKEN)))).withChannel(new String(decoder.decode(secret.getData().get(ObservabilityManager.OBSERVABILITY_CHANNEL)))).withTag(new String(decoder.decode(secret.getData().get(ObservabilityManager.OBSERVABILITY_TAG)))).withRepository(new String(decoder.decode(secret.getData().get(ObservabilityManager.OBSERVABILITY_REPOSITORY)))).build();
    // secret verification
    assertEquals(secretConfig, config);
    assertEquals("observability-operator", secret.getMetadata().getLabels().get("configures"));
    // status verification, the Informers do not work in test framework thus direct verification
    secret = ObservabilityManager.createObservabilitySecretBuilder(client.getNamespace(), config).editMetadata().addToAnnotations(ObservabilityManager.OBSERVABILITY_OPERATOR_STATUS, ObservabilityManager.ACCEPTED).endMetadata().build();
    observabilityManager.observabilitySecretResource().createOrReplace(secret);
    secret = observabilityManager.observabilitySecretResource().get();
    assertTrue(ObservabilityManager.isObservabilityStatusAccepted(secret));
    this.observabilityManager.createOrUpdateObservabilitySecret(config, owner);
    // no-op update and make sure the flag is not flipped
    secret = observabilityManager.observabilitySecretResource().get();
    assertTrue(ObservabilityManager.isObservabilityStatusAccepted(secret));
}
Also used : Secret(io.fabric8.kubernetes.api.model.Secret) SecretBuilder(io.fabric8.kubernetes.api.model.SecretBuilder) ObservabilityConfiguration(org.bf2.operator.resources.v1alpha1.ObservabilityConfiguration) ObservabilityConfigurationBuilder(org.bf2.operator.resources.v1alpha1.ObservabilityConfigurationBuilder) QuarkusTest(io.quarkus.test.junit.QuarkusTest) Test(org.junit.jupiter.api.Test)

Aggregations

QuarkusTest (io.quarkus.test.junit.QuarkusTest)3 Test (org.junit.jupiter.api.Test)3 InformerManager (org.bf2.operator.managers.InformerManager)2 ManagedKafka (org.bf2.operator.resources.v1alpha1.ManagedKafka)2 ManagedKafkaUtils.exampleManagedKafka (org.bf2.operator.utils.ManagedKafkaUtils.exampleManagedKafka)2 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)2 PersistentVolumeClaim (io.fabric8.kubernetes.api.model.PersistentVolumeClaim)1 PersistentVolumeClaimBuilder (io.fabric8.kubernetes.api.model.PersistentVolumeClaimBuilder)1 Secret (io.fabric8.kubernetes.api.model.Secret)1 SecretBuilder (io.fabric8.kubernetes.api.model.SecretBuilder)1 Kafka (io.strimzi.api.kafka.model.Kafka)1 KafkaBuilder (io.strimzi.api.kafka.model.KafkaBuilder)1 ConditionBuilder (io.strimzi.api.kafka.model.status.ConditionBuilder)1 ObservabilityConfiguration (org.bf2.operator.resources.v1alpha1.ObservabilityConfiguration)1 ObservabilityConfigurationBuilder (org.bf2.operator.resources.v1alpha1.ObservabilityConfigurationBuilder)1