Search in sources :

Example 41 with ManagedKafka

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

the class KafkaCluster method kafkaFrom.

/* test */
@Override
public Kafka kafkaFrom(ManagedKafka managedKafka, Kafka current) {
    KafkaBuilder builder = current != null ? new KafkaBuilder(current) : new KafkaBuilder();
    int actualReplicas = getBrokerReplicas(managedKafka, current);
    int desiredReplicas = getBrokerReplicas(managedKafka, null);
    KafkaBuilder kafkaBuilder = builder.editOrNewMetadata().withName(kafkaClusterName(managedKafka)).withNamespace(kafkaClusterNamespace(managedKafka)).withLabels(buildKafkaLabels(managedKafka)).withAnnotations(buildKafkaAnnotations(managedKafka, current)).addToAnnotations(REPLICAS, String.valueOf(desiredReplicas)).endMetadata().editOrNewSpec().editOrNewKafka().withVersion(this.kafkaManager.currentKafkaVersion(managedKafka)).withConfig(buildKafkaConfig(managedKafka, current)).withReplicas(actualReplicas).withResources(buildKafkaResources(managedKafka)).withJvmOptions(buildKafkaJvmOptions(managedKafka)).withStorage(buildKafkaStorage(managedKafka, current)).withListeners(buildListeners(managedKafka, actualReplicas)).withRack(buildKafkaRack(managedKafka)).withTemplate(buildKafkaTemplate(managedKafka)).withMetricsConfig(buildKafkaMetricsConfig(managedKafka)).withAuthorization(buildKafkaAuthorization(managedKafka)).withImage(kafkaImage.orElse(null)).withExternalLogging(buildKafkaExternalLogging(managedKafka)).endKafka().editOrNewZookeeper().withReplicas(this.config.getZookeeper().getReplicas()).withStorage((SingleVolumeStorage) buildZooKeeperStorage(current)).withResources(buildZooKeeperResources(managedKafka)).withJvmOptions(buildZooKeeperJvmOptions(managedKafka)).withTemplate(buildZookeeperTemplate(managedKafka)).withMetricsConfig(buildZooKeeperMetricsConfig(managedKafka)).withImage(zookeeperImage.orElse(null)).withExternalLogging(buildZookeeperExternalLogging(managedKafka)).endZookeeper().withKafkaExporter(buildKafkaExporter(managedKafka)).endSpec();
    Kafka kafka = this.upgrade(managedKafka, kafkaBuilder);
    // setting the ManagedKafka as owner of the Kafka resource is needed
    // by the operator sdk to handle events on the Kafka resource properly
    OperandUtils.setAsOwner(managedKafka, kafka);
    return kafka;
}
Also used : SingleVolumeStorage(io.strimzi.api.kafka.model.storage.SingleVolumeStorage) ManagedKafka(org.bf2.operator.resources.v1alpha1.ManagedKafka) Kafka(io.strimzi.api.kafka.model.Kafka) KafkaBuilder(io.strimzi.api.kafka.model.KafkaBuilder) TopologySpreadConstraint(io.fabric8.kubernetes.api.model.TopologySpreadConstraint)

Example 42 with ManagedKafka

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

the class KafkaCluster method buildKafkaStorage.

