Search in sources :

Example 1 with KafkaCluster

use of org.bf2.operator.operands.KafkaCluster 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)

Example 2 with KafkaCluster

use of org.bf2.operator.operands.KafkaCluster in project kas-fleetshard by bf2fc6cc711aee1a0c2a.

the class InstanceProfiler method setup.

private void setup() throws Exception {
    readResults();
    if (profilingResult.name == null) {
        profilingResult.name = "profile-" + Environment.DATE_FORMAT.format(LocalDateTime.now());
    }
    logDir = new File("target", profilingResult.name);
    Files.createDirectories(logDir.toPath());
    kafkaCluster = KubeClusterResource.connectToKubeCluster(PerformanceEnvironment.KAFKA_KUBECONFIG);
    profilingResult.kafkaNodeType = kafkaCluster.getWorkerNodes().get(0).getMetadata().getLabels().get("node.kubernetes.io/instance-type");
    kafkaProvisioner = ManagedKafkaProvisioner.create(kafkaCluster);
    kafkaProvisioner.setup();
    omb = new OMB(KubeClusterResource.connectToKubeCluster(PerformanceEnvironment.OMB_KUBECONFIG));
    omb.install(kafkaProvisioner.getTlsConfig());
    // TODO: if there is an existing result, make sure it's the same test setup
    profilingResult.ombNodeType = omb.getOmbCluster().getWorkerNodes().get(0).getMetadata().getLabels().get("node.kubernetes.io/instance-type");
    profilingResult.ombWorkerNodes = omb.getOmbCluster().getWorkerNodes().size();
    AvailableResources resources = getMinAvailableResources(omb.getOmbCluster().getWorkerNodes().stream());
    // use all available resources on the worker nodes with 2 workers per node
    // if (resources.memoryBytes > 16*ONE_GB || resources.memoryBytes < 8*ONE_GB) {
    // throw new IllegalStateException("Client instance types are expected to have 16 GB");
    // }
    // assume instead resources that will fit on 2xlarge or xlarge
    resources.cpuMillis = Math.min(6400, resources.cpuMillis);
    resources.memoryBytes = Math.min(12 * ONE_GB, resources.memoryBytes);
    omb.setWorkerCpu(Quantity.parse(resources.cpuMillis / 2 + "m"));
    omb.setWorkerContainerMemory(Quantity.parse(String.valueOf(resources.memoryBytes / 2)));
    profilingResult.ombWorkerCpu = omb.getWorkerCpu();
    profilingResult.ombWorkerMemory = omb.getWorkerContainerMemory();
    LOGGER.info("OMB Workers will use {} cpu and {} memory requests", omb.getWorkerCpu(), omb.getWorkerContainerMemory());
    if (profilingResult.completedStep == null) {
        installedProvisioner = true;
        kafkaProvisioner.install();
        writeResults(Step.SETUP);
    }
}
Also used : AvailableResources(org.bf2.performance.TestUtils.AvailableResources) File(java.io.File)

Example 3 with KafkaCluster

use of org.bf2.operator.operands.KafkaCluster in project kas-fleetshard by bf2fc6cc711aee1a0c2a.

the class InstanceProfiler method deployIfNeeded.

private void deployIfNeeded(String name) throws Exception {
    ManagedKafka mk = null;
    Resource<ManagedKafka> mkResource = kafkaCluster.kubeClient().client().resources(ManagedKafka.class).inNamespace(Constants.KAFKA_NAMESPACE).withName(name);
    try {
        mk = mkResource.get();
    } catch (KubernetesClientException e) {
    }
    ManagedKafkaDeployment kd = null;
    if (mk == null) {
        if (!installedProvisioner) {
            // TODO: come up with a better resume logic here - it currently has to recreate everything
            installedProvisioner = true;
            kafkaProvisioner.install();
        }
        kafkaProvisioner.removeClusters(true);
        kd = kafkaProvisioner.deployCluster(name, profilingResult.capacity, profilingResult.config);
    } else {
        // TODO validate config / capacity
        kd = new ManagedKafkaDeployment(mk, kafkaCluster);
        kd.start();
    }
    instanceBootstrap = kd.waitUntilReady();
}
Also used : ManagedKafka(org.bf2.operator.resources.v1alpha1.ManagedKafka) KubernetesClientException(io.fabric8.kubernetes.client.KubernetesClientException)

