Search in sources :

Example 66 with Namespace

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

the class KafkaConnectS2IAssemblyOperator method createOrUpdate.

@Override
public void createOrUpdate(Reconciliation reconciliation, ConfigMap assemblyCm, Handler<AsyncResult<Void>> handler) {
    String namespace = reconciliation.namespace();
    if (isOpenShift) {
        KafkaConnectS2ICluster connect = KafkaConnectS2ICluster.fromConfigMap(assemblyCm);
        Future<Void> chainFuture = Future.future();
        deploymentConfigOperations.scaleDown(namespace, connect.getName(), connect.getReplicas()).compose(scale -> serviceOperations.reconcile(namespace, connect.getName(), connect.generateService())).compose(i -> deploymentConfigOperations.reconcile(namespace, connect.getName(), connect.generateDeploymentConfig())).compose(i -> imagesStreamOperations.reconcile(namespace, connect.getSourceImageStreamName(), connect.generateSourceImageStream())).compose(i -> imagesStreamOperations.reconcile(namespace, connect.getName(), connect.generateTargetImageStream())).compose(i -> buildConfigOperations.reconcile(namespace, connect.getName(), connect.generateBuildConfig())).compose(i -> deploymentConfigOperations.scaleUp(namespace, connect.getName(), connect.getReplicas()).map((Void) null)).compose(chainFuture::complete, chainFuture);
        chainFuture.setHandler(handler);
    } else {
        handler.handle(Future.failedFuture("S2I only available on OpenShift"));
    }
}
Also used : AssemblyType(io.strimzi.controller.cluster.model.AssemblyType) Logger(org.slf4j.Logger) Vertx(io.vertx.core.Vertx) LoggerFactory(org.slf4j.LoggerFactory) ServiceOperator(io.strimzi.controller.cluster.operator.resource.ServiceOperator) ConfigMapOperator(io.strimzi.controller.cluster.operator.resource.ConfigMapOperator) HasMetadata(io.fabric8.kubernetes.api.model.HasMetadata) Labels(io.strimzi.controller.cluster.model.Labels) Future(io.vertx.core.Future) ConfigMap(io.fabric8.kubernetes.api.model.ConfigMap) ArrayList(java.util.ArrayList) BuildConfigOperator(io.strimzi.controller.cluster.operator.resource.BuildConfigOperator) CompositeFuture(io.vertx.core.CompositeFuture) List(java.util.List) ImageStreamOperator(io.strimzi.controller.cluster.operator.resource.ImageStreamOperator) Reconciliation(io.strimzi.controller.cluster.Reconciliation) DeploymentConfigOperator(io.strimzi.controller.cluster.operator.resource.DeploymentConfigOperator) KafkaConnectS2ICluster(io.strimzi.controller.cluster.model.KafkaConnectS2ICluster) AsyncResult(io.vertx.core.AsyncResult) Handler(io.vertx.core.Handler) KafkaConnectS2ICluster(io.strimzi.controller.cluster.model.KafkaConnectS2ICluster)

Example 67 with Namespace

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

the class StatefulSetOperator method restartPod.

private Future<Void> restartPod(String namespace, String name, Predicate<String> isReady, String podName) {
    Future<Void> result = Future.future();
    log.info("Roll {}/{}: Rolling pod {}", namespace, name, podName);
    Future<Void> deleted = Future.future();
    Future<CompositeFuture> deleteFinished = Future.future();
    Watcher<Pod> watcher = new RollingUpdateWatcher(deleted);
    Watch watch = podOperations.watch(namespace, podName, watcher);
    // Delete the pod
    log.debug("Roll {}/{}: Waiting for pod {} to be deleted", namespace, name, podName);
    Future podReconcileFuture = podOperations.reconcile(namespace, podName, null);
    CompositeFuture.join(podReconcileFuture, deleted).setHandler(deleteResult -> {
        watch.close();
        if (deleteResult.succeeded()) {
            log.debug("Roll {}/{}: Pod {} was deleted", namespace, name, podName);
        }
        deleteFinished.handle(deleteResult);
    });
    deleteFinished.compose(ix -> {
        log.debug("Roll {}/{}: Waiting for new pod {} to get ready", namespace, name, podName);
        Future<Void> readyFuture = Future.future();
        vertx.setPeriodic(1_000, timerId -> {
            p(isReady, podName).setHandler(x -> {
                if (x.succeeded()) {
                    if (x.result()) {
                        vertx.cancelTimer(timerId);
                        readyFuture.complete();
                    }
                // else not ready
                } else {
                    vertx.cancelTimer(timerId);
                    readyFuture.fail(x.cause());
                }
            });
        });
        return readyFuture;
    }).setHandler(result);
    return result;
}
Also used : CompositeFuture(io.vertx.core.CompositeFuture) KubernetesClientException(io.fabric8.kubernetes.client.KubernetesClientException) StatefulSetList(io.fabric8.kubernetes.api.model.extensions.StatefulSetList) MixedOperation(io.fabric8.kubernetes.client.dsl.MixedOperation) DoneableStatefulSet(io.fabric8.kubernetes.api.model.extensions.DoneableStatefulSet) Logger(org.slf4j.Logger) StatefulSet(io.fabric8.kubernetes.api.model.extensions.StatefulSet) Predicate(java.util.function.Predicate) Vertx(io.vertx.core.Vertx) LoggerFactory(org.slf4j.LoggerFactory) Pod(io.fabric8.kubernetes.api.model.Pod) Watcher(io.fabric8.kubernetes.client.Watcher) Watch(io.fabric8.kubernetes.client.Watch) Future(io.vertx.core.Future) ArrayList(java.util.ArrayList) CompositeFuture(io.vertx.core.CompositeFuture) List(java.util.List) RollableScalableResource(io.fabric8.kubernetes.client.dsl.RollableScalableResource) KubernetesClient(io.fabric8.kubernetes.client.KubernetesClient) Pod(io.fabric8.kubernetes.api.model.Pod) Watch(io.fabric8.kubernetes.client.Watch) Future(io.vertx.core.Future) CompositeFuture(io.vertx.core.CompositeFuture)

