Search in sources :

Example 6 with ReconciliationException

use of io.strimzi.operator.common.ReconciliationException in project strimzi by strimzi.

the class KafkaAssemblyOperator method createOrUpdate.

@Override
public Future<KafkaStatus> createOrUpdate(Reconciliation reconciliation, Kafka kafkaAssembly) {
    Promise<KafkaStatus> createOrUpdatePromise = Promise.promise();
    ReconciliationState reconcileState = createReconciliationState(reconciliation, kafkaAssembly);
    reconcile(reconcileState).onComplete(reconcileResult -> {
        KafkaStatus status = reconcileState.kafkaStatus;
        Condition condition;
        if (kafkaAssembly.getMetadata().getGeneration() != null) {
            status.setObservedGeneration(kafkaAssembly.getMetadata().getGeneration());
        }
        if (reconcileResult.succeeded()) {
            condition = new ConditionBuilder().withLastTransitionTime(StatusUtils.iso8601(dateSupplier())).withType("Ready").withStatus("True").build();
            status.addCondition(condition);
            createOrUpdatePromise.complete(status);
        } else {
            condition = new ConditionBuilder().withLastTransitionTime(StatusUtils.iso8601(dateSupplier())).withType("NotReady").withStatus("True").withReason(reconcileResult.cause().getClass().getSimpleName()).withMessage(reconcileResult.cause().getMessage()).build();
            status.addCondition(condition);
            createOrUpdatePromise.fail(new ReconciliationException(status, reconcileResult.cause()));
        }
    });
    return createOrUpdatePromise.future();
}
Also used : Condition(io.strimzi.api.kafka.model.status.Condition) ReconciliationException(io.strimzi.operator.common.ReconciliationException) ConditionBuilder(io.strimzi.api.kafka.model.status.ConditionBuilder) KafkaStatus(io.strimzi.api.kafka.model.status.KafkaStatus)

Example 7 with ReconciliationException

use of io.strimzi.operator.common.ReconciliationException in project strimzi by strimzi.

the class KafkaConnectAssemblyOperator method createOrUpdate.

