Search in sources :

Example 11 with ManagedKafka

use of org.bf2.operator.resources.v1alpha1.ManagedKafka in project kas-fleetshard by bf2fc6cc711aee1a0c2a.

the class ManagedKafkaControllerTest method shouldCreateStatus.

@Test
void shouldCreateStatus() throws InterruptedException {
    ManagedKafka mk = ManagedKafka.getDummyInstance(1);
    mk.getMetadata().setUid(UUID.randomUUID().toString());
    mk.getMetadata().setGeneration(1l);
    mk.getMetadata().setResourceVersion("1");
    // create
    Context<ManagedKafka> context = Mockito.mock(Context.class);
    Mockito.when(context.getEvents()).thenReturn(new EventList(Arrays.asList(new CustomResourceEvent(Action.ADDED, mk, null))));
    StrimziManager strimziManager = Mockito.mock(StrimziManager.class);
    Mockito.when(strimziManager.getStrimziVersion("strimzi-cluster-operator.v0.23.0")).thenReturn(new StrimziVersionStatusBuilder().withVersion(mk.getSpec().getVersions().getStrimzi()).withKafkaVersions(mk.getSpec().getVersions().getKafka()).build());
    Mockito.when(strimziManager.getVersionLabel()).thenReturn("managedkafka.bf2.org/strimziVersion");
    QuarkusMock.installMockForType(strimziManager, StrimziManager.class);
    mkController.createOrUpdateResource(mk, context);
    ManagedKafkaCondition condition = mk.getStatus().getConditions().get(0);
    assertEquals(ManagedKafkaCondition.Reason.Installing.name(), condition.getReason());
    mk.getSpec().setDeleted(true);
    // this simulates, but not exactly an issue seen with older logic
    // essentially there "last event" of the delete is something other than a deployment or a kafka
    // it should still trigger the update of the status
    Mockito.when(context.getEvents()).thenReturn(new EventList(Arrays.asList(new ResourceEvent<>(new ServiceBuilder().withNewMetadata().withOwnerReferences(new OwnerReferenceBuilder().withUid(mk.getMetadata().getUid()).build()).endMetadata().build(), null, Watcher.Action.DELETED))));
    mkController.createOrUpdateResource(mk, context);
    // should now be deleted
    condition = mk.getStatus().getConditions().get(0);
    assertEquals(ManagedKafkaCondition.Reason.Deleted.name(), condition.getReason());
}
Also used : ManagedKafka(org.bf2.operator.resources.v1alpha1.ManagedKafka) OwnerReferenceBuilder(io.fabric8.kubernetes.api.model.OwnerReferenceBuilder) StrimziVersionStatusBuilder(org.bf2.operator.resources.v1alpha1.StrimziVersionStatusBuilder) EventList(io.javaoperatorsdk.operator.processing.event.EventList) StrimziManager(org.bf2.operator.managers.StrimziManager) CustomResourceEvent(io.javaoperatorsdk.operator.processing.event.internal.CustomResourceEvent) ManagedKafkaCondition(org.bf2.operator.resources.v1alpha1.ManagedKafkaCondition) ServiceBuilder(io.fabric8.kubernetes.api.model.ServiceBuilder) QuarkusTest(io.quarkus.test.junit.QuarkusTest) Test(org.junit.jupiter.api.Test)

Example 12 with ManagedKafka

use of org.bf2.operator.resources.v1alpha1.ManagedKafka in project kas-fleetshard by bf2fc6cc711aee1a0c2a.

the class ManagedKafkaControllerTest method testWrongVersions.

