Search in sources :

Example 6 with StatefulSet

use of io.fabric8.kubernetes.api.model.extensions.StatefulSet in project strimzi by strimzi.

the class KafkaCluster method fromAssembly.

/**
 * Create a Kafka cluster from the deployed StatefulSet resource
 *
 * @param ss The StatefulSet from which the cluster state should be recovered.
 * @param namespace Kubernetes/OpenShift namespace where cluster resources belong to
 * @param cluster   overall cluster name
 * @return  Kafka cluster instance
 */
public static KafkaCluster fromAssembly(StatefulSet ss, String namespace, String cluster) {
    KafkaCluster kafka = new KafkaCluster(namespace, cluster, Labels.fromResource(ss));
    kafka.setReplicas(ss.getSpec().getReplicas());
    Container container = ss.getSpec().getTemplate().getSpec().getContainers().get(0);
    kafka.setImage(container.getImage());
    kafka.setHealthCheckInitialDelay(container.getReadinessProbe().getInitialDelaySeconds());
    kafka.setHealthCheckTimeout(container.getReadinessProbe().getTimeoutSeconds());
    Map<String, String> vars = containerEnvVars(container);
    kafka.setZookeeperConnect(vars.getOrDefault(KEY_KAFKA_ZOOKEEPER_CONNECT, ss.getMetadata().getName() + "-zookeeper:2181"));
    kafka.setDefaultReplicationFactor(Integer.parseInt(vars.getOrDefault(KEY_KAFKA_DEFAULT_REPLICATION_FACTOR, String.valueOf(DEFAULT_KAFKA_DEFAULT_REPLICATION_FACTOR))));
    kafka.setOffsetsTopicReplicationFactor(Integer.parseInt(vars.getOrDefault(KEY_KAFKA_OFFSETS_TOPIC_REPLICATION_FACTOR, String.valueOf(DEFAULT_KAFKA_OFFSETS_TOPIC_REPLICATION_FACTOR))));
    kafka.setTransactionStateLogReplicationFactor(Integer.parseInt(vars.getOrDefault(KEY_KAFKA_TRANSACTION_STATE_LOG_REPLICATION_FACTOR, String.valueOf(DEFAULT_KAFKA_TRANSACTION_STATE_LOG_REPLICATION_FACTOR))));
    kafka.setMetricsEnabled(Boolean.parseBoolean(vars.getOrDefault(KEY_KAFKA_METRICS_ENABLED, String.valueOf(DEFAULT_KAFKA_METRICS_ENABLED))));
    if (kafka.isMetricsEnabled()) {
        kafka.setMetricsConfigName(metricConfigsName(cluster));
    }
    if (!ss.getSpec().getVolumeClaimTemplates().isEmpty()) {
        Storage storage = Storage.fromPersistentVolumeClaim(ss.getSpec().getVolumeClaimTemplates().get(0));
        if (ss.getMetadata().getAnnotations() != null) {
            String deleteClaimAnnotation = String.format("%s/%s", ClusterController.STRIMZI_CLUSTER_CONTROLLER_DOMAIN, Storage.DELETE_CLAIM_FIELD);
            storage.withDeleteClaim(Boolean.valueOf(ss.getMetadata().getAnnotations().computeIfAbsent(deleteClaimAnnotation, s -> "false")));
        }
        kafka.setStorage(storage);
    } else {
        Storage storage = new Storage(Storage.StorageType.EPHEMERAL);
        kafka.setStorage(storage);
    }
    return kafka;
}
Also used : Container(io.fabric8.kubernetes.api.model.Container)

Example 7 with StatefulSet

use of io.fabric8.kubernetes.api.model.extensions.StatefulSet in project strimzi by strimzi.

the class KafkaAssemblyOperator method createOrUpdateKafka.