@Override
protected Future<KafkaConnectStatus> createOrUpdate(Reconciliation reconciliation, KafkaConnect kafkaConnect) {
    KafkaConnectCluster connect;
    KafkaConnectBuild build;
    KafkaConnectStatus kafkaConnectStatus = new KafkaConnectStatus();
    try {
        connect = KafkaConnectCluster.fromCrd(reconciliation, kafkaConnect, versions);
        build = KafkaConnectBuild.fromCrd(reconciliation, kafkaConnect, versions);
    } catch (Exception e) {
        LOGGER.warnCr(reconciliation, e);
        StatusUtils.setStatusConditionAndObservedGeneration(kafkaConnect, kafkaConnectStatus, Future.failedFuture(e));
        return Future.failedFuture(new ReconciliationException(kafkaConnectStatus, e));
    }
    Promise<KafkaConnectStatus> createOrUpdatePromise = Promise.promise();
    String namespace = reconciliation.namespace();
    Map<String, String> annotations = new HashMap<>(2);
    boolean connectHasZeroReplicas = connect.getReplicas() == 0;
    final AtomicReference<String> image = new AtomicReference<>();
    final AtomicReference<String> desiredLogging = new AtomicReference<>();
    String initCrbName = KafkaConnectResources.initContainerClusterRoleBindingName(kafkaConnect.getMetadata().getName(), namespace);
    ClusterRoleBinding initCrb = connect.generateClusterRoleBinding();
    LOGGER.debugCr(reconciliation, "Updating Kafka Connect cluster");
    connectServiceAccount(reconciliation, namespace, KafkaConnectResources.serviceAccountName(connect.getCluster()), connect).compose(i -> connectInitClusterRoleBinding(reconciliation, initCrbName, initCrb)).compose(i -> connectNetworkPolicy(reconciliation, namespace, connect, isUseResources(kafkaConnect))).compose(i -> connectBuildOperator.reconcile(reconciliation, namespace, connect.getName(), build)).compose(buildInfo -> {
        if (buildInfo != null) {
            annotations.put(Annotations.STRIMZI_IO_CONNECT_BUILD_REVISION, buildInfo.getBuildRevision());
            image.set(buildInfo.getImage());
        }
        return Future.succeededFuture();
    }).compose(i -> deploymentOperations.scaleDown(reconciliation, namespace, connect.getName(), connect.getReplicas())).compose(i -> serviceOperations.reconcile(reconciliation, namespace, connect.getServiceName(), connect.generateService())).compose(i -> generateMetricsAndLoggingConfigMap(reconciliation, namespace, connect)).compose(logAndMetricsConfigMap -> {
        String logging = logAndMetricsConfigMap.getData().get(AbstractModel.ANCILLARY_CM_KEY_LOG_CONFIG);
        annotations.put(Annotations.ANNO_STRIMZI_LOGGING_DYNAMICALLY_UNCHANGEABLE_HASH, Util.hashStub(Util.getLoggingDynamicallyUnmodifiableEntries(logging)));
        desiredLogging.set(logging);
        return configMapOperations.reconcile(reconciliation, namespace, connect.getAncillaryConfigMapName(), logAndMetricsConfigMap);
    }).compose(i -> kafkaConnectJmxSecret(reconciliation, namespace, kafkaConnect.getMetadata().getName(), connect)).compose(i -> pfa.hasPodDisruptionBudgetV1() ? podDisruptionBudgetOperator.reconcile(reconciliation, namespace, connect.getName(), connect.generatePodDisruptionBudget()) : Future.succeededFuture()).compose(i -> !pfa.hasPodDisruptionBudgetV1() ? podDisruptionBudgetV1Beta1Operator.reconcile(reconciliation, namespace, connect.getName(), connect.generatePodDisruptionBudgetV1Beta1()) : Future.succeededFuture()).compose(i -> generateAuthHash(namespace, kafkaConnect.getSpec())).compose(hash -> {
        annotations.put(Annotations.ANNO_STRIMZI_AUTH_HASH, Integer.toString(hash));
        Deployment deployment = generateDeployment(connect, image.get(), annotations);
        return deploymentOperations.reconcile(reconciliation, namespace, connect.getName(), deployment);
    }).compose(i -> deploymentOperations.scaleUp(reconciliation, namespace, connect.getName(), connect.getReplicas())).compose(i -> deploymentOperations.waitForObserved(reconciliation, namespace, connect.getName(), 1_000, operationTimeoutMs)).compose(i -> connectHasZeroReplicas ? Future.succeededFuture() : deploymentOperations.readiness(reconciliation, namespace, connect.getName(), 1_000, operationTimeoutMs)).compose(i -> reconcileConnectors(reconciliation, kafkaConnect, kafkaConnectStatus, connectHasZeroReplicas, desiredLogging.get(), connect.getDefaultLogConfig())).onComplete(reconciliationResult -> {
        StatusUtils.setStatusConditionAndObservedGeneration(kafkaConnect, kafkaConnectStatus, reconciliationResult);
        if (!connectHasZeroReplicas) {
            kafkaConnectStatus.setUrl(KafkaConnectResources.url(connect.getCluster(), namespace, KafkaConnectCluster.REST_API_PORT));
        }
        kafkaConnectStatus.setReplicas(connect.getReplicas());
        kafkaConnectStatus.setLabelSelector(connect.getSelectorLabels().toSelectorString());
        if (reconciliationResult.succeeded()) {
            createOrUpdatePromise.complete(kafkaConnectStatus);
        } else {
            createOrUpdatePromise.fail(new ReconciliationException(kafkaConnectStatus, reconciliationResult.cause()));
        }
    });
    return createOrUpdatePromise.future();
}
Also used : KafkaConnectStatus(io.strimzi.api.kafka.model.status.KafkaConnectStatus) ReconciliationException(io.strimzi.operator.common.ReconciliationException) ClusterRoleBinding(io.fabric8.kubernetes.api.model.rbac.ClusterRoleBinding) LabelSelector(io.fabric8.kubernetes.api.model.LabelSelector) Annotations(io.strimzi.operator.common.Annotations) HashMap(java.util.HashMap) AtomicReference(java.util.concurrent.atomic.AtomicReference) Function(java.util.function.Function) KafkaConnector(io.strimzi.api.kafka.model.KafkaConnector) Resource(io.fabric8.kubernetes.client.dsl.Resource) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) KafkaConnectStatus(io.strimzi.api.kafka.model.status.KafkaConnectStatus) Map(java.util.Map) ResourceOperatorSupplier(io.strimzi.operator.cluster.operator.resource.ResourceOperatorSupplier) ReconciliationException(io.strimzi.operator.common.ReconciliationException) AsyncResult(io.vertx.core.AsyncResult) AbstractModel(io.strimzi.operator.cluster.model.AbstractModel) Operator(io.strimzi.operator.common.Operator) StatusUtils(io.strimzi.operator.common.operator.resource.StatusUtils) KafkaConnect(io.strimzi.api.kafka.model.KafkaConnect) ReconciliationLogger(io.strimzi.operator.common.ReconciliationLogger) CertSecretSource(io.strimzi.api.kafka.model.CertSecretSource) KafkaConnectBuild(io.strimzi.operator.cluster.model.KafkaConnectBuild) DeploymentOperator(io.strimzi.operator.common.operator.resource.DeploymentOperator) Promise(io.vertx.core.Promise) KafkaVersion(io.strimzi.operator.cluster.model.KafkaVersion) Vertx(io.vertx.core.Vertx) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) Set(java.util.Set) Future(io.vertx.core.Future) Collectors(java.util.stream.Collectors) Reconciliation(io.strimzi.operator.common.Reconciliation) NamespaceAndName(io.strimzi.operator.common.model.NamespaceAndName) KafkaConnectCluster(io.strimzi.operator.cluster.model.KafkaConnectCluster) List(java.util.List) Util(io.strimzi.operator.common.Util) Labels(io.strimzi.operator.common.model.Labels) KafkaConnectorStatus(io.strimzi.api.kafka.model.status.KafkaConnectorStatus) KubernetesClient(io.fabric8.kubernetes.client.KubernetesClient) Optional(java.util.Optional) KafkaConnectList(io.strimzi.api.kafka.KafkaConnectList) Handler(io.vertx.core.Handler) LabelSelectorRequirement(io.fabric8.kubernetes.api.model.LabelSelectorRequirement) Deployment(io.fabric8.kubernetes.api.model.apps.Deployment) KafkaConnectSpec(io.strimzi.api.kafka.model.KafkaConnectSpec) KafkaClientAuthentication(io.strimzi.api.kafka.model.authentication.KafkaClientAuthentication) PlatformFeaturesAvailability(io.strimzi.operator.PlatformFeaturesAvailability) Collections(java.util.Collections) ClusterOperatorConfig(io.strimzi.operator.cluster.ClusterOperatorConfig) KafkaConnectResources(io.strimzi.api.kafka.model.KafkaConnectResources) HashMap(java.util.HashMap) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) ClusterRoleBinding(io.fabric8.kubernetes.api.model.rbac.ClusterRoleBinding) Deployment(io.fabric8.kubernetes.api.model.apps.Deployment) KafkaConnectCluster(io.strimzi.operator.cluster.model.KafkaConnectCluster) AtomicReference(java.util.concurrent.atomic.AtomicReference) ReconciliationException(io.strimzi.operator.common.ReconciliationException) KafkaConnectBuild(io.strimzi.operator.cluster.model.KafkaConnectBuild)