private Storage buildKafkaStorage(ManagedKafka managedKafka, Kafka current) {
    PersistentClaimStorageBuilder builder = new PersistentClaimStorageBuilder().withId(JBOD_VOLUME_ID).withSize(getAdjustedMaxDataRetentionSize(managedKafka, current).getAmount()).withDeleteClaim(DELETE_CLAIM);
    Optional.ofNullable(current).map(Kafka::getSpec).map(KafkaSpec::getKafka).map(KafkaClusterSpec::getStorage).map(this::getExistingVolumesFromJbodStorage).ifPresentOrElse(existingVolumes -> existingVolumes.stream().forEach(v -> handleExistingVolume(v, builder)), () -> builder.withStorageClass(config.getKafka().getStorageClass()));
    return new JbodStorageBuilder().withVolumes(builder.build()).build();
}
Also used : KafkaClusterSpec(io.strimzi.api.kafka.model.KafkaClusterSpec) Quantity(io.fabric8.kubernetes.api.model.Quantity) KafkaClusterSpec(io.strimzi.api.kafka.model.KafkaClusterSpec) PodAffinityTerm(io.fabric8.kubernetes.api.model.PodAffinityTerm) LabelSelector(io.fabric8.kubernetes.api.model.LabelSelector) ImagePullSecretManager(org.bf2.operator.managers.ImagePullSecretManager) Storage(io.strimzi.api.kafka.model.storage.Storage) Rack(io.strimzi.api.kafka.model.Rack) StrimziManager(org.bf2.operator.managers.StrimziManager) Resource(io.fabric8.kubernetes.client.dsl.Resource) JvmOptionsBuilder(io.strimzi.api.kafka.model.JvmOptionsBuilder) PersistentClaimStorage(io.strimzi.api.kafka.model.storage.PersistentClaimStorage) ResourceRequirements(io.fabric8.kubernetes.api.model.ResourceRequirements) ConfigMapKeySelector(io.fabric8.kubernetes.api.model.ConfigMapKeySelector) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) KafkaClusterTemplate(io.strimzi.api.kafka.model.template.KafkaClusterTemplate) SystemProperty(io.strimzi.api.kafka.model.SystemProperty) Map(java.util.Map) KafkaExporterSpec(io.strimzi.api.kafka.model.KafkaExporterSpec) KafkaSpec(io.strimzi.api.kafka.model.KafkaSpec) KafkaManager(org.bf2.operator.managers.KafkaManager) Instance(javax.enterprise.inject.Instance) ExternalLogging(io.strimzi.api.kafka.model.ExternalLogging) ZookeeperClusterTemplateBuilder(io.strimzi.api.kafka.model.template.ZookeeperClusterTemplateBuilder) JvmOptions(io.strimzi.api.kafka.model.JvmOptions) JbodStorageBuilder(io.strimzi.api.kafka.model.storage.JbodStorageBuilder) OperandUtils(org.bf2.common.OperandUtils) DrainCleanerManager(org.bf2.operator.managers.DrainCleanerManager) Config(org.eclipse.microprofile.config.Config) Collectors(java.util.stream.Collectors) Objects(java.util.Objects) PodAffinityTermBuilder(io.fabric8.kubernetes.api.model.PodAffinityTermBuilder) Startup(io.quarkus.runtime.Startup) List(java.util.List) RackBuilder(io.strimzi.api.kafka.model.RackBuilder) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) Optional(java.util.Optional) ApplicationScoped(javax.enterprise.context.ApplicationScoped) TopologySpreadConstraintBuilder(io.fabric8.kubernetes.api.model.TopologySpreadConstraintBuilder) ManagedKafka(org.bf2.operator.resources.v1alpha1.ManagedKafka) DatatypeConverter(javax.xml.bind.DatatypeConverter) ZookeeperClusterTemplate(io.strimzi.api.kafka.model.template.ZookeeperClusterTemplate) PersistentVolumeClaimStatus(io.fabric8.kubernetes.api.model.PersistentVolumeClaimStatus) Context(io.javaoperatorsdk.operator.api.Context) ZookeeperClusterSpec(io.strimzi.api.kafka.model.ZookeeperClusterSpec) ExternalLoggingBuilder(io.strimzi.api.kafka.model.ExternalLoggingBuilder) MessageDigest(java.security.MessageDigest) Logger(org.jboss.logging.Logger) ResourceRequirementsBuilder(io.fabric8.kubernetes.api.model.ResourceRequirementsBuilder) KafkaAuthorizationCustomBuilder(io.strimzi.api.kafka.model.KafkaAuthorizationCustomBuilder) SingleVolumeStorage(io.strimzi.api.kafka.model.storage.SingleVolumeStorage) HashMap(java.util.HashMap) Supplier(java.util.function.Supplier) KafkaBuilder(io.strimzi.api.kafka.model.KafkaBuilder) Inject(javax.inject.Inject) PodDisruptionBudgetTemplateBuilder(io.strimzi.api.kafka.model.template.PodDisruptionBudgetTemplateBuilder) DefaultBean(io.quarkus.arc.DefaultBean) PersistentClaimStorageBuilder(io.strimzi.api.kafka.model.storage.PersistentClaimStorageBuilder) PodAntiAffinity(io.fabric8.kubernetes.api.model.PodAntiAffinity) ExternalConfigurationReferenceBuilder(io.strimzi.api.kafka.model.ExternalConfigurationReferenceBuilder) JmxPrometheusExporterMetricsBuilder(io.strimzi.api.kafka.model.JmxPrometheusExporterMetricsBuilder) KafkaAuthorization(io.strimzi.api.kafka.model.KafkaAuthorization) KafkaClusterTemplateBuilder(io.strimzi.api.kafka.model.template.KafkaClusterTemplateBuilder) MetricsConfig(io.strimzi.api.kafka.model.MetricsConfig) SecuritySecretManager(org.bf2.operator.managers.SecuritySecretManager) PodAffinity(io.fabric8.kubernetes.api.model.PodAffinity) PodAntiAffinityBuilder(io.fabric8.kubernetes.api.model.PodAntiAffinityBuilder) Versions(org.bf2.operator.resources.v1alpha1.Versions) JbodStorage(io.strimzi.api.kafka.model.storage.JbodStorage) TopologySpreadConstraint(io.fabric8.kubernetes.api.model.TopologySpreadConstraint) IngressControllerManager(org.bf2.operator.managers.IngressControllerManager) Toleration(io.fabric8.kubernetes.api.model.Toleration) IOException(java.io.IOException) PodTemplateBuilder(io.strimzi.api.kafka.model.template.PodTemplateBuilder) ServiceAccount(org.bf2.operator.resources.v1alpha1.ServiceAccount) TolerationBuilder(io.fabric8.kubernetes.api.model.TolerationBuilder) ConfigMap(io.fabric8.kubernetes.api.model.ConfigMap) AffinityBuilder(io.fabric8.kubernetes.api.model.AffinityBuilder) ConfigMapBuilder(io.fabric8.kubernetes.api.model.ConfigMapBuilder) ManagedKafkaAuthenticationOAuth(org.bf2.operator.resources.v1alpha1.ManagedKafkaAuthenticationOAuth) KafkaExporterSpecBuilder(io.strimzi.api.kafka.model.KafkaExporterSpecBuilder) AccessControl(org.bf2.operator.operands.KafkaInstanceConfiguration.AccessControl) SystemPropertyBuilder(io.strimzi.api.kafka.model.SystemPropertyBuilder) ConfigMapKeySelectorBuilder(io.fabric8.kubernetes.api.model.ConfigMapKeySelectorBuilder) DigestInputStream(java.security.DigestInputStream) PodNested(io.strimzi.api.kafka.model.template.ZookeeperClusterTemplateFluent.PodNested) ConfigProperty(org.eclipse.microprofile.config.inject.ConfigProperty) Kafka(io.strimzi.api.kafka.model.Kafka) Collections(java.util.Collections) InputStream(java.io.InputStream) JbodStorageBuilder(io.strimzi.api.kafka.model.storage.JbodStorageBuilder) ManagedKafka(org.bf2.operator.resources.v1alpha1.ManagedKafka) Kafka(io.strimzi.api.kafka.model.Kafka) PersistentClaimStorageBuilder(io.strimzi.api.kafka.model.storage.PersistentClaimStorageBuilder)