private final Future<Void> createOrUpdateKafka(Reconciliation reconciliation, ConfigMap assemblyCm) {
    String namespace = assemblyCm.getMetadata().getNamespace();
    String name = assemblyCm.getMetadata().getName();
    log.info("{}: create/update kafka {}", reconciliation, name);
    KafkaCluster kafka = KafkaCluster.fromConfigMap(assemblyCm);
    Service service = kafka.generateService();
    Service headlessService = kafka.generateHeadlessService();
    ConfigMap metricsConfigMap = kafka.generateMetricsConfigMap();
    StatefulSet statefulSet = kafka.generateStatefulSet(isOpenShift);
    Future<Void> chainFuture = Future.future();
    kafkaSetOperations.scaleDown(namespace, kafka.getName(), kafka.getReplicas()).compose(scale -> serviceOperations.reconcile(namespace, kafka.getName(), service)).compose(i -> serviceOperations.reconcile(namespace, kafka.getHeadlessName(), headlessService)).compose(i -> configMapOperations.reconcile(namespace, kafka.getMetricsConfigName(), metricsConfigMap)).compose(i -> kafkaSetOperations.reconcile(namespace, kafka.getName(), statefulSet)).compose(diffs -> {
        if (diffs instanceof ReconcileResult.Patched && ((ReconcileResult.Patched<Boolean>) diffs).differences()) {
            return kafkaSetOperations.rollingUpdate(namespace, kafka.getName());
        } else {
            return Future.succeededFuture();
        }
    }).compose(i -> kafkaSetOperations.scaleUp(namespace, kafka.getName(), kafka.getReplicas())).compose(scale -> serviceOperations.endpointReadiness(namespace, service, 1_000, operationTimeoutMs)).compose(i -> serviceOperations.endpointReadiness(namespace, headlessService, 1_000, operationTimeoutMs)).compose(chainFuture::complete, chainFuture);
    return chainFuture;
}
Also used : PvcOperator(io.strimzi.controller.cluster.operator.resource.PvcOperator) TopicController.topicControllerName(io.strimzi.controller.cluster.model.TopicController.topicControllerName) KafkaSetOperator(io.strimzi.controller.cluster.operator.resource.KafkaSetOperator) ZookeeperCluster(io.strimzi.controller.cluster.model.ZookeeperCluster) Deployment(io.fabric8.kubernetes.api.model.extensions.Deployment) ZookeeperSetOperator(io.strimzi.controller.cluster.operator.resource.ZookeeperSetOperator) LoggerFactory(org.slf4j.LoggerFactory) ConfigMapOperator(io.strimzi.controller.cluster.operator.resource.ConfigMapOperator) Storage(io.strimzi.controller.cluster.model.Storage) Labels(io.strimzi.controller.cluster.model.Labels) ArrayList(java.util.ArrayList) CompositeFuture(io.vertx.core.CompositeFuture) Reconciliation(io.strimzi.controller.cluster.Reconciliation) DeploymentOperator(io.strimzi.controller.cluster.operator.resource.DeploymentOperator) KafkaCluster(io.strimzi.controller.cluster.model.KafkaCluster) Service(io.fabric8.kubernetes.api.model.Service) AsyncResult(io.vertx.core.AsyncResult) AssemblyType(io.strimzi.controller.cluster.model.AssemblyType) Logger(org.slf4j.Logger) StatefulSet(io.fabric8.kubernetes.api.model.extensions.StatefulSet) Vertx(io.vertx.core.Vertx) ServiceOperator(io.strimzi.controller.cluster.operator.resource.ServiceOperator) TopicController(io.strimzi.controller.cluster.model.TopicController) ReconcileResult(io.strimzi.controller.cluster.operator.resource.ReconcileResult) HasMetadata(io.fabric8.kubernetes.api.model.HasMetadata) Future(io.vertx.core.Future) ConfigMap(io.fabric8.kubernetes.api.model.ConfigMap) List(java.util.List) Handler(io.vertx.core.Handler) KafkaCluster(io.strimzi.controller.cluster.model.KafkaCluster) ConfigMap(io.fabric8.kubernetes.api.model.ConfigMap) ReconcileResult(io.strimzi.controller.cluster.operator.resource.ReconcileResult) Service(io.fabric8.kubernetes.api.model.Service) StatefulSet(io.fabric8.kubernetes.api.model.extensions.StatefulSet)

Example 8 with StatefulSet

use of io.fabric8.kubernetes.api.model.extensions.StatefulSet in project strimzi by strimzi.

the class KafkaAssemblyOperator method deleteZk.

