Search in sources :

Example 1 with ZooKeeperRoller

use of io.strimzi.operator.cluster.operator.resource.ZooKeeperRoller in project strimzi by strimzi.

the class CaReconciler method rollingUpdateForNewCaKey.

/**
 * Perform a rolling update of the cluster so that CA certificates get added to their truststores, or expired CA
 * certificates get removed from their truststores. Note this is only necessary when the CA certificate has changed
 * due to a new CA key. It is not necessary when the CA certificate is replace while retaining the existing key.
 */
Future<Void> rollingUpdateForNewCaKey() {
    List<String> reason = new ArrayList<>(2);
    if (clusterCa.keyReplaced()) {
        reason.add("trust new cluster CA certificate signed by new key");
    }
    if (clientsCa.keyReplaced()) {
        reason.add("trust new clients CA certificate signed by new key");
    }
    if (!reason.isEmpty()) {
        Future<Void> zkRollFuture;
        Function<Pod, List<String>> rollPodAndLogReason = pod -> {
            LOGGER.debugCr(reconciliation, "Rolling Pod {} to {}", pod.getMetadata().getName(), reason);
            return reason;
        };
        if (clusterCa.keyReplaced()) {
            // ZooKeeper is rolled only for new Cluster CA key
            Labels zkSelectorLabels = Labels.EMPTY.withStrimziKind(reconciliation.kind()).withStrimziCluster(reconciliation.name()).withStrimziName(KafkaResources.zookeeperStatefulSetName(reconciliation.name()));
            zkRollFuture = new ZooKeeperRoller(podOperator, zookeeperLeaderFinder, operationTimeoutMs).maybeRollingUpdate(reconciliation, zkSelectorLabels, rollPodAndLogReason, clusterCa.caCertSecret(), oldCoSecret);
        } else {
            zkRollFuture = Future.succeededFuture();
        }
        return zkRollFuture.compose(i -> {
            if (featureGates.useStrimziPodSetsEnabled()) {
                return strimziPodSetOperator.getAsync(reconciliation.namespace(), KafkaResources.kafkaStatefulSetName(reconciliation.name())).compose(podSet -> {
                    if (podSet != null) {
                        return Future.succeededFuture(KafkaCluster.generatePodList(reconciliation.name(), podSet.getSpec().getPods().size()));
                    } else {
                        return Future.succeededFuture(List.<String>of());
                    }
                });
            } else {
                return stsOperator.getAsync(reconciliation.namespace(), KafkaResources.kafkaStatefulSetName(reconciliation.name())).compose(sts -> {
                    if (sts != null) {
                        return Future.succeededFuture(KafkaCluster.generatePodList(reconciliation.name(), sts.getSpec().getReplicas()));
                    } else {
                        return Future.succeededFuture(List.<String>of());
                    }
                });
            }
        }).compose(replicas -> new KafkaRoller(reconciliation, vertx, podOperator, 1_000, operationTimeoutMs, () -> new BackOff(250, 2, 10), replicas, clusterCa.caCertSecret(), oldCoSecret, adminClientProvider, brokerId -> null, null, null, false).rollingRestart(rollPodAndLogReason)).compose(i -> {
            if (clusterCa.keyReplaced()) {
                // EO, KE and CC need to be rolled only for new Cluster CA key.
                return rollDeploymentIfExists(KafkaResources.entityOperatorDeploymentName(reconciliation.name()), reason.toString()).compose(i2 -> rollDeploymentIfExists(KafkaExporterResources.deploymentName(reconciliation.name()), reason.toString())).compose(i2 -> rollDeploymentIfExists(CruiseControlResources.deploymentName(reconciliation.name()), reason.toString()));
            } else {
                return Future.succeededFuture();
            }
        });
    } else {
        return Future.succeededFuture();
    }
}
Also used : BackOff(io.strimzi.operator.common.BackOff) KafkaExporterResources(io.strimzi.api.kafka.model.KafkaExporterResources) StrimziPodSetOperator(io.strimzi.operator.common.operator.resource.StrimziPodSetOperator) Date(java.util.Date) CertManager(io.strimzi.certs.CertManager) Annotations(io.strimzi.operator.common.Annotations) OwnerReference(io.fabric8.kubernetes.api.model.OwnerReference) Function(java.util.function.Function) Supplier(java.util.function.Supplier) FeatureGates(io.strimzi.operator.cluster.FeatureGates) ArrayList(java.util.ArrayList) CompositeFuture(io.vertx.core.CompositeFuture) KafkaCluster(io.strimzi.operator.cluster.model.KafkaCluster) KafkaResources(io.strimzi.api.kafka.model.KafkaResources) ClusterOperator(io.strimzi.operator.cluster.ClusterOperator) Ca(io.strimzi.operator.cluster.model.Ca) Map(java.util.Map) ZookeeperLeaderFinder(io.strimzi.operator.cluster.operator.resource.ZookeeperLeaderFinder) PodOperator(io.strimzi.operator.common.operator.resource.PodOperator) KafkaRoller(io.strimzi.operator.cluster.operator.resource.KafkaRoller) ResourceOperatorSupplier(io.strimzi.operator.cluster.operator.resource.ResourceOperatorSupplier) ReconcileResult(io.strimzi.operator.common.operator.resource.ReconcileResult) AbstractModel(io.strimzi.operator.cluster.model.AbstractModel) StatefulSetOperator(io.strimzi.operator.cluster.operator.resource.StatefulSetOperator) ModelUtils(io.strimzi.operator.cluster.model.ModelUtils) ReconciliationLogger(io.strimzi.operator.common.ReconciliationLogger) CertificateAuthority(io.strimzi.api.kafka.model.CertificateAuthority) OwnerReferenceBuilder(io.fabric8.kubernetes.api.model.OwnerReferenceBuilder) InvalidResourceException(io.strimzi.operator.cluster.model.InvalidResourceException) DeploymentOperator(io.strimzi.operator.common.operator.resource.DeploymentOperator) Promise(io.vertx.core.Promise) Vertx(io.vertx.core.Vertx) Pod(io.fabric8.kubernetes.api.model.Pod) SecretOperator(io.strimzi.operator.common.operator.resource.SecretOperator) ClientsCa(io.strimzi.operator.cluster.model.ClientsCa) ZooKeeperRoller(io.strimzi.operator.cluster.operator.resource.ZooKeeperRoller) Future(io.vertx.core.Future) CruiseControlResources(io.strimzi.api.kafka.model.CruiseControlResources) Reconciliation(io.strimzi.operator.common.Reconciliation) List(java.util.List) Util(io.strimzi.operator.common.Util) Labels(io.strimzi.operator.common.model.Labels) PasswordGenerator(io.strimzi.operator.common.PasswordGenerator) Secret(io.fabric8.kubernetes.api.model.Secret) AdminClientProvider(io.strimzi.operator.common.AdminClientProvider) Kafka(io.strimzi.api.kafka.model.Kafka) ClusterCa(io.strimzi.operator.cluster.model.ClusterCa) ClusterOperatorConfig(io.strimzi.operator.cluster.ClusterOperatorConfig) Pod(io.fabric8.kubernetes.api.model.Pod) ArrayList(java.util.ArrayList) Labels(io.strimzi.operator.common.model.Labels) BackOff(io.strimzi.operator.common.BackOff) ZooKeeperRoller(io.strimzi.operator.cluster.operator.resource.ZooKeeperRoller) ArrayList(java.util.ArrayList) List(java.util.List) KafkaRoller(io.strimzi.operator.cluster.operator.resource.KafkaRoller)

