Search in sources :

Example 61 with Namespace

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

the class KafkaConnectS2ICluster method generateBuildConfig.

/**
 * Generate new BuildConfig
 *
 * @return      BuildConfig resource definition
 */
public BuildConfig generateBuildConfig() {
    BuildTriggerPolicy triggerConfigChange = new BuildTriggerPolicy();
    triggerConfigChange.setType("ConfigChange");
    BuildTriggerPolicy triggerImageChange = new BuildTriggerPolicy();
    triggerImageChange.setType("ImageChange");
    triggerImageChange.setImageChange(new ImageChangeTrigger());
    BuildConfig build = new BuildConfigBuilder().withNewMetadata().withName(name).withLabels(getLabelsWithName()).withNamespace(namespace).endMetadata().withNewSpec().withFailedBuildsHistoryLimit(5).withNewOutput().withNewTo().withKind("ImageStreamTag").withName(image).endTo().endOutput().withRunPolicy("Serial").withNewSource().withType("Binary").withBinary(new BinaryBuildSource()).endSource().withNewStrategy().withType("Source").withNewSourceStrategy().withNewFrom().withKind("ImageStreamTag").withName(getSourceImageStreamName() + ":" + sourceImageTag).endFrom().endSourceStrategy().endStrategy().withTriggers(triggerConfigChange, triggerImageChange).endSpec().build();
    return build;
}
Also used : BinaryBuildSource(io.fabric8.openshift.api.model.BinaryBuildSource) BuildConfig(io.fabric8.openshift.api.model.BuildConfig) ImageChangeTrigger(io.fabric8.openshift.api.model.ImageChangeTrigger) BuildConfigBuilder(io.fabric8.openshift.api.model.BuildConfigBuilder) BuildTriggerPolicy(io.fabric8.openshift.api.model.BuildTriggerPolicy)

Example 62 with Namespace

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

the class AbstractAssemblyOperator method reconcileAssembly.

/**
 * Reconcile assembly resources in the given namespace having the given {@code assemblyName}.
 * Reconciliation works by getting the assembly ConfigMap in the given namespace with the given assemblyName and
 * comparing with the corresponding {@linkplain #getResources(String) resource}.
 * <ul>
 * <li>An assembly will be {@linkplain #createOrUpdate(Reconciliation, ConfigMap, Handler) created or updated} if ConfigMap is without same-named resources</li>
 * <li>An assembly will be {@linkplain #delete(Reconciliation, Handler) deleted} if resources without same-named ConfigMap</li>
 * </ul>
 */
public final void reconcileAssembly(Reconciliation reconciliation, Handler<AsyncResult<Void>> handler) {
    String namespace = reconciliation.namespace();
    String assemblyName = reconciliation.assemblyName();
    final String lockName = getLockName(assemblyType, namespace, assemblyName);
    vertx.sharedData().getLockWithTimeout(lockName, LOCK_TIMEOUT, res -> {
        if (res.succeeded()) {
            log.debug("{}: Lock {} acquired", reconciliation, lockName);
            Lock lock = res.result();
            try {
                // get ConfigMap and related resources for the specific cluster
                ConfigMap cm = configMapOperations.get(namespace, assemblyName);
                if (cm != null) {
                    log.info("{}: assembly {} should be created or updated", reconciliation, assemblyName);
                    createOrUpdate(reconciliation, cm, createResult -> {
                        lock.release();
                        log.debug("{}: Lock {} released", reconciliation, lockName);
                        handler.handle(createResult);
                    });
                } else {
                    log.info("{}: assembly {} should be deleted", reconciliation, assemblyName);
                    delete(reconciliation, deleteResult -> {
                        lock.release();
                        log.debug("{}: Lock {} released", reconciliation, lockName);
                        handler.handle(deleteResult);
                    });
                }
            } catch (Throwable ex) {
                lock.release();
                log.debug("{}: Lock {} released", reconciliation, lockName);
                handler.handle(Future.failedFuture(ex));
            }
        } else {
            log.warn("{}: Failed to acquire lock {}.", reconciliation, lockName);
        }
    });
}
Also used : ConfigMap(io.fabric8.kubernetes.api.model.ConfigMap) Lock(io.vertx.core.shareddata.Lock)

Example 63 with Namespace

use of io.fabric8.kubernetes.api.model.Namespace 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 64 with Namespace

use of io.fabric8.kubernetes.api.model.Namespace 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 65 with Namespace

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

the class KafkaAssemblyOperator method createOrUpdateTopicController.

private final Future<ReconcileResult<Void>> createOrUpdateTopicController(Reconciliation reconciliation, ConfigMap assemblyCm) {
    String namespace = assemblyCm.getMetadata().getNamespace();
    String name = assemblyCm.getMetadata().getName();
    log.info("{}: create/update topic controller {}", reconciliation, name);
    TopicController topicController = TopicController.fromConfigMap(assemblyCm);
    Deployment deployment = topicController != null ? topicController.generateDeployment() : null;
    return deploymentOperations.reconcile(namespace, topicControllerName(name), deployment);
}
Also used : TopicController(io.strimzi.controller.cluster.model.TopicController) Deployment(io.fabric8.kubernetes.api.model.extensions.Deployment)

Aggregations

IOException (java.io.IOException)81 Test (org.junit.Test)78 KubernetesClientException (io.fabric8.kubernetes.client.KubernetesClientException)74 ConfigMap (io.fabric8.kubernetes.api.model.ConfigMap)65 OpenShiftClient (io.fabric8.openshift.client.OpenShiftClient)60 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)59 HashMap (java.util.HashMap)59 KubernetesClient (io.fabric8.kubernetes.client.KubernetesClient)58 FileNotFoundException (java.io.FileNotFoundException)49 DefaultKubernetesClient (io.fabric8.kubernetes.client.DefaultKubernetesClient)48 OpenShiftNotAvailableException (io.fabric8.openshift.client.OpenShiftNotAvailableException)48 JSONObject (org.json.JSONObject)44 Service (io.fabric8.kubernetes.api.model.Service)38 Pod (io.fabric8.kubernetes.api.model.Pod)36 ArrayList (java.util.ArrayList)32 File (java.io.File)25 ReplicationController (io.fabric8.kubernetes.api.model.ReplicationController)24 BuildConfig (io.fabric8.openshift.api.model.BuildConfig)24 Map (java.util.Map)22 ConfigMapBuilder (io.fabric8.kubernetes.api.model.ConfigMapBuilder)21