Example 8 with ReconciliationException

use of io.strimzi.operator.common.ReconciliationException in project strimzi by strimzi.

the class KafkaUserOperator method createOrUpdate.

/**
 * Creates or updates the user. The implementation
 * should not assume that any resources are in any particular state (e.g. that the absence on
 * one resource means that all resources need to be created).
 *
 * @param reconciliation Unique identification for the reconciliation
 * @param resource KafkaUser resources with the desired user configuration.
 * @return a Future
 */
@Override
protected Future<KafkaUserStatus> createOrUpdate(Reconciliation reconciliation, KafkaUser resource) {
    KafkaUserModel user;
    KafkaUserStatus userStatus = new KafkaUserStatus();
    try {
        user = KafkaUserModel.fromCrd(resource, config.getSecretPrefix(), config.isAclsAdminApiSupported(), config.isKraftEnabled());
        LOGGER.debugCr(reconciliation, "Updating User {} in namespace {}", reconciliation.name(), reconciliation.namespace());
    } catch (Exception e) {
        LOGGER.warnCr(reconciliation, e);
        StatusUtils.setStatusConditionAndObservedGeneration(resource, userStatus, Future.failedFuture(e));
        return Future.failedFuture(new ReconciliationException(userStatus, e));
    }
    Promise<KafkaUserStatus> handler = Promise.promise();
    secretOperations.getAsync(reconciliation.namespace(), user.getSecretName()).compose(userSecret -> maybeGenerateCredentials(reconciliation, user, userSecret)).compose(ignore -> reconcileCredentialsQuotasAndAcls(reconciliation, user, userStatus)).onComplete(reconciliationResult -> {
        StatusUtils.setStatusConditionAndObservedGeneration(resource, userStatus, reconciliationResult.mapEmpty());
        userStatus.setUsername(user.getUserName());
        if (reconciliationResult.succeeded()) {
            handler.complete(userStatus);
        } else {
            handler.fail(new ReconciliationException(userStatus, reconciliationResult.cause()));
        }
    });
    return handler.future();
}
Also used : ReconciliationException(io.strimzi.operator.common.ReconciliationException) Date(java.util.Date) CertManager(io.strimzi.certs.CertManager) KafkaUser(io.strimzi.api.kafka.model.KafkaUser) KafkaUserList(io.strimzi.api.kafka.KafkaUserList) CompositeFuture(io.vertx.core.CompositeFuture) CrdOperator(io.strimzi.operator.common.operator.resource.CrdOperator) ReconciliationException(io.strimzi.operator.common.ReconciliationException) ReconcileResult(io.strimzi.operator.common.operator.resource.ReconcileResult) AbstractOperator(io.strimzi.operator.common.AbstractOperator) StatusUtils(io.strimzi.operator.common.operator.resource.StatusUtils) ReconciliationLogger(io.strimzi.operator.common.ReconciliationLogger) KafkaUserStatus(io.strimzi.api.kafka.model.status.KafkaUserStatus) SimpleAclRule(io.strimzi.operator.user.model.acl.SimpleAclRule) Promise(io.vertx.core.Promise) Collection(java.util.Collection) MicrometerMetricsProvider(io.strimzi.operator.common.MicrometerMetricsProvider) Vertx(io.vertx.core.Vertx) SecretOperator(io.strimzi.operator.common.operator.resource.SecretOperator) Set(java.util.Set) Future(io.vertx.core.Future) Collectors(java.util.stream.Collectors) KafkaUserModel(io.strimzi.operator.user.model.KafkaUserModel) Reconciliation(io.strimzi.operator.common.Reconciliation) NamespaceAndName(io.strimzi.operator.common.model.NamespaceAndName) List(java.util.List) KafkaUserQuotas(io.strimzi.api.kafka.model.KafkaUserQuotas) PasswordGenerator(io.strimzi.operator.common.PasswordGenerator) UserOperatorConfig(io.strimzi.operator.user.UserOperatorConfig) KubernetesClient(io.fabric8.kubernetes.client.KubernetesClient) Secret(io.fabric8.kubernetes.api.model.Secret) KafkaUserSpec(io.strimzi.api.kafka.model.KafkaUserSpec) KafkaUserModel(io.strimzi.operator.user.model.KafkaUserModel) KafkaUserStatus(io.strimzi.api.kafka.model.status.KafkaUserStatus) ReconciliationException(io.strimzi.operator.common.ReconciliationException)