private final Future<CompositeFuture> deleteZk(Reconciliation reconciliation) {
    String namespace = reconciliation.namespace();
    String name = reconciliation.assemblyName();
    log.info("{}: delete zookeeper {}", reconciliation, name);
    StatefulSet ss = zkSetOperations.get(namespace, ZookeeperCluster.zookeeperClusterName(name));
    ZookeeperCluster zk = ss == null ? null : ZookeeperCluster.fromAssembly(ss, namespace, name);
    boolean deleteClaims = zk != null && zk.getStorage().type() == Storage.StorageType.PERSISTENT_CLAIM && zk.getStorage().isDeleteClaim();
    List<Future> result = new ArrayList<>(4 + (deleteClaims ? zk.getReplicas() : 0));
    result.add(configMapOperations.reconcile(namespace, ZookeeperCluster.zookeeperMetricsName(name), null));
    result.add(serviceOperations.reconcile(namespace, ZookeeperCluster.zookeeperClusterName(name), null));
    result.add(serviceOperations.reconcile(namespace, ZookeeperCluster.zookeeperHeadlessName(name), null));
    result.add(zkSetOperations.reconcile(namespace, ZookeeperCluster.zookeeperClusterName(name), null));
    if (deleteClaims) {
        for (int i = 0; i < zk.getReplicas(); i++) {
            result.add(pvcOperations.reconcile(namespace, zk.getPersistentVolumeClaimName(i), null));
        }
    }
    return CompositeFuture.join(result);
}
Also used : ArrayList(java.util.ArrayList) CompositeFuture(io.vertx.core.CompositeFuture) Future(io.vertx.core.Future) ZookeeperCluster(io.strimzi.controller.cluster.model.ZookeeperCluster) StatefulSet(io.fabric8.kubernetes.api.model.extensions.StatefulSet)

Example 9 with StatefulSet

use of io.fabric8.kubernetes.api.model.extensions.StatefulSet in project strimzi by strimzi.

the class KafkaClusterTest method testGenerateStatefulSet.

@Test
public void testGenerateStatefulSet() {
    // We expect a single statefulSet ...
    StatefulSet ss = kc.generateStatefulSet(true);
    checkStatefulSet(ss);
}
Also used : StatefulSet(io.fabric8.kubernetes.api.model.extensions.StatefulSet) Test(org.junit.Test)

Example 10 with StatefulSet

use of io.fabric8.kubernetes.api.model.extensions.StatefulSet in project strimzi by strimzi.

the class KafkaAssemblyOperatorMockIT method assertStorageClass.

private void assertStorageClass(TestContext context, String statefulSetName, String expectedClass) {
    StatefulSet statefulSet = mockClient.apps().statefulSets().inNamespace(NAMESPACE).withName(statefulSetName).get();
    context.assertNotNull(statefulSet);
    // Check the storage class is initially "foo"
    List<PersistentVolumeClaim> volumeClaimTemplates = statefulSet.getSpec().getVolumeClaimTemplates();
    context.assertFalse(volumeClaimTemplates.isEmpty());
    context.assertEquals(expectedClass, volumeClaimTemplates.get(0).getSpec().getStorageClassName());
}
Also used : PersistentVolumeClaim(io.fabric8.kubernetes.api.model.PersistentVolumeClaim) StatefulSet(io.fabric8.kubernetes.api.model.extensions.StatefulSet)

Aggregations

StatefulSet (io.fabric8.kubernetes.api.model.extensions.StatefulSet)15 ConfigMap (io.fabric8.kubernetes.api.model.ConfigMap)8 Deployment (io.fabric8.kubernetes.api.model.extensions.Deployment)8 Service (io.fabric8.kubernetes.api.model.Service)6 PersistentVolumeClaim (io.fabric8.kubernetes.api.model.PersistentVolumeClaim)5 Reconciliation (io.strimzi.controller.cluster.Reconciliation)5 KafkaCluster (io.strimzi.controller.cluster.model.KafkaCluster)5 ConfigMapOperator (io.strimzi.controller.cluster.operator.resource.ConfigMapOperator)5 DeploymentOperator (io.strimzi.controller.cluster.operator.resource.DeploymentOperator)5 KafkaSetOperator (io.strimzi.controller.cluster.operator.resource.KafkaSetOperator)5 PvcOperator (io.strimzi.controller.cluster.operator.resource.PvcOperator)5 ServiceOperator (io.strimzi.controller.cluster.operator.resource.ServiceOperator)5 ZookeeperSetOperator (io.strimzi.controller.cluster.operator.resource.ZookeeperSetOperator)5 ArrayList (java.util.ArrayList)5 Pod (io.fabric8.kubernetes.api.model.Pod)4 TopicController (io.strimzi.controller.cluster.model.TopicController)4 ZookeeperCluster (io.strimzi.controller.cluster.model.ZookeeperCluster)4 HasMetadata (io.fabric8.kubernetes.api.model.HasMetadata)3 ReplicationController (io.fabric8.kubernetes.api.model.ReplicationController)3 DaemonSet (io.fabric8.kubernetes.api.model.extensions.DaemonSet)3