Example 43 with ManagedKafka

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

the class KafkaCluster method addQuotaConfig.

private void addQuotaConfig(ManagedKafka managedKafka, Kafka current, Map<String, Object> config) {
    config.put("client.quota.callback.class", IO_STRIMZI_KAFKA_QUOTA_STATIC_QUOTA_CALLBACK);
    // Throttle at Ingress/Egress MB/sec per broker
    config.put(QUOTA_PRODUCE, String.valueOf(getIngressBytes(managedKafka, current)));
    config.put(QUOTA_FETCH, String.valueOf(getEgressBytes(managedKafka, current)));
    // Start throttling when disk is above requested size. Full stop when only storageMinMargin is free.
    Quantity maxDataRetentionSize = getAdjustedMaxDataRetentionSize(managedKafka, current);
    long hardStorageLimit = Quantity.getAmountInBytes(maxDataRetentionSize).longValue() - Quantity.getAmountInBytes(storageMinMargin).longValue();
    long softStorageLimit = Quantity.getAmountInBytes(maxDataRetentionSize).longValue() - getStoragePadding(managedKafka, current);
    config.put("client.quota.callback.static.storage.soft", String.valueOf(softStorageLimit));
    config.put("client.quota.callback.static.storage.hard", String.valueOf(hardStorageLimit));
    // Check storage every storageCheckInterval seconds
    config.put("client.quota.callback.static.storage.check-interval", String.valueOf(storageCheckInterval));
    // Configure the quota plugin so that the canary is not subjected to the quota checks.
    Optional<ServiceAccount> canaryServiceAccount = managedKafka.getServiceAccount(ServiceAccount.ServiceAccountName.Canary);
    canaryServiceAccount.ifPresent(serviceAccount -> config.put("client.quota.callback.static.excluded.principal.name.list", serviceAccount.getPrincipal()));
    config.put("quota.window.num", "30");
    config.put("quota.window.size.seconds", "2");
}
Also used : ServiceAccount(org.bf2.operator.resources.v1alpha1.ServiceAccount) Quantity(io.fabric8.kubernetes.api.model.Quantity)