Example 9 with ReconciliationException

use of io.strimzi.operator.common.ReconciliationException in project strimzi-kafka-operator by strimzi.

the class KafkaConnectAssemblyOperator method createOrUpdate.

@Override
protected Future<KafkaConnectStatus> createOrUpdate(Reconciliation reconciliation, KafkaConnect kafkaConnect) {
    KafkaConnectCluster connect;
    KafkaConnectBuild build;
    KafkaConnectStatus kafkaConnectStatus = new KafkaConnectStatus();
    try {
        connect = KafkaConnectCluster.fromCrd(reconciliation, kafkaConnect, versions);
        build = KafkaConnectBuild.fromCrd(reconciliation, kafkaConnect, versions);
    } catch (Exception e) {
        LOGGER.warnCr(reconciliation, e);
        StatusUtils.setStatusConditionAndObservedGeneration(kafkaConnect, kafkaConnectStatus, Future.failedFuture(e));
        return Future.failedFuture(new ReconciliationException(kafkaConnectStatus, e));
    }
    Promise<KafkaConnectStatus> createOrUpdatePromise = Promise.promise();
    String namespace = reconciliation.namespace();
    Map<String, String> annotations = new HashMap<>(2);
    boolean connectHasZeroReplicas = connect.getReplicas() == 0;
    final AtomicReference<String> image = new AtomicReference<>();
    final AtomicReference<String> desiredLogging = new AtomicReference<>();
    String initCrbName = KafkaConnectResources.initContainerClusterRoleBindingName(kafkaConnect.getMetadata().getName(), namespace);
    ClusterRoleBinding initCrb = connect.generateClusterRoleBinding();
    LOGGER.debugCr(reconciliation, "Updating Kafka Connect cluster");
    connectServiceAccount(reconciliation, namespace, KafkaConnectResources.serviceAccountName(connect.getCluster()), connect).compose(i -> connectInitClusterRoleBinding(reconciliation, initCrbName, initCrb)).compose(i -> connectNetworkPolicy(reconciliation, namespace, connect, isUseResources(kafkaConnect))).compose(i -> connectBuildOperator.reconcile(reconciliation, namespace, connect.getName(), build)).compose(buildInfo -> {
        if (buildInfo != null) {
            annotations.put(Annotations.STRIMZI_IO_CONNECT_BUILD_REVISION, buildInfo.getBuildRevision());
            image.set(buildInfo.getImage());
        }
        return Future.succeededFuture();
    }).compose(i -> deploymentOperations.scaleDown(reconciliation, namespace, connect.getName(), connect.getReplicas())).compose(i -> serviceOperations.reconcile(reconciliation, namespace, connect.getServiceName(), connect.generateService())).compose(i -> generateMetricsAndLoggingConfigMap(reconciliation, namespace, connect)).compose(logAndMetricsConfigMap -> {
        String logging = logAndMetricsConfigMap.getData().get(AbstractModel.ANCILLARY_CM_KEY_LOG_CONFIG);
        annotations.put(Annotations.ANNO_STRIMZI_LOGGING_DYNAMICALLY_UNCHANGEABLE_HASH, Util.hashStub(Util.getLoggingDynamicallyUnmodifiableEntries(logging)));
        desiredLogging.set(logging);
        return configMapOperations.reconcile(reconciliation, namespace, connect.getAncillaryConfigMapName(), logAndMetricsConfigMap);
    }).compose(i -> kafkaConnectJmxSecret(reconciliation, namespace, kafkaConnect.getMetadata().getName(), connect)).compose(i -> pfa.hasPodDisruptionBudgetV1() ? podDisruptionBudgetOperator.reconcile(reconciliation, namespace, connect.getName(), connect.generatePodDisruptionBudget()) : Future.succeededFuture()).compose(i -> !pfa.hasPodDisruptionBudgetV1() ? podDisruptionBudgetV1Beta1Operator.reconcile(reconciliation, namespace, connect.getName(), connect.generatePodDisruptionBudgetV1Beta1()) : Future.succeededFuture()).compose(i -> generateAuthHash(namespace, kafkaConnect.getSpec())).compose(hash -> {
        annotations.put(Annotations.ANNO_STRIMZI_AUTH_HASH, Integer.toString(hash));
        Deployment deployment = generateDeployment(connect, image.get(), annotations);
        return deploymentOperations.reconcile(reconciliation, namespace, connect.getName(), deployment);
    }).compose(i -> deploymentOperations.scaleUp(reconciliation, namespace, connect.getName(), connect.getReplicas())).compose(i -> deploymentOperations.waitForObserved(reconciliation, namespace, connect.getName(), 1_000, operationTimeoutMs)).compose(i -> connectHasZeroReplicas ? Future.succeededFuture() : deploymentOperations.readiness(reconciliation, namespace, connect.getName(), 1_000, operationTimeoutMs)).compose(i -> reconcileConnectors(reconciliation, kafkaConnect, kafkaConnectStatus, connectHasZeroReplicas, desiredLogging.get(), connect.getDefaultLogConfig())).onComplete(reconciliationResult -> {
        StatusUtils.setStatusConditionAndObservedGeneration(kafkaConnect, kafkaConnectStatus, reconciliationResult);
        if (!connectHasZeroReplicas) {
            kafkaConnectStatus.setUrl(KafkaConnectResources.url(connect.getCluster(), namespace, KafkaConnectCluster.REST_API_PORT));
        }
        kafkaConnectStatus.setReplicas(connect.getReplicas());
        kafkaConnectStatus.setLabelSelector(connect.getSelectorLabels().toSelectorString());
        if (reconciliationResult.succeeded()) {
            createOrUpdatePromise.complete(kafkaConnectStatus);
        } else {
            createOrUpdatePromise.fail(new ReconciliationException(kafkaConnectStatus, reconciliationResult.cause()));
        }
    });
    return createOrUpdatePromise.future();
}
Also used : KafkaConnectStatus(io.strimzi.api.kafka.model.status.KafkaConnectStatus) ReconciliationException(io.strimzi.operator.common.ReconciliationException) ClusterRoleBinding(io.fabric8.kubernetes.api.model.rbac.ClusterRoleBinding) LabelSelector(io.fabric8.kubernetes.api.model.LabelSelector) Annotations(io.strimzi.operator.common.Annotations) HashMap(java.util.HashMap) AtomicReference(java.util.concurrent.atomic.AtomicReference) Function(java.util.function.Function) KafkaConnector(io.strimzi.api.kafka.model.KafkaConnector) Resource(io.fabric8.kubernetes.client.dsl.Resource) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) KafkaConnectStatus(io.strimzi.api.kafka.model.status.KafkaConnectStatus) Map(java.util.Map) ResourceOperatorSupplier(io.strimzi.operator.cluster.operator.resource.ResourceOperatorSupplier) ReconciliationException(io.strimzi.operator.common.ReconciliationException) AsyncResult(io.vertx.core.AsyncResult) AbstractModel(io.strimzi.operator.cluster.model.AbstractModel) Operator(io.strimzi.operator.common.Operator) StatusUtils(io.strimzi.operator.common.operator.resource.StatusUtils) KafkaConnect(io.strimzi.api.kafka.model.KafkaConnect) ReconciliationLogger(io.strimzi.operator.common.ReconciliationLogger) CertSecretSource(io.strimzi.api.kafka.model.CertSecretSource) KafkaConnectBuild(io.strimzi.operator.cluster.model.KafkaConnectBuild) DeploymentOperator(io.strimzi.operator.common.operator.resource.DeploymentOperator) Promise(io.vertx.core.Promise) KafkaVersion(io.strimzi.operator.cluster.model.KafkaVersion) Vertx(io.vertx.core.Vertx) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) Set(java.util.Set) Future(io.vertx.core.Future) Collectors(java.util.stream.Collectors) Reconciliation(io.strimzi.operator.common.Reconciliation) NamespaceAndName(io.strimzi.operator.common.model.NamespaceAndName) KafkaConnectCluster(io.strimzi.operator.cluster.model.KafkaConnectCluster) List(java.util.List) Util(io.strimzi.operator.common.Util) Labels(io.strimzi.operator.common.model.Labels) KafkaConnectorStatus(io.strimzi.api.kafka.model.status.KafkaConnectorStatus) KubernetesClient(io.fabric8.kubernetes.client.KubernetesClient) Optional(java.util.Optional) KafkaConnectList(io.strimzi.api.kafka.KafkaConnectList) Handler(io.vertx.core.Handler) LabelSelectorRequirement(io.fabric8.kubernetes.api.model.LabelSelectorRequirement) Deployment(io.fabric8.kubernetes.api.model.apps.Deployment) KafkaConnectSpec(io.strimzi.api.kafka.model.KafkaConnectSpec) KafkaClientAuthentication(io.strimzi.api.kafka.model.authentication.KafkaClientAuthentication) PlatformFeaturesAvailability(io.strimzi.operator.PlatformFeaturesAvailability) Collections(java.util.Collections) ClusterOperatorConfig(io.strimzi.operator.cluster.ClusterOperatorConfig) KafkaConnectResources(io.strimzi.api.kafka.model.KafkaConnectResources) HashMap(java.util.HashMap) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) ClusterRoleBinding(io.fabric8.kubernetes.api.model.rbac.ClusterRoleBinding) Deployment(io.fabric8.kubernetes.api.model.apps.Deployment) KafkaConnectCluster(io.strimzi.operator.cluster.model.KafkaConnectCluster) AtomicReference(java.util.concurrent.atomic.AtomicReference) ReconciliationException(io.strimzi.operator.common.ReconciliationException) KafkaConnectBuild(io.strimzi.operator.cluster.model.KafkaConnectBuild)

