Search in sources :

Example 1 with Version

use of org.bf2.cos.fleetshard.api.Version in project kafka-admin-api by bf2fc6cc711aee1a0c2a.

the class DeploymentManager method deployStrimziKafka.

private KafkaContainer<?> deployStrimziKafka() {
    LOGGER.info("Deploying Strimzi Kafka container");
    class StrimziPlainKafkaContainer extends StrimziKafkaContainer implements KafkaContainer<StrimziKafkaContainer> {

        StrimziPlainKafkaContainer(String version) {
            super(version);
        }
    }
    String imageTag = System.getProperty("strimzi-kafka.tag");
    var container = new StrimziPlainKafkaContainer(imageTag).withLabels(Collections.singletonMap("test-ident", Environment.TEST_CONTAINER_LABEL)).withLogConsumer(new Slf4jLogConsumer(LoggerFactory.getLogger("systemtests.plain-kafka"), true)).withCreateContainerCmdModifier(cmd -> cmd.withName(name("plain-kafka"))).withNetwork(testNetwork);
    container.start();
    return (KafkaContainer<?>) container;
}
Also used : BindMode(org.testcontainers.containers.BindMode) CONFIG(org.bf2.admin.kafka.systemtest.Environment.CONFIG) Logger(org.jboss.logging.Logger) LoggerFactory(org.slf4j.LoggerFactory) HashMap(java.util.HashMap) Network(org.testcontainers.containers.Network) StrimziKafkaContainer(io.strimzi.StrimziKafkaContainer) ArrayList(java.util.ArrayList) Slf4jLogConsumer(org.testcontainers.containers.output.Slf4jLogConsumer) Duration(java.time.Duration) Map(java.util.Map) GenericContainer(org.testcontainers.containers.GenericContainer) Startable(org.testcontainers.lifecycle.Startable) Wait(org.testcontainers.containers.wait.strategy.Wait) Properties(java.util.Properties) KafkaAdminConfigRetriever(org.bf2.admin.kafka.admin.KafkaAdminConfigRetriever) Environment(org.bf2.admin.kafka.systemtest.Environment) IOException(java.io.IOException) UUID(java.util.UUID) InputStreamReader(java.io.InputStreamReader) Collectors(java.util.stream.Collectors) StandardCharsets(java.nio.charset.StandardCharsets) UncheckedIOException(java.io.UncheckedIOException) Base64(java.util.Base64) List(java.util.List) MountableFile(org.testcontainers.utility.MountableFile) BufferedReader(java.io.BufferedReader) Collections(java.util.Collections) InputStream(java.io.InputStream) StrimziKafkaContainer(io.strimzi.StrimziKafkaContainer) Slf4jLogConsumer(org.testcontainers.containers.output.Slf4jLogConsumer) StrimziKafkaContainer(io.strimzi.StrimziKafkaContainer)

Example 2 with Version

use of org.bf2.cos.fleetshard.api.Version 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 3 with Version

use of org.bf2.cos.fleetshard.api.Version in project kas-fleetshard by bf2fc6cc711aee1a0c2a.

the class StrimziManager method setStrimziPendingInstallationVersions.

/**
 * Notify the strimzi manager of pending versions.
 * @param pendingVersions
 * @return true if the pending state has changed
 */
public boolean setStrimziPendingInstallationVersions(List<String> pendingVersions) {
    if (!Collections.disjoint(strimziPendingInstallationVersions.keySet(), pendingVersions)) {
        return false;
    }
    log.infof("Notified of pending strimzi versions %s", pendingVersions);
    ConcurrentHashMap<String, StrimziVersionStatus> next = new ConcurrentHashMap<>();
    for (String version : pendingVersions) {
        StrimziVersionStatus existing = strimziVersions.get(version);
        if (existing != null) {
            next.put(version, new StrimziVersionStatusBuilder(existing).withReady(false).build());
        } else {
            next.put(version, EMPTY_STATUS);
        }
    }
    this.strimziPendingInstallationVersions = next;
    informerManager.resyncManagedKafkaAgent();
    return true;
}
Also used : StrimziVersionStatus(org.bf2.operator.resources.v1alpha1.StrimziVersionStatus) StrimziVersionStatusBuilder(org.bf2.operator.resources.v1alpha1.StrimziVersionStatusBuilder) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap)