Example 44 with ManagedKafka

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

the class IngressControllerManager method getManagedKafkaRoutesFor.

public List<ManagedKafkaRoute> getManagedKafkaRoutesFor(ManagedKafka mk) {
    String multiZoneRoute = getIngressControllerDomain("kas");
    String bootstrapDomain = mk.getSpec().getEndpoint().getBootstrapServerHost();
    return Stream.concat(Stream.of(new ManagedKafkaRoute("bootstrap", "", multiZoneRoute), new ManagedKafkaRoute("admin-server", "admin-server", multiZoneRoute)), routesFor(mk).filter(IS_BROKER_ROUTE).map(r -> {
        String router = getIngressControllerDomain("kas-" + getZoneForBrokerRoute(r));
        String routePrefix = r.getSpec().getHost().replaceFirst("-" + bootstrapDomain, "");
        return new ManagedKafkaRoute(routePrefix, routePrefix, router);
    })).sorted(Comparator.comparing(ManagedKafkaRoute::getName)).collect(Collectors.toList());
}
Also used : Quantity(io.fabric8.kubernetes.api.model.Quantity) KafkaClusterSpec(io.strimzi.api.kafka.model.KafkaClusterSpec) LabelSelector(io.fabric8.kubernetes.api.model.LabelSelector) Cache(io.fabric8.kubernetes.client.informers.cache.Cache) ManagedKafkaRoute(org.bf2.operator.resources.v1alpha1.ManagedKafkaRoute) IngressControllerBuilder(io.fabric8.openshift.api.model.operator.v1.IngressControllerBuilder) TypedVisitor(io.fabric8.kubernetes.api.builder.TypedVisitor) BigDecimal(java.math.BigDecimal) Resource(io.fabric8.kubernetes.client.dsl.Resource) Route(io.fabric8.openshift.api.model.Route) IngressControllerSpec(io.fabric8.openshift.api.model.operator.v1.IngressControllerSpec) Map(java.util.Map) ContainerBuilder(io.fabric8.kubernetes.api.model.ContainerBuilder) AbstractKafkaCluster(org.bf2.operator.operands.AbstractKafkaCluster) Scheduled(io.quarkus.scheduler.Scheduled) OperandUtils(org.bf2.common.OperandUtils) Predicate(java.util.function.Predicate) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HasMetadata(io.fabric8.kubernetes.api.model.HasMetadata) FilterWatchListDeletable(io.fabric8.kubernetes.client.dsl.FilterWatchListDeletable) Collectors(java.util.stream.Collectors) NodeList(io.fabric8.kubernetes.api.model.NodeList) Objects(java.util.Objects) Startup(io.quarkus.runtime.Startup) List(java.util.List) KafkaCluster(org.bf2.operator.operands.KafkaCluster) Stream(java.util.stream.Stream) IngressControllerList(io.fabric8.openshift.api.model.operator.v1.IngressControllerList) ResourceInformerFactory(org.bf2.common.ResourceInformerFactory) PostConstruct(javax.annotation.PostConstruct) Optional(java.util.Optional) ApplicationScoped(javax.enterprise.context.ApplicationScoped) Pattern(java.util.regex.Pattern) IngressController(io.fabric8.openshift.api.model.operator.v1.IngressController) ManagedKafka(org.bf2.operator.resources.v1alpha1.ManagedKafka) GenericKafkaListener(io.strimzi.api.kafka.model.listener.arraylistener.GenericKafkaListener) ResourceEventHandler(io.fabric8.kubernetes.client.informers.ResourceEventHandler) Logger(org.jboss.logging.Logger) ResourceRequirementsBuilder(io.fabric8.kubernetes.api.model.ResourceRequirementsBuilder) HashMap(java.util.HashMap) Function(java.util.function.Function) Supplier(java.util.function.Supplier) Inject(javax.inject.Inject) UnlessBuildProperty(io.quarkus.arc.properties.UnlessBuildProperty) GenericKafkaListenerConfiguration(io.strimzi.api.kafka.model.listener.arraylistener.GenericKafkaListenerConfiguration) Service(io.fabric8.kubernetes.api.model.Service) Node(io.fabric8.kubernetes.api.model.Node) LongSummaryStatistics(java.util.LongSummaryStatistics) KafkaInstanceConfiguration(org.bf2.operator.operands.KafkaInstanceConfiguration) Pod(io.fabric8.kubernetes.api.model.Pod) OpenShiftClient(io.fabric8.openshift.client.OpenShiftClient) ResourceInformer(org.bf2.common.ResourceInformer) NonNamespaceOperation(io.fabric8.kubernetes.client.dsl.NonNamespaceOperation) PodList(io.fabric8.kubernetes.api.model.PodList) ConfigProperty(org.eclipse.microprofile.config.inject.ConfigProperty) Kafka(io.strimzi.api.kafka.model.Kafka) Comparator(java.util.Comparator) Deployment(io.fabric8.kubernetes.api.model.apps.Deployment) ManagedKafkaRoute(org.bf2.operator.resources.v1alpha1.ManagedKafkaRoute)

