Search in sources :

Example 61 with ManagedKafka

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

the class ManagedKafkaResourceType method isDeleted.

public static void isDeleted(ManagedKafka mk) {
    TestUtils.waitFor("Managed kafka is removed", 1_000, 600_000, () -> {
        ManagedKafka m = ManagedKafkaResourceType.getOperation().inNamespace(mk.getMetadata().getNamespace()).withName(mk.getMetadata().getName()).get();
        List<Pod> pods = KubeClient.getInstance().client().pods().inNamespace(mk.getMetadata().getNamespace()).list().getItems();
        return m == null && pods.size() == 0;
    });
}
Also used : ManagedKafka(org.bf2.operator.resources.v1alpha1.ManagedKafka) Pod(io.fabric8.kubernetes.api.model.Pod)

Example 62 with ManagedKafka

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

the class StrimziManagerTest method testStrimziVersionChange.

@Test
public void testStrimziVersionChange() {
    ManagedKafka mk = ManagedKafka.getDummyInstance(1);
    mk.getSpec().getVersions().setStrimzi("strimzi-cluster-operator.v1");
    Kafka kafka = this.kafkaCluster.kafkaFrom(mk, null);
    kafkaClient.create(kafka);
    // Kafka reconcile not paused and current label version as the ManagedKafka one
    assertFalse(kafka.getMetadata().getAnnotations().containsKey(StrimziManager.STRIMZI_PAUSE_RECONCILE_ANNOTATION));
    assertEquals(kafka.getMetadata().getLabels().get(this.strimziManager.getVersionLabel()), mk.getSpec().getVersions().getStrimzi());
    // ManagedKafka and Kafka updated their status information
    mk.setStatus(new ManagedKafkaStatusBuilder().withVersions(new VersionsBuilder().withStrimzi("strimzi-cluster-operator.v1").build()).build());
    kafka.setStatus(new KafkaStatusBuilder().withConditions(new ConditionBuilder().withType("Ready").withStatus("True").build()).build());
    kafkaClient.replaceStatus(kafka);
    // ask for a Strimzi version change on ManagedKafka
    mk.getSpec().getVersions().setStrimzi("strimzi-cluster-operator.v2");
    kafka = this.kafkaCluster.kafkaFrom(mk, kafka);
    // Kafka reconcile paused but label is still the current version
    assertTrue(kafka.getMetadata().getAnnotations().containsKey(StrimziManager.STRIMZI_PAUSE_RECONCILE_ANNOTATION));
    assertTrue(kafka.getMetadata().getAnnotations().containsKey(StrimziManager.STRIMZI_PAUSE_REASON_ANNOTATION));
    assertEquals(kafka.getMetadata().getLabels().get(this.strimziManager.getVersionLabel()), mk.getStatus().getVersions().getStrimzi());
    // nothing should change after an intermediate reconcile
    kafka = this.kafkaCluster.kafkaFrom(mk, kafka);
    assertTrue(kafka.getMetadata().getAnnotations().containsKey(StrimziManager.STRIMZI_PAUSE_REASON_ANNOTATION));
    // Kafka moves to be paused
    kafka.setStatus(new KafkaStatusBuilder().withConditions(new ConditionBuilder().withType("ReconciliationPaused").withStatus("True").build()).build());
    kafkaClient.replaceStatus(kafka);
    kafka = this.kafkaCluster.kafkaFrom(mk, kafka);
    // Kafka reconcile not paused and Kafka label updated to requested Strimzi version
    assertFalse(kafka.getMetadata().getAnnotations().containsKey(StrimziManager.STRIMZI_PAUSE_RECONCILE_ANNOTATION));
    // the pause reason should stay until strimzi updates to ready
    assertTrue(kafka.getMetadata().getAnnotations().containsKey(StrimziManager.STRIMZI_PAUSE_REASON_ANNOTATION));
    assertEquals(kafka.getMetadata().getLabels().get(this.strimziManager.getVersionLabel()), "strimzi-cluster-operator.v2");
}
Also used : ConditionBuilder(io.strimzi.api.kafka.model.status.ConditionBuilder) ManagedKafka(org.bf2.operator.resources.v1alpha1.ManagedKafka) ManagedKafkaStatusBuilder(org.bf2.operator.resources.v1alpha1.ManagedKafkaStatusBuilder) Kafka(io.strimzi.api.kafka.model.Kafka) ManagedKafka(org.bf2.operator.resources.v1alpha1.ManagedKafka) ManagedKafkaStatusBuilder(org.bf2.operator.resources.v1alpha1.ManagedKafkaStatusBuilder) KafkaStatusBuilder(io.strimzi.api.kafka.model.status.KafkaStatusBuilder) VersionsBuilder(org.bf2.operator.resources.v1alpha1.VersionsBuilder) QuarkusTest(io.quarkus.test.junit.QuarkusTest) Test(org.junit.jupiter.api.Test)