Example 2 with ZooKeeperRoller

use of io.strimzi.operator.cluster.operator.resource.ZooKeeperRoller in project strimzi-kafka-operator by strimzi.

the class CaReconciler method rollingUpdateForNewCaKey.

/**
 * Perform a rolling update of the cluster so that CA certificates get added to their truststores, or expired CA
 * certificates get removed from their truststores. Note this is only necessary when the CA certificate has changed
 * due to a new CA key. It is not necessary when the CA certificate is replace while retaining the existing key.
 */
Future<Void> rollingUpdateForNewCaKey() {
    List<String> reason = new ArrayList<>(2);
    if (clusterCa.keyReplaced()) {
        reason.add("trust new cluster CA certificate signed by new key");
    }
    if (clientsCa.keyReplaced()) {
        reason.add("trust new clients CA certificate signed by new key");
    }
    if (!reason.isEmpty()) {
        Future<Void> zkRollFuture;
        Function<Pod, List<String>> rollPodAndLogReason = pod -> {
            LOGGER.debugCr(reconciliation, "Rolling Pod {} to {}", pod.getMetadata().getName(), reason);
            return reason;
        };
        if (clusterCa.keyReplaced()) {
            // ZooKeeper is rolled only for new Cluster CA key
            Labels zkSelectorLabels = Labels.EMPTY.withStrimziKind(reconciliation.kind()).withStrimziCluster(reconciliation.name()).withStrimziName(KafkaResources.zookeeperStatefulSetName(reconciliation.name()));
            zkRollFuture = new ZooKeeperRoller(podOperator, zookeeperLeaderFinder, operationTimeoutMs).maybeRollingUpdate(reconciliation, zkSelectorLabels, rollPodAndLogReason, clusterCa.caCertSecret(), oldCoSecret);
        } else {
            zkRollFuture = Future.succeededFuture();
        }
        return zkRollFuture.compose(i -> {
            if (featureGates.useStrimziPodSetsEnabled()) {
                return strimziPodSetOperator.getAsync(reconciliation.namespace(), KafkaResources.kafkaStatefulSetName(reconciliation.name())).compose(podSet -> {
                    if (podSet != null) {
                        return Future.succeededFuture(KafkaCluster.generatePodList(reconciliation.name(), podSet.getSpec().getPods().size()));
                    } else {
                        return Future.succeededFuture(List.<String>of());
                    }
                });
            } else {
                return stsOperator.getAsync(reconciliation.namespace(), KafkaResources.kafkaStatefulSetName(reconciliation.name())).compose(sts -> {
                    if (sts != null) {
                        return Future.succeededFuture(KafkaCluster.generatePodList(reconciliation.name(), sts.getSpec().getReplicas()));
                    } else {
                        return Future.succeededFuture(List.<String>of());
                    }
                });
            }
        }).compose(replicas -> new KafkaRoller(reconciliation, vertx, podOperator, 1_000, operationTimeoutMs, () -> new BackOff(250, 2, 10), replicas, clusterCa.caCertSecret(), oldCoSecret, adminClientProvider, brokerId -> null, null, null, false).rollingRestart(rollPodAndLogReason)).compose(i -> {
            if (clusterCa.keyReplaced()) {
                // EO, KE and CC need to be rolled only for new Cluster CA key.
                return rollDeploymentIfExists(KafkaResources.entityOperatorDeploymentName(reconciliation.name()), reason.toString()).compose(i2 -> rollDeploymentIfExists(KafkaExporterResources.deploymentName(reconciliation.name()), reason.toString())).compose(i2 -> rollDeploymentIfExists(CruiseControlResources.deploymentName(reconciliation.name()), reason.toString()));
            } else {
                return Future.succeededFuture();
            }
        });
    } else {
        return Future.succeededFuture();
    }
}
Also used : BackOff(io.strimzi.operator.common.BackOff) KafkaExporterResources(io.strimzi.api.kafka.model.KafkaExporterResources) StrimziPodSetOperator(io.strimzi.operator.common.operator.resource.StrimziPodSetOperator) Date(java.util.Date) CertManager(io.strimzi.certs.CertManager) Annotations(io.strimzi.operator.common.Annotations) OwnerReference(io.fabric8.kubernetes.api.model.OwnerReference) Function(java.util.function.Function) Supplier(java.util.function.Supplier) FeatureGates(io.strimzi.operator.cluster.FeatureGates) ArrayList(java.util.ArrayList) CompositeFuture(io.vertx.core.CompositeFuture) KafkaCluster(io.strimzi.operator.cluster.model.KafkaCluster) KafkaResources(io.strimzi.api.kafka.model.KafkaResources) ClusterOperator(io.strimzi.operator.cluster.ClusterOperator) Ca(io.strimzi.operator.cluster.model.Ca) Map(java.util.Map) ZookeeperLeaderFinder(io.strimzi.operator.cluster.operator.resource.ZookeeperLeaderFinder) PodOperator(io.strimzi.operator.common.operator.resource.PodOperator) KafkaRoller(io.strimzi.operator.cluster.operator.resource.KafkaRoller) ResourceOperatorSupplier(io.strimzi.operator.cluster.operator.resource.ResourceOperatorSupplier) ReconcileResult(io.strimzi.operator.common.operator.resource.ReconcileResult) AbstractModel(io.strimzi.operator.cluster.model.AbstractModel) StatefulSetOperator(io.strimzi.operator.cluster.operator.resource.StatefulSetOperator) ModelUtils(io.strimzi.operator.cluster.model.ModelUtils) ReconciliationLogger(io.strimzi.operator.common.ReconciliationLogger) CertificateAuthority(io.strimzi.api.kafka.model.CertificateAuthority) OwnerReferenceBuilder(io.fabric8.kubernetes.api.model.OwnerReferenceBuilder) InvalidResourceException(io.strimzi.operator.cluster.model.InvalidResourceException) DeploymentOperator(io.strimzi.operator.common.operator.resource.DeploymentOperator) Promise(io.vertx.core.Promise) Vertx(io.vertx.core.Vertx) Pod(io.fabric8.kubernetes.api.model.Pod) SecretOperator(io.strimzi.operator.common.operator.resource.SecretOperator) ClientsCa(io.strimzi.operator.cluster.model.ClientsCa) ZooKeeperRoller(io.strimzi.operator.cluster.operator.resource.ZooKeeperRoller) Future(io.vertx.core.Future) CruiseControlResources(io.strimzi.api.kafka.model.CruiseControlResources) Reconciliation(io.strimzi.operator.common.Reconciliation) List(java.util.List) Util(io.strimzi.operator.common.Util) Labels(io.strimzi.operator.common.model.Labels) PasswordGenerator(io.strimzi.operator.common.PasswordGenerator) Secret(io.fabric8.kubernetes.api.model.Secret) AdminClientProvider(io.strimzi.operator.common.AdminClientProvider) Kafka(io.strimzi.api.kafka.model.Kafka) ClusterCa(io.strimzi.operator.cluster.model.ClusterCa) ClusterOperatorConfig(io.strimzi.operator.cluster.ClusterOperatorConfig) Pod(io.fabric8.kubernetes.api.model.Pod) ArrayList(java.util.ArrayList) Labels(io.strimzi.operator.common.model.Labels) BackOff(io.strimzi.operator.common.BackOff) ZooKeeperRoller(io.strimzi.operator.cluster.operator.resource.ZooKeeperRoller) ArrayList(java.util.ArrayList) List(java.util.List) KafkaRoller(io.strimzi.operator.cluster.operator.resource.KafkaRoller)