Example 10 with ReconciliationException

use of io.strimzi.operator.common.ReconciliationException in project strimzi-kafka-operator by strimzi.

the class KafkaMirrorMakerAssemblyOperator method createOrUpdate.

@Override
protected Future<KafkaMirrorMakerStatus> createOrUpdate(Reconciliation reconciliation, KafkaMirrorMaker assemblyResource) {
    String namespace = reconciliation.namespace();
    KafkaMirrorMakerCluster mirror;
    KafkaMirrorMakerStatus kafkaMirrorMakerStatus = new KafkaMirrorMakerStatus();
    try {
        mirror = KafkaMirrorMakerCluster.fromCrd(reconciliation, assemblyResource, versions);
    } catch (Exception e) {
        LOGGER.warnCr(reconciliation, e);
        StatusUtils.setStatusConditionAndObservedGeneration(assemblyResource, kafkaMirrorMakerStatus, Future.failedFuture(e));
        return Future.failedFuture(new ReconciliationException(kafkaMirrorMakerStatus, e));
    }
    Map<String, String> annotations = new HashMap<>(1);
    KafkaClientAuthentication authConsumer = assemblyResource.getSpec().getConsumer().getAuthentication();
    List<CertSecretSource> trustedCertificatesConsumer = assemblyResource.getSpec().getConsumer().getTls() == null ? Collections.emptyList() : assemblyResource.getSpec().getConsumer().getTls().getTrustedCertificates();
    KafkaClientAuthentication authProducer = assemblyResource.getSpec().getProducer().getAuthentication();
    List<CertSecretSource> trustedCertificatesProducer = assemblyResource.getSpec().getProducer().getTls() == null ? Collections.emptyList() : assemblyResource.getSpec().getProducer().getTls().getTrustedCertificates();
    Promise<KafkaMirrorMakerStatus> createOrUpdatePromise = Promise.promise();
    boolean mirrorHasZeroReplicas = mirror.getReplicas() == 0;
    LOGGER.debugCr(reconciliation, "Updating Kafka Mirror Maker cluster");
    mirrorMakerServiceAccount(reconciliation, namespace, mirror).compose(i -> deploymentOperations.scaleDown(reconciliation, namespace, mirror.getName(), mirror.getReplicas())).compose(i -> Util.metricsAndLogging(reconciliation, configMapOperations, namespace, mirror.getLogging(), mirror.getMetricsConfigInCm())).compose(metricsAndLoggingCm -> {
        ConfigMap logAndMetricsConfigMap = mirror.generateMetricsAndLogConfigMap(metricsAndLoggingCm);
        annotations.put(Annotations.STRIMZI_LOGGING_ANNOTATION, logAndMetricsConfigMap.getData().get(mirror.ANCILLARY_CM_KEY_LOG_CONFIG));
        return configMapOperations.reconcile(reconciliation, namespace, mirror.getAncillaryConfigMapName(), logAndMetricsConfigMap);
    }).compose(i -> pfa.hasPodDisruptionBudgetV1() ? podDisruptionBudgetOperator.reconcile(reconciliation, namespace, mirror.getName(), mirror.generatePodDisruptionBudget()) : Future.succeededFuture()).compose(i -> !pfa.hasPodDisruptionBudgetV1() ? podDisruptionBudgetV1Beta1Operator.reconcile(reconciliation, namespace, mirror.getName(), mirror.generatePodDisruptionBudgetV1Beta1()) : Future.succeededFuture()).compose(i -> CompositeFuture.join(Util.authTlsHash(secretOperations, namespace, authConsumer, trustedCertificatesConsumer), Util.authTlsHash(secretOperations, namespace, authProducer, trustedCertificatesProducer))).compose(hashFut -> {
        if (hashFut != null) {
            annotations.put(Annotations.ANNO_STRIMZI_AUTH_HASH, Integer.toString((int) hashFut.resultAt(0) + (int) hashFut.resultAt(1)));
        }
        return Future.succeededFuture();
    }).compose(i -> deploymentOperations.reconcile(reconciliation, namespace, mirror.getName(), mirror.generateDeployment(annotations, pfa.isOpenshift(), imagePullPolicy, imagePullSecrets))).compose(i -> deploymentOperations.scaleUp(reconciliation, namespace, mirror.getName(), mirror.getReplicas())).compose(i -> deploymentOperations.waitForObserved(reconciliation, namespace, mirror.getName(), 1_000, operationTimeoutMs)).compose(i -> mirrorHasZeroReplicas ? Future.succeededFuture() : deploymentOperations.readiness(reconciliation, namespace, mirror.getName(), 1_000, operationTimeoutMs)).onComplete(reconciliationResult -> {
        StatusUtils.setStatusConditionAndObservedGeneration(assemblyResource, kafkaMirrorMakerStatus, reconciliationResult);
        kafkaMirrorMakerStatus.setReplicas(mirror.getReplicas());
        kafkaMirrorMakerStatus.setLabelSelector(mirror.getSelectorLabels().toSelectorString());
        if (reconciliationResult.succeeded()) {
            createOrUpdatePromise.complete(kafkaMirrorMakerStatus);
        } else {
            createOrUpdatePromise.fail(new ReconciliationException(kafkaMirrorMakerStatus, reconciliationResult.cause()));
        }
    });
    return createOrUpdatePromise.future();
}
Also used : ReconciliationException(io.strimzi.operator.common.ReconciliationException) KafkaMirrorMakerResources(io.strimzi.api.kafka.model.KafkaMirrorMakerResources) KafkaMirrorMakerList(io.strimzi.api.kafka.KafkaMirrorMakerList) CertManager(io.strimzi.certs.CertManager) Annotations(io.strimzi.operator.common.Annotations) HashMap(java.util.HashMap) CompositeFuture(io.vertx.core.CompositeFuture) Resource(io.fabric8.kubernetes.client.dsl.Resource) Map(java.util.Map) KafkaMirrorMakerSpec(io.strimzi.api.kafka.model.KafkaMirrorMakerSpec) ResourceOperatorSupplier(io.strimzi.operator.cluster.operator.resource.ResourceOperatorSupplier) ReconciliationException(io.strimzi.operator.common.ReconciliationException) ReconcileResult(io.strimzi.operator.common.operator.resource.ReconcileResult) StatusUtils(io.strimzi.operator.common.operator.resource.StatusUtils) ReconciliationLogger(io.strimzi.operator.common.ReconciliationLogger) CertSecretSource(io.strimzi.api.kafka.model.CertSecretSource) KafkaMirrorMaker(io.strimzi.api.kafka.model.KafkaMirrorMaker) DeploymentOperator(io.strimzi.operator.common.operator.resource.DeploymentOperator) Promise(io.vertx.core.Promise) KafkaVersion(io.strimzi.operator.cluster.model.KafkaVersion) Vertx(io.vertx.core.Vertx) Future(io.vertx.core.Future) ConfigMap(io.fabric8.kubernetes.api.model.ConfigMap) Reconciliation(io.strimzi.operator.common.Reconciliation) List(java.util.List) Util(io.strimzi.operator.common.Util) PasswordGenerator(io.strimzi.operator.common.PasswordGenerator) KubernetesClient(io.fabric8.kubernetes.client.KubernetesClient) KafkaMirrorMakerCluster(io.strimzi.operator.cluster.model.KafkaMirrorMakerCluster) KafkaMirrorMakerStatus(io.strimzi.api.kafka.model.status.KafkaMirrorMakerStatus) ServiceAccount(io.fabric8.kubernetes.api.model.ServiceAccount) KafkaClientAuthentication(io.strimzi.api.kafka.model.authentication.KafkaClientAuthentication) PlatformFeaturesAvailability(io.strimzi.operator.PlatformFeaturesAvailability) Collections(java.util.Collections) ClusterOperatorConfig(io.strimzi.operator.cluster.ClusterOperatorConfig) KafkaMirrorMakerStatus(io.strimzi.api.kafka.model.status.KafkaMirrorMakerStatus) ConfigMap(io.fabric8.kubernetes.api.model.ConfigMap) HashMap(java.util.HashMap) KafkaMirrorMakerCluster(io.strimzi.operator.cluster.model.KafkaMirrorMakerCluster) ReconciliationException(io.strimzi.operator.common.ReconciliationException) KafkaClientAuthentication(io.strimzi.api.kafka.model.authentication.KafkaClientAuthentication) CertSecretSource(io.strimzi.api.kafka.model.CertSecretSource)