Example 63 with ManagedKafka

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

the class AdminServerTest method createAdminServerDeployment.

@ParameterizedTest
@CsvSource({ "test-mk-q,     1, true,  false, /expected/adminserver-quarkus.yml", "test-mk-tls-q, 2, true,  true,  /expected/adminserver-tls-quarkus.yml", "test-mk,       3, false, false, /expected/adminserver.yml", "test-mk-tls,   4, false, true,  /expected/adminserver-tls.yml" })
void createAdminServerDeployment(String name, String versionString, boolean quarkusBased, boolean tls, String expectedResource) throws Exception {
    ManagedKafka mk = buildBasicManagedKafka(name, versionString, tls ? new TlsKeyPair() : null);
    OperandOverride override = new OperandOverride();
    override.setImage("quay.io/mk-ci-cd/kafka-admin-api:0.7.0");
    override.setAdditionalProperty("quarkus-based", quarkusBased);
    OperandOverrideManager overrideManager = Mockito.mock(OperandOverrideManager.class);
    Mockito.when(overrideManager.getAdminServerOverride(versionString)).thenReturn(override);
    Mockito.when(overrideManager.getAdminServerImage(versionString)).thenReturn(override.image);
    QuarkusMock.installMockForType(overrideManager, OperandOverrideManager.class);
    Deployment adminServerDeployment = adminServer.deploymentFrom(mk, null);
    server.getClient().apps().deployments().create(adminServerDeployment);
    assertNotNull(server.getClient().apps().deployments().inNamespace(adminServerDeployment.getMetadata().getNamespace()).withName(adminServerDeployment.getMetadata().getName()).get());
    KafkaClusterTest.diffToExpected(adminServerDeployment, expectedResource);
}
Also used : ManagedKafka(org.bf2.operator.resources.v1alpha1.ManagedKafka) TlsKeyPair(org.bf2.operator.resources.v1alpha1.TlsKeyPair) OperandOverrideManager(org.bf2.operator.managers.OperandOverrideManager) Deployment(io.fabric8.kubernetes.api.model.apps.Deployment) OperandOverride(org.bf2.operator.managers.OperandOverrideManager.OperandOverride) CsvSource(org.junit.jupiter.params.provider.CsvSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 64 with ManagedKafka

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

the class KafkaClusterTest method testExistingStorageClassOverridesDontGetUpdated.

@Test
void testExistingStorageClassOverridesDontGetUpdated() {
    ManagedKafka mk = exampleManagedKafka("60Gi");
    Kafka defaultKafka = kafkaCluster.kafkaFrom(mk, null);
    JbodStorage defaultKafkaStorage = (JbodStorage) defaultKafka.getSpec().getKafka().getStorage();
    PersistentClaimStorage defaultZookeeperStorage = (PersistentClaimStorage) defaultKafka.getSpec().getZookeeper().getStorage();
    JbodStorage kafkaStorageWithOverrides = new JbodStorageBuilder(defaultKafkaStorage).withVolumes(defaultKafkaStorage.getVolumes().stream().map(v -> {
        PersistentClaimStorage pcs = (PersistentClaimStorage) v;
        pcs.setStorageClass(null);
        pcs.setOverrides(buildStorageOverrides());
        return pcs;
    }).collect(Collectors.toList())).build();
    PersistentClaimStorage zookeeperStorageWithOverrides = new PersistentClaimStorageBuilder(defaultZookeeperStorage).withStorageClass(null).withOverrides(buildStorageOverrides()).build();
    Kafka kafkaWithOverrides = new KafkaBuilder(defaultKafka).editSpec().editKafka().withStorage(kafkaStorageWithOverrides).endKafka().editZookeeper().withStorage(zookeeperStorageWithOverrides).endZookeeper().endSpec().build();
    Kafka reconciledKafka = kafkaCluster.kafkaFrom(mk, kafkaWithOverrides);
    assertNull(((PersistentClaimStorage) reconciledKafka.getSpec().getZookeeper().getStorage()).getStorageClass());
    assertEquals(buildStorageOverrides(), ((PersistentClaimStorage) reconciledKafka.getSpec().getZookeeper().getStorage()).getOverrides());
    ((JbodStorage) reconciledKafka.getSpec().getKafka().getStorage()).getVolumes().stream().forEach(v -> {
        assertNull(((PersistentClaimStorage) v).getStorageClass());
        assertEquals(buildStorageOverrides(), ((PersistentClaimStorage) v).getOverrides());
    });
}
Also used : Quantity(io.fabric8.kubernetes.api.model.Quantity) PersistentClaimStorageOverrideBuilder(io.strimzi.api.kafka.model.storage.PersistentClaimStorageOverrideBuilder) BeforeEach(org.junit.jupiter.api.BeforeEach) CsvSource(org.junit.jupiter.params.provider.CsvSource) KubernetesServerTestResource(io.quarkus.test.kubernetes.client.KubernetesServerTestResource) QuarkusMock(io.quarkus.test.junit.QuarkusMock) Status(org.bf2.operator.resources.v1alpha1.ManagedKafkaCondition.Status) Assertions.assertNull(org.junit.jupiter.api.Assertions.assertNull) StrimziManager(org.bf2.operator.managers.StrimziManager) JsonDiff(io.fabric8.zjsonpatch.JsonDiff) KafkaBuilder(io.strimzi.api.kafka.model.KafkaBuilder) QuarkusTest(io.quarkus.test.junit.QuarkusTest) ArrayList(java.util.ArrayList) Inject(javax.inject.Inject) PersistentClaimStorage(io.strimzi.api.kafka.model.storage.PersistentClaimStorage) PersistentClaimStorageBuilder(io.strimzi.api.kafka.model.storage.PersistentClaimStorageBuilder) Serialization(io.fabric8.kubernetes.client.utils.Serialization) Map(java.util.Map) JsonNode(com.fasterxml.jackson.databind.JsonNode) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) QuarkusTestResource(io.quarkus.test.common.QuarkusTestResource) JbodStorage(io.strimzi.api.kafka.model.storage.JbodStorage) KubernetesServer(io.fabric8.kubernetes.client.server.mock.KubernetesServer) JbodStorageBuilder(io.strimzi.api.kafka.model.storage.JbodStorageBuilder) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) InformerManager(org.bf2.operator.managers.InformerManager) IngressControllerManager(org.bf2.operator.managers.IngressControllerManager) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) DrainCleanerManager(org.bf2.operator.managers.DrainCleanerManager) IOException(java.io.IOException) Reason(org.bf2.operator.resources.v1alpha1.ManagedKafkaCondition.Reason) UUID(java.util.UUID) Collectors(java.util.stream.Collectors) ManagedKafkaUtils.exampleManagedKafka(org.bf2.operator.utils.ManagedKafkaUtils.exampleManagedKafka) Test(org.junit.jupiter.api.Test) Mockito(org.mockito.Mockito) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) List(java.util.List) ConditionBuilder(io.strimzi.api.kafka.model.status.ConditionBuilder) KubernetesClient(io.fabric8.kubernetes.client.KubernetesClient) KubernetesTestServer(io.quarkus.test.kubernetes.client.KubernetesTestServer) PersistentVolumeClaim(io.fabric8.kubernetes.api.model.PersistentVolumeClaim) JsonMappingException(com.fasterxml.jackson.databind.JsonMappingException) Kafka(io.strimzi.api.kafka.model.Kafka) PersistentClaimStorageOverride(io.strimzi.api.kafka.model.storage.PersistentClaimStorageOverride) PersistentVolumeClaimBuilder(io.fabric8.kubernetes.api.model.PersistentVolumeClaimBuilder) ManagedKafka(org.bf2.operator.resources.v1alpha1.ManagedKafka) JbodStorageBuilder(io.strimzi.api.kafka.model.storage.JbodStorageBuilder) ManagedKafkaUtils.exampleManagedKafka(org.bf2.operator.utils.ManagedKafkaUtils.exampleManagedKafka) ManagedKafka(org.bf2.operator.resources.v1alpha1.ManagedKafka) PersistentClaimStorage(io.strimzi.api.kafka.model.storage.PersistentClaimStorage) ManagedKafkaUtils.exampleManagedKafka(org.bf2.operator.utils.ManagedKafkaUtils.exampleManagedKafka) Kafka(io.strimzi.api.kafka.model.Kafka) ManagedKafka(org.bf2.operator.resources.v1alpha1.ManagedKafka) PersistentClaimStorageBuilder(io.strimzi.api.kafka.model.storage.PersistentClaimStorageBuilder) KafkaBuilder(io.strimzi.api.kafka.model.KafkaBuilder) JbodStorage(io.strimzi.api.kafka.model.storage.JbodStorage) QuarkusTest(io.quarkus.test.junit.QuarkusTest) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 65 with ManagedKafka

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

the class KafkaClusterTest method testManagedKafkaMaximumSessionLifetimeMapping.

@ParameterizedTest
@CsvSource({ // Default to 4m 59s
",       299000", // No less than zero
"-1,          0", "0,           0", "1,           1", "299000, 299000" })
void testManagedKafkaMaximumSessionLifetimeMapping(Long maximumSessionLifetime, long maxReauthMs) throws IOException {
    ManagedKafka mk = exampleManagedKafka("60Gi");
    mk.getSpec().getOauth().setMaximumSessionLifetime(maximumSessionLifetime);
    Kafka kafka = kafkaCluster.kafkaFrom(mk, null);
    assertEquals(maxReauthMs, kafka.getSpec().getKafka().getConfig().get("connections.max.reauth.ms"));
}
Also used : 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) CsvSource(org.junit.jupiter.params.provider.CsvSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

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