Example 4 with Version

use of org.bf2.cos.fleetshard.api.Version in project kas-fleetshard by bf2fc6cc711aee1a0c2a.

the class StrimziManager method currentStrimziVersion.

/**
 * Returns the current Strimzi version for the Kafka instance
 * It comes directly from the Kafka custom resource label or from the ManagedKafka in case of creation
 *
 * @param managedKafka ManagedKafka instance
 * @return current Strimzi version for the Kafka instance
 */
public String currentStrimziVersion(ManagedKafka managedKafka) {
    Kafka kafka = cachedKafka(managedKafka);
    // on first time Kafka resource creation, we take the Strimzi version from the ManagedKafka resource spec
    String kafkaStrimziVersion = kafka != null && kafka.getMetadata().getLabels() != null && kafka.getMetadata().getLabels().containsKey(this.versionLabel) ? kafka.getMetadata().getLabels().get(this.versionLabel) : managedKafka.getSpec().getVersions().getStrimzi();
    log.debugf("currentStrimziVersion = %s", kafkaStrimziVersion);
    return kafkaStrimziVersion;
}
Also used : Kafka(io.strimzi.api.kafka.model.Kafka) ManagedKafka(org.bf2.operator.resources.v1alpha1.ManagedKafka)

Example 5 with Version

use of org.bf2.cos.fleetshard.api.Version in project kas-fleetshard by bf2fc6cc711aee1a0c2a.

the class StrimziManager method updateStatus.

private void updateStatus() {
    List<StrimziVersionStatus> versions = new ArrayList<>(this.strimziVersions.values());
    // create the Kafka informer only when a Strimzi bundle is installed (aka at least one available version)
    if (!versions.isEmpty()) {
        informerManager.createKafkaInformer();
    }
    ManagedKafkaAgent resource = agentClient.getByName(agentClient.getNamespace(), ManagedKafkaAgentResourceClient.RESOURCE_NAME);
    if (resource != null && resource.getStatus() != null) {
        List<StrimziVersionStatus> existing = resource.getStatus().getStrimzi();
        if (!versions.equals(existing)) {
            log.debugf("Updating Strimzi versions %s", versions);
            resource.getStatus().setStrimzi(versions);
            agentClient.replaceStatus(resource);
            // version changes should sync the managed kafkas
            if (existing == null || !toVersionKeySet(versions).equals(toVersionKeySet(existing))) {
                informerManager.resyncManagedKafka();
            }
        }
    }
}
Also used : StrimziVersionStatus(org.bf2.operator.resources.v1alpha1.StrimziVersionStatus) ArrayList(java.util.ArrayList) ManagedKafkaAgent(org.bf2.operator.resources.v1alpha1.ManagedKafkaAgent)

Aggregations

ManagedKafka (org.bf2.operator.resources.v1alpha1.ManagedKafka)10 Test (org.junit.jupiter.api.Test)6 Kafka (io.strimzi.api.kafka.model.Kafka)5 ManagedConnector (org.bf2.cos.fleetshard.api.ManagedConnector)5 NamespaceBuilder (io.fabric8.kubernetes.api.model.NamespaceBuilder)4 QuarkusTest (io.quarkus.test.junit.QuarkusTest)4 ArrayList (java.util.ArrayList)4 Collections (java.util.Collections)4 List (java.util.List)4 Map (java.util.Map)4 Objects (java.util.Objects)4 Collectors (java.util.stream.Collectors)4 LoggerFactory (org.slf4j.LoggerFactory)4 Namespace (io.fabric8.kubernetes.api.model.Namespace)3 ObjectMetaBuilder (io.fabric8.kubernetes.api.model.ObjectMetaBuilder)3 OperatorSelector (org.bf2.cos.fleetshard.api.OperatorSelector)3 StrimziVersionStatus (org.bf2.operator.resources.v1alpha1.StrimziVersionStatus)3 ArrayNode (com.fasterxml.jackson.databind.node.ArrayNode)2 Container (io.fabric8.kubernetes.api.model.Container)2 EnvVar (io.fabric8.kubernetes.api.model.EnvVar)2