@Test
void testWrongVersions() throws InterruptedException {
    ManagedKafka mk = ManagedKafka.getDummyInstance(1);
    mk.getMetadata().setUid(UUID.randomUUID().toString());
    mk.getMetadata().setGeneration(1l);
    mk.getMetadata().setResourceVersion("1");
    // create
    Context<ManagedKafka> context = Mockito.mock(Context.class);
    Mockito.when(context.getEvents()).thenReturn(new EventList(Arrays.asList(new CustomResourceEvent(Action.ADDED, mk, null))));
    StrimziManager strimziManager = Mockito.mock(StrimziManager.class);
    Mockito.when(strimziManager.getVersionLabel()).thenReturn("managedkafka.bf2.org/strimziVersion");
    QuarkusMock.installMockForType(strimziManager, StrimziManager.class);
    mkController.createOrUpdateResource(mk, context);
    ManagedKafkaCondition condition = mk.getStatus().getConditions().get(0);
    assertEquals(ManagedKafkaCondition.Reason.Error.name(), condition.getReason());
    assertEquals("The requested Strimzi version strimzi-cluster-operator.v0.23.0 is not supported", condition.getMessage());
    Mockito.when(strimziManager.getStrimziVersion("strimzi-cluster-operator.v0.23.0")).thenReturn(new StrimziVersionStatusBuilder().withVersion(mk.getSpec().getVersions().getStrimzi()).withKafkaVersions("3.0.0").build());
    mkController.createOrUpdateResource(mk, context);
    condition = mk.getStatus().getConditions().get(0);
    assertEquals(ManagedKafkaCondition.Reason.Error.name(), condition.getReason());
    assertEquals("The requested Kafka version 2.7.0 is not supported by the Strimzi version strimzi-cluster-operator.v0.23.0", condition.getMessage());
}
Also used : ManagedKafka(org.bf2.operator.resources.v1alpha1.ManagedKafka) StrimziVersionStatusBuilder(org.bf2.operator.resources.v1alpha1.StrimziVersionStatusBuilder) EventList(io.javaoperatorsdk.operator.processing.event.EventList) StrimziManager(org.bf2.operator.managers.StrimziManager) CustomResourceEvent(io.javaoperatorsdk.operator.processing.event.internal.CustomResourceEvent) ManagedKafkaCondition(org.bf2.operator.resources.v1alpha1.ManagedKafkaCondition) QuarkusTest(io.quarkus.test.junit.QuarkusTest) Test(org.junit.jupiter.api.Test)

Example 13 with ManagedKafka

use of org.bf2.operator.resources.v1alpha1.ManagedKafka in project kas-fleetshard by bf2fc6cc711aee1a0c2a.

the class ImagePullSecretManagerTest method testWithSecrets.

@Test
void testWithSecrets() {
    Deployment deployment = new DeploymentBuilder().withNewMetadata().withName(OperandUtils.FLEETSHARD_OPERATOR_NAME).endMetadata().withNewSpec().withNewTemplate().withNewSpec().withImagePullSecrets(new LocalObjectReferenceBuilder().withName("name").build(), new LocalObjectReferenceBuilder().withName("other").build()).endSpec().endTemplate().endSpec().build();
    client.apps().deployments().inNamespace(client.getNamespace()).create(deployment);
    imagePullSecretManager.initialize();
    ManagedKafka managedKafka = new ManagedKafka();
    managedKafka.setMetadata(new ObjectMetaBuilder().withName("mk").withNamespace("testWithSecrets").build());
    assertEquals(Set.of("mk-pull-name", "mk-pull-other"), imagePullSecretManager.getOperatorImagePullSecrets(managedKafka).stream().map(l -> l.getName()).collect(Collectors.toSet()));
    // no-ops - the secrets aren't yet retrieved
    imagePullSecretManager.propagateSecrets(managedKafka);
    imagePullSecretManager.deleteSecrets(managedKafka);
    imagePullSecretManager.checkSecret();
    client.secrets().inNamespace(client.getNamespace()).create(new SecretBuilder().withNewMetadata().withName("name").endMetadata().build());
    client.secrets().inNamespace(client.getNamespace()).create(new SecretBuilder().withNewMetadata().withName("other").endMetadata().build());
    // should succeed, but there's no ManagedKafkas so nothing happens
    imagePullSecretManager.checkSecret();
    assertTrue(client.secrets().inNamespace("testWithSecrets").list().getItems().isEmpty());
    imagePullSecretManager.propagateSecrets(managedKafka);
    assertEquals(Set.of("mk-pull-name", "mk-pull-other"), client.secrets().inNamespace("testWithSecrets").list().getItems().stream().map(s -> s.getMetadata().getName()).collect(Collectors.toSet()));
}
Also used : SecretBuilder(io.fabric8.kubernetes.api.model.SecretBuilder) ManagedKafka(org.bf2.operator.resources.v1alpha1.ManagedKafka) Deployment(io.fabric8.kubernetes.api.model.apps.Deployment) ObjectMetaBuilder(io.fabric8.kubernetes.api.model.ObjectMetaBuilder) LocalObjectReferenceBuilder(io.fabric8.kubernetes.api.model.LocalObjectReferenceBuilder) DeploymentBuilder(io.fabric8.kubernetes.api.model.apps.DeploymentBuilder) QuarkusTest(io.quarkus.test.junit.QuarkusTest) Test(org.junit.jupiter.api.Test)