Example 45 with ManagedKafka

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

the class KafkaManager method doKafkaUpgradeStabilityCheck.

/**
 * Scheduled job to execute the Kafka stability check
 *
 * @param managedKafka ManagedKafka instance
 */
void doKafkaUpgradeStabilityCheck(ManagedKafka managedKafka) {
    log.infof("[%s/%s] Kafka upgrade stability check", managedKafka.getMetadata().getNamespace(), managedKafka.getMetadata().getName());
    CanaryService canaryService = RestClientBuilder.newBuilder().baseUri(URI.create("http://" + AbstractCanary.canaryName(managedKafka) + "." + managedKafka.getMetadata().getNamespace() + ":8080")).connectTimeout(10, TimeUnit.SECONDS).readTimeout(30, TimeUnit.SECONDS).build(CanaryService.class);
    try {
        Status status = canaryService.getStatus();
        log.infof("[%s/%s] Canary status: timeWindow %d - percentage %d", managedKafka.getMetadata().getNamespace(), managedKafka.getMetadata().getName(), status.getConsuming().getTimeWindow(), status.getConsuming().getPercentage());
        if (status.getConsuming().getPercentage() > consumingPercentageThreshold) {
            log.debugf("[%s/%s] Remove Kafka upgrade start/end annotations", managedKafka.getMetadata().getNamespace(), managedKafka.getMetadata().getName());
            managedKafkaClient.inNamespace(managedKafka.getMetadata().getNamespace()).withName(managedKafka.getMetadata().getName()).edit(mk -> new ManagedKafkaBuilder(mk).editMetadata().removeFromAnnotations(KAFKA_UPGRADE_START_TIMESTAMP_ANNOTATION).removeFromAnnotations(KAFKA_UPGRADE_END_TIMESTAMP_ANNOTATION).endMetadata().build());
        } else {
            log.warnf("[%s/%s] Reported consuming percentage %d less than %d threshold", managedKafka.getMetadata().getNamespace(), managedKafka.getMetadata().getName(), status.getConsuming().getPercentage(), consumingPercentageThreshold);
            managedKafkaClient.inNamespace(managedKafka.getMetadata().getNamespace()).withName(managedKafka.getMetadata().getName()).edit(mk -> new ManagedKafkaBuilder(mk).editMetadata().removeFromAnnotations(KAFKA_UPGRADE_END_TIMESTAMP_ANNOTATION).endMetadata().build());
        }
        // trigger a reconcile on the ManagedKafka instance to push checking if next step
        // Kafka IBP upgrade is needed or another stability check
        informerManager.resyncManagedKafka(managedKafka);
    } catch (Exception e) {
        log.errorf("[%s/%s] Error while checking Kafka upgrade stability", managedKafka.getMetadata().getNamespace(), managedKafka.getMetadata().getName(), e);
    }
}
Also used : Status(org.bf2.operator.clients.canary.Status) CanaryService(org.bf2.operator.clients.canary.CanaryService) ManagedKafkaBuilder(org.bf2.operator.resources.v1alpha1.ManagedKafkaBuilder) SchedulerException(org.quartz.SchedulerException)

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