Example 68 with Namespace

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

the class KubernetesContainerClient method registerNode.

@Override
public ContainerClientRegistration registerNode(String zaleniumContainerName, URL remoteHost) {
    String podIpAddress = remoteHost.getHost();
    // The only way to lookup a pod name by IP address is by looking at all pods in the namespace it seems.
    PodList list = client.pods().withLabels(createdByZaleniumMap).list();
    String containerId = null;
    Pod currentPod = null;
    for (Pod pod : list.getItems()) {
        if (podIpAddress.equals(pod.getStatus().getPodIP())) {
            containerId = pod.getMetadata().getName();
            currentPod = pod;
            break;
        }
    }
    if (containerId == null) {
        throw new IllegalStateException("Unable to locate pod by ip address, registration will fail");
    }
    ContainerClientRegistration registration = new ContainerClientRegistration();
    List<EnvVar> podEnvironmentVariables = currentPod.getSpec().getContainers().get(0).getEnv();
    Optional<EnvVar> noVncPort = podEnvironmentVariables.stream().filter(env -> "NOVNC_PORT".equals(env.getName())).findFirst();
    if (noVncPort.isPresent()) {
        Integer noVncPortInt = Integer.decode(noVncPort.get().getValue());
        registration.setNoVncPort(noVncPortInt);
    } else {
        logger.warn(String.format("%s Couldn't find NOVNC_PORT, live preview will not work.", containerId));
    }
    registration.setIpAddress(currentPod.getStatus().getPodIP());
    registration.setContainerId(containerId);
    return registration;
}
Also used : Quantity(io.fabric8.kubernetes.api.model.Quantity) VolumeMount(io.fabric8.kubernetes.api.model.VolumeMount) Arrays(java.util.Arrays) StringUtils(org.apache.commons.lang.StringUtils) DoneablePod(io.fabric8.kubernetes.api.model.DoneablePod) EnvVar(io.fabric8.kubernetes.api.model.EnvVar) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Environment(de.zalando.ep.zalenium.util.Environment) URL(java.net.URL) ContainerClientRegistration(de.zalando.ep.zalenium.container.ContainerClientRegistration) LoggerFactory(org.slf4j.LoggerFactory) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) HashMap(java.util.HashMap) CompletableFuture(java.util.concurrent.CompletableFuture) Function(java.util.function.Function) Supplier(java.util.function.Supplier) ArrayList(java.util.ArrayList) InetAddress(java.net.InetAddress) HostAlias(io.fabric8.kubernetes.api.model.HostAlias) Map(java.util.Map) Response(okhttp3.Response) ExecListener(io.fabric8.kubernetes.client.dsl.ExecListener) ContainerClient(de.zalando.ep.zalenium.container.ContainerClient) Volume(io.fabric8.kubernetes.api.model.Volume) Logger(org.slf4j.Logger) Pod(io.fabric8.kubernetes.api.model.Pod) ExecWatch(io.fabric8.kubernetes.client.dsl.ExecWatch) UnknownHostException(java.net.UnknownHostException) Collectors(java.util.stream.Collectors) CountDownLatch(java.util.concurrent.CountDownLatch) List(java.util.List) PodList(io.fabric8.kubernetes.api.model.PodList) KubernetesClient(io.fabric8.kubernetes.client.KubernetesClient) Optional(java.util.Optional) ContainerCreationStatus(de.zalando.ep.zalenium.container.ContainerCreationStatus) InputStream(java.io.InputStream) PodList(io.fabric8.kubernetes.api.model.PodList) ContainerClientRegistration(de.zalando.ep.zalenium.container.ContainerClientRegistration) DoneablePod(io.fabric8.kubernetes.api.model.DoneablePod) Pod(io.fabric8.kubernetes.api.model.Pod) EnvVar(io.fabric8.kubernetes.api.model.EnvVar)

Example 69 with Namespace

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

the class KubernetesAssert method getReplicationController.

protected ReplicationController getReplicationController(String replicationControllerId, String namespace) {
    assertThat(replicationControllerId).isNotNull();
    ReplicationController replicationController = null;
    try {
        replicationController = client.replicationControllers().inNamespace(namespace).withName(replicationControllerId).get();
    } catch (Exception e) {
        fail("Could not find replicationController for '" + replicationControllerId + "'");
    }
    assertThat(replicationController).isNotNull();
    return replicationController;
}
Also used : ReplicationController(io.fabric8.kubernetes.api.model.ReplicationController) IOException(java.io.IOException)

Example 70 with Namespace

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

the class KubernetesAssert method services.

public ServicesAssert services() {
    ServiceList serviceList = client.services().inNamespace(namespace()).list();
    assertThat(serviceList).isNotNull();
    List<Service> services = serviceList.getItems();
    return new ServicesAssert(client, services);
}
Also used : ServiceList(io.fabric8.kubernetes.api.model.ServiceList) Service(io.fabric8.kubernetes.api.model.Service)

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