Example 4 with KafkaCluster

use of org.bf2.operator.operands.KafkaCluster in project kas-fleetshard by bf2fc6cc711aee1a0c2a.

the class IngressControllerManager method ingressControllersFrom.

private void ingressControllersFrom(Map<String, IngressController> ingressControllers, String clusterDomain, List<Kafka> kafkas, long connectionDemand) {
    LongSummaryStatistics egress = summarize(kafkas, KafkaCluster::getFetchQuota, () -> config.getKafka().getEgressPerSec());
    LongSummaryStatistics ingress = summarize(kafkas, KafkaCluster::getProduceQuota, () -> config.getKafka().getIngressPerSec());
    ingressControllers.entrySet().stream().forEach(e -> {
        String zone = e.getKey();
        String kasZone = "kas-" + zone;
        String domain = kasZone + "." + clusterDomain;
        int replicas = numReplicasForZone(zone, nodeInformer.getList(), ingress, egress, connectionDemand);
        Map<String, String> routeMatchLabel = Map.of("managedkafka.bf2.org/" + kasZone, "true");
        LabelSelector routeSelector = new LabelSelector(null, routeMatchLabel);
        routeMatchLabels.putAll(routeMatchLabel);
        buildIngressController(kasZone, domain, e.getValue(), replicas, routeSelector, zone);
    });
}
Also used : LongSummaryStatistics(java.util.LongSummaryStatistics) AbstractKafkaCluster(org.bf2.operator.operands.AbstractKafkaCluster) KafkaCluster(org.bf2.operator.operands.KafkaCluster) LabelSelector(io.fabric8.kubernetes.api.model.LabelSelector)

Example 5 with KafkaCluster

use of org.bf2.operator.operands.KafkaCluster in project kas-fleetshard by bf2fc6cc711aee1a0c2a.

the class AbstractKafkaCluster method isReconciliationPaused.