Example 14 with ManagedKafka

use of org.bf2.operator.resources.v1alpha1.ManagedKafka in project kas-fleetshard by bf2fc6cc711aee1a0c2a.

the class ImagePullSecretManagerTest method testNoSecrets.

@Test
void testNoSecrets() {
    ManagedKafka mk = new ManagedKafka();
    assertTrue(imagePullSecretManager.getOperatorImagePullSecrets(mk).isEmpty());
    // these will just be no-ops
    imagePullSecretManager.checkSecret();
    imagePullSecretManager.propagateSecrets(mk);
    imagePullSecretManager.deleteSecrets(mk);
}
Also used : ManagedKafka(org.bf2.operator.resources.v1alpha1.ManagedKafka) QuarkusTest(io.quarkus.test.junit.QuarkusTest) Test(org.junit.jupiter.api.Test)

Example 15 with ManagedKafka

use of org.bf2.operator.resources.v1alpha1.ManagedKafka in project kas-fleetshard by bf2fc6cc711aee1a0c2a.

the class IngressControllerManagerTest method testSummarize.

@Test
public void testSummarize() {
    ManagedKafka mk = ManagedKafka.getDummyInstance(1);
    Kafka kafka = this.kafkaCluster.kafkaFrom(mk, null);
    int replicas = kafka.getSpec().getKafka().getReplicas();
    int instances = 4;
    LongSummaryStatistics egress = IngressControllerManager.summarize(Collections.nCopies(instances, kafka), KafkaCluster::getFetchQuota, () -> {
        throw new AssertionError();
    });
    long singleEgress = Quantity.getAmountInBytes(mk.getSpec().getCapacity().getEgressPerSec()).longValue() / replicas * replicas;
    assertEquals(singleEgress, egress.getMax());
    assertEquals(singleEgress * instances, egress.getSum());
}
Also used : LongSummaryStatistics(java.util.LongSummaryStatistics) AbstractKafkaCluster(org.bf2.operator.operands.AbstractKafkaCluster) KafkaCluster(org.bf2.operator.operands.KafkaCluster) ManagedKafka(org.bf2.operator.resources.v1alpha1.ManagedKafka) Kafka(io.strimzi.api.kafka.model.Kafka) ManagedKafka(org.bf2.operator.resources.v1alpha1.ManagedKafka) QuarkusTest(io.quarkus.test.junit.QuarkusTest) Test(org.junit.jupiter.api.Test)

Aggregations

ManagedKafka (org.bf2.operator.resources.v1alpha1.ManagedKafka)67 Kafka (io.strimzi.api.kafka.model.Kafka)30 Test (org.junit.jupiter.api.Test)24 QuarkusTest (io.quarkus.test.junit.QuarkusTest)23 List (java.util.List)16 Map (java.util.Map)15 Inject (javax.inject.Inject)15 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)15 Objects (java.util.Objects)14 Quantity (io.fabric8.kubernetes.api.model.Quantity)11 Optional (java.util.Optional)11 Collectors (java.util.stream.Collectors)10 ApplicationScoped (javax.enterprise.context.ApplicationScoped)9 StrimziManager (org.bf2.operator.managers.StrimziManager)9 Logger (org.jboss.logging.Logger)9 KubernetesClient (io.fabric8.kubernetes.client.KubernetesClient)8 ArrayList (java.util.ArrayList)8 Reason (org.bf2.operator.resources.v1alpha1.ManagedKafkaCondition.Reason)8 Status (org.bf2.operator.resources.v1alpha1.ManagedKafkaCondition.Status)8 ManagedKafkaUtils.exampleManagedKafka (org.bf2.operator.utils.ManagedKafkaUtils.exampleManagedKafka)8