Aggregations

ReconciliationException (io.strimzi.operator.common.ReconciliationException)12 KubernetesClient (io.fabric8.kubernetes.client.KubernetesClient)10 Reconciliation (io.strimzi.operator.common.Reconciliation)10 ReconciliationLogger (io.strimzi.operator.common.ReconciliationLogger)10 StatusUtils (io.strimzi.operator.common.operator.resource.StatusUtils)10 Future (io.vertx.core.Future)10 Promise (io.vertx.core.Promise)10 Vertx (io.vertx.core.Vertx)10 List (java.util.List)10 Resource (io.fabric8.kubernetes.client.dsl.Resource)8 CertSecretSource (io.strimzi.api.kafka.model.CertSecretSource)8 PlatformFeaturesAvailability (io.strimzi.operator.PlatformFeaturesAvailability)8 ClusterOperatorConfig (io.strimzi.operator.cluster.ClusterOperatorConfig)8 KafkaVersion (io.strimzi.operator.cluster.model.KafkaVersion)8 ResourceOperatorSupplier (io.strimzi.operator.cluster.operator.resource.ResourceOperatorSupplier)8 Annotations (io.strimzi.operator.common.Annotations)8 Util (io.strimzi.operator.common.Util)8 DeploymentOperator (io.strimzi.operator.common.operator.resource.DeploymentOperator)8 Collections (java.util.Collections)8 KafkaClientAuthentication (io.strimzi.api.kafka.model.authentication.KafkaClientAuthentication)6