public boolean isReconciliationPaused(ManagedKafka managedKafka) {
    Kafka kafka = cachedKafka(managedKafka);
    boolean isReconciliationPaused = kafka != null && kafka.getStatus() != null && hasKafkaCondition(kafka, c -> c.getType() != null && "ReconciliationPaused".equals(c.getType()) && "True".equals(c.getStatus()));
    log.tracef("KafkaCluster isReconciliationPaused = %s", isReconciliationPaused);
    return isReconciliationPaused;
}
Also used : Quantity(io.fabric8.kubernetes.api.model.Quantity) Context(io.javaoperatorsdk.operator.api.Context) KafkaStatus(io.strimzi.api.kafka.model.status.KafkaStatus) GenericKafkaListener(io.strimzi.api.kafka.model.listener.arraylistener.GenericKafkaListener) Arrays(java.util.Arrays) GenericSecretSource(io.strimzi.api.kafka.model.GenericSecretSource) Status(org.bf2.operator.resources.v1alpha1.ManagedKafkaCondition.Status) Logger(org.jboss.logging.Logger) KafkaListenerAuthentication(io.strimzi.api.kafka.model.listener.KafkaListenerAuthentication) StrimziManager(org.bf2.operator.managers.StrimziManager) GenericKafkaListenerConfigurationBrokerBuilder(io.strimzi.api.kafka.model.listener.arraylistener.GenericKafkaListenerConfigurationBrokerBuilder) GenericKafkaListenerConfigurationBootstrapBuilder(io.strimzi.api.kafka.model.listener.arraylistener.GenericKafkaListenerConfigurationBootstrapBuilder) Function(java.util.function.Function) ArrayList(java.util.ArrayList) Inject(javax.inject.Inject) CertAndKeySecretSourceBuilder(io.strimzi.api.kafka.model.CertAndKeySecretSourceBuilder) GenericKafkaListenerConfigurationBroker(io.strimzi.api.kafka.model.listener.arraylistener.GenericKafkaListenerConfigurationBroker) SecuritySecretManager(org.bf2.operator.managers.SecuritySecretManager) Map(java.util.Map) KafkaManager(org.bf2.operator.managers.KafkaManager) KafkaResourceClient(org.bf2.operator.clients.KafkaResourceClient) CertAndKeySecretSource(io.strimzi.api.kafka.model.CertAndKeySecretSource) CertSecretSource(io.strimzi.api.kafka.model.CertSecretSource) Predicate(java.util.function.Predicate) Pod(io.fabric8.kubernetes.api.model.Pod) InformerManager(org.bf2.operator.managers.InformerManager) GenericKafkaListenerBuilder(io.strimzi.api.kafka.model.listener.arraylistener.GenericKafkaListenerBuilder) Reason(org.bf2.operator.resources.v1alpha1.ManagedKafkaCondition.Reason) OpenShiftClient(io.fabric8.openshift.client.OpenShiftClient) ManagedKafkaAuthenticationOAuth(org.bf2.operator.resources.v1alpha1.ManagedKafkaAuthenticationOAuth) Objects(java.util.Objects) List(java.util.List) CertSecretSourceBuilder(io.strimzi.api.kafka.model.CertSecretSourceBuilder) GenericSecretSourceBuilder(io.strimzi.api.kafka.model.GenericSecretSourceBuilder) KafkaListenerType(io.strimzi.api.kafka.model.listener.arraylistener.KafkaListenerType) KubernetesClient(io.fabric8.kubernetes.client.KubernetesClient) KafkaListenerAuthenticationOAuthBuilder(io.strimzi.api.kafka.model.listener.KafkaListenerAuthenticationOAuthBuilder) Optional(java.util.Optional) NetworkPolicyPeerBuilder(io.fabric8.kubernetes.api.model.networking.v1.NetworkPolicyPeerBuilder) Condition(io.strimzi.api.kafka.model.status.Condition) ConfigProperty(org.eclipse.microprofile.config.inject.ConfigProperty) Kafka(io.strimzi.api.kafka.model.Kafka) ManagedKafka(org.bf2.operator.resources.v1alpha1.ManagedKafka) Collections(java.util.Collections) GenericKafkaListenerConfigurationBuilder(io.strimzi.api.kafka.model.listener.arraylistener.GenericKafkaListenerConfigurationBuilder) Kafka(io.strimzi.api.kafka.model.Kafka) ManagedKafka(org.bf2.operator.resources.v1alpha1.ManagedKafka)

Aggregations

ManagedKafka (org.bf2.operator.resources.v1alpha1.ManagedKafka)4 QuarkusTest (io.quarkus.test.junit.QuarkusTest)2 Kafka (io.strimzi.api.kafka.model.Kafka)2 LongSummaryStatistics (java.util.LongSummaryStatistics)2 LabelSelector (io.fabric8.kubernetes.api.model.LabelSelector)1 Pod (io.fabric8.kubernetes.api.model.Pod)1 Quantity (io.fabric8.kubernetes.api.model.Quantity)1 NetworkPolicyPeerBuilder (io.fabric8.kubernetes.api.model.networking.v1.NetworkPolicyPeerBuilder)1 KubernetesClient (io.fabric8.kubernetes.client.KubernetesClient)1 KubernetesClientException (io.fabric8.kubernetes.client.KubernetesClientException)1 OpenShiftClient (io.fabric8.openshift.client.OpenShiftClient)1 Context (io.javaoperatorsdk.operator.api.Context)1 CertAndKeySecretSource (io.strimzi.api.kafka.model.CertAndKeySecretSource)1 CertAndKeySecretSourceBuilder (io.strimzi.api.kafka.model.CertAndKeySecretSourceBuilder)1 CertSecretSource (io.strimzi.api.kafka.model.CertSecretSource)1 CertSecretSourceBuilder (io.strimzi.api.kafka.model.CertSecretSourceBuilder)1 GenericSecretSource (io.strimzi.api.kafka.model.GenericSecretSource)1 GenericSecretSourceBuilder (io.strimzi.api.kafka.model.GenericSecretSourceBuilder)1 KafkaListenerAuthentication (io.strimzi.api.kafka.model.listener.KafkaListenerAuthentication)1 KafkaListenerAuthenticationOAuthBuilder (io.strimzi.api.kafka.model.listener.KafkaListenerAuthenticationOAuthBuilder)1