Aggregations

OwnerReference (io.fabric8.kubernetes.api.model.OwnerReference)2 OwnerReferenceBuilder (io.fabric8.kubernetes.api.model.OwnerReferenceBuilder)2 Pod (io.fabric8.kubernetes.api.model.Pod)2 Secret (io.fabric8.kubernetes.api.model.Secret)2 CertificateAuthority (io.strimzi.api.kafka.model.CertificateAuthority)2 CruiseControlResources (io.strimzi.api.kafka.model.CruiseControlResources)2 Kafka (io.strimzi.api.kafka.model.Kafka)2 KafkaExporterResources (io.strimzi.api.kafka.model.KafkaExporterResources)2 KafkaResources (io.strimzi.api.kafka.model.KafkaResources)2 CertManager (io.strimzi.certs.CertManager)2 ClusterOperator (io.strimzi.operator.cluster.ClusterOperator)2 ClusterOperatorConfig (io.strimzi.operator.cluster.ClusterOperatorConfig)2 FeatureGates (io.strimzi.operator.cluster.FeatureGates)2 AbstractModel (io.strimzi.operator.cluster.model.AbstractModel)2 Ca (io.strimzi.operator.cluster.model.Ca)2 ClientsCa (io.strimzi.operator.cluster.model.ClientsCa)2 ClusterCa (io.strimzi.operator.cluster.model.ClusterCa)2 InvalidResourceException (io.strimzi.operator.cluster.model.InvalidResourceException)2 KafkaCluster (io.strimzi.operator.cluster.model.KafkaCluster)2 ModelUtils (io.strimzi.operator.cluster.model.ModelUtils)2