Search in sources :

Example 61 with Client

use of io.fabric8.kubernetes.client.Client in project vertx-openshift-it by cescoffier.

the class SockJsIT method checkSockStatuses.

@Test
public void checkSockStatuses() throws InterruptedException {
    ensureThat("we can navigate to application ", () -> {
        final Route route = client.routes().withName(deploymentAssistant.applicationName()).get();
        webDriver.navigate().to(urlForRoute(route));
    });
    ensureThat("both statuses are updated", () -> {
        await().atMost(3, TimeUnit.MINUTES).catchUncaughtExceptions().until(() -> isElementEmpty(EB_STATUS));
        await().atMost(3, TimeUnit.MINUTES).catchUncaughtExceptions().until(() -> isElementEmpty(SOCK_STATUS));
    });
    ensureThat("all transports are working and asserted", () -> {
        final JsonPath serverStatus = get("/status").body().jsonPath();
        final JsonObject clientSideEbStatus = getJsonById(EB_STATUS);
        final JsonObject clientSideSockStatus = getJsonById(SOCK_STATUS);
        for (Transport t : Transport.values()) {
            softly.assertThat(serverStatus.getBoolean(t + "-EB")).as("Transport " + t + " should be used on server side (on EventBus). ").isTrue();
            softly.assertThat(serverStatus.getBoolean(t + "-sock")).as("Transport " + t + " should be used on server side (on SockJS). ").isTrue();
            softly.assertThat(clientSideEbStatus.getInteger(t.name())).as("Transport " + t + " should be used on client side (on EventBus). ").isGreaterThan(0);
            softly.assertThat(clientSideSockStatus.getInteger(t.name())).as("Transport " + t + " should be used on client side (on SockJS). ").isGreaterThan(0);
        }
    });
}
Also used : JsonObject(io.vertx.core.json.JsonObject) JsonPath(io.restassured.path.json.JsonPath) Transport(io.vertx.ext.web.handler.sockjs.Transport) Route(io.fabric8.openshift.api.model.Route) Kube.urlForRoute(io.vertx.it.openshift.utils.Kube.urlForRoute) Test(org.junit.Test)

Example 62 with Client

use of io.fabric8.kubernetes.client.Client in project zalenium by zalando.

the class KubernetesContainerClient method copyFiles.

/**
 * Copy some files by executing a tar command to the stdout and return the InputStream that contains the tar
 * contents.
 * <p>
 * Unfortunately due to the fact that any error handling happens on another thread, if the tar command fails the
 * InputStream will simply be empty and it will close. It won't propagate an Exception to the reader of the
 * InputStream.
 */
@Override
public InputStream copyFiles(String containerId, String folderName) {
    ByteArrayOutputStream stderr = new ByteArrayOutputStream();
    String[] command = new String[] { "tar", "-C", folderName, "-c", "." };
    CopyFilesExecListener listener = new CopyFilesExecListener(stderr, command, containerId);
    ExecWatch exec = client.pods().withName(containerId).redirectingOutput().writingError(stderr).usingListener(listener).exec(command);
    // FIXME: This is a bit dodgy, but we need the listener to be able to close the ExecWatch in failure conditions,
    // because it doesn't cleanup properly and deadlocks.
    // Needs bugs fixed inside kubernetes-client.
    listener.setExecWatch(exec);
    // When zalenium is under high load sometimes the stdout isn't connected by the time we try to read from it.
    // Let's wait until it is connected before proceeding.
    listener.waitForInputStreamToConnect();
    return exec.getOutput();
}
Also used : ExecWatch(io.fabric8.kubernetes.client.dsl.ExecWatch) ByteArrayOutputStream(java.io.ByteArrayOutputStream)

Example 63 with Client

use of io.fabric8.kubernetes.client.Client in project syndesis by syndesisio.

the class OpenShiftServiceImplTest method testDeploy.

@SuppressWarnings({ "PMD.ExcessiveMethodLength", "PMD.JUnitTestsShouldIncludeAssert" })
@Test
public void testDeploy() {
    String name = "test-deployment";
    OpenShiftConfigurationProperties config = new OpenShiftConfigurationProperties();
    OpenShiftServiceImpl service = new OpenShiftServiceImpl(client, config);
    DeploymentData deploymentData = new DeploymentData.Builder().addAnnotation("testName", testName.getMethodName()).addLabel("type", "test").addSecretEntry("secret-key", "secret-val").withImage("testimage").build();
    ImageStream expectedImageStream = new ImageStreamBuilder().withNewMetadata().withName(name).endMetadata().build();
    Secret expectedSecret = new SecretBuilder().withNewMetadata().withName(name).addToAnnotations(deploymentData.getAnnotations()).addToLabels(deploymentData.getLabels()).endMetadata().withStringData(deploymentData.getSecret()).build();
    DeploymentConfig expectedDeploymentConfig = new DeploymentConfigBuilder().withNewMetadata().withName(OpenShiftServiceImpl.openshiftName(name)).addToAnnotations(deploymentData.getAnnotations()).addToLabels(deploymentData.getLabels()).endMetadata().withNewSpec().withReplicas(1).addToSelector("integration", name).withNewStrategy().withType("Recreate").withNewResources().addToLimits("memory", new Quantity(config.getDeploymentMemoryLimitMi() + "Mi")).addToRequests("memory", new Quantity(config.getDeploymentMemoryRequestMi() + "Mi")).endResources().endStrategy().withRevisionHistoryLimit(0).withNewTemplate().withNewMetadata().addToLabels("integration", name).addToLabels(OpenShiftServiceImpl.COMPONENT_LABEL, "integration").addToLabels(deploymentData.getLabels()).addToAnnotations(deploymentData.getAnnotations()).addToAnnotations("prometheus.io/scrape", "true").addToAnnotations("prometheus.io/port", "9779").endMetadata().withNewSpec().addNewContainer().withImage(deploymentData.getImage()).withImagePullPolicy("Always").withName(name).addToEnv(new EnvVarBuilder().withName("LOADER_HOME").withValue(config.getIntegrationDataPath()).build()).addToEnv(new EnvVarBuilder().withName("AB_JMX_EXPORTER_CONFIG").withValue("/tmp/src/prometheus-config.yml").build()).addNewPort().withName("jolokia").withContainerPort(8778).endPort().addNewVolumeMount().withName("secret-volume").withMountPath("/deployments/config").withReadOnly(false).endVolumeMount().endContainer().addNewVolume().withName("secret-volume").withNewSecret().withSecretName(expectedSecret.getMetadata().getName()).endSecret().endVolume().endSpec().endTemplate().addNewTrigger().withType("ConfigChange").endTrigger().endSpec().withNewStatus().withLatestVersion(1L).endStatus().build();
    server.expect().withPath("/oapi/v1/namespaces/test/imagestreams").andReturn(200, expectedImageStream).always();
    server.expect().withPath("/api/v1/namespaces/test/secrets").andReturn(200, expectedSecret).always();
    server.expect().withPath("/oapi/v1/namespaces/test/deploymentconfigs").andReturn(200, expectedDeploymentConfig).always();
    server.expect().withPath("/oapi/v1/namespaces/test/deploymentconfigs/i-test-deployment").andReturn(200, expectedDeploymentConfig).always();
    server.expect().withPath("/oapi/v1/namespaces/test/deploymentconfigs/test-deployment").andReturn(200, expectedDeploymentConfig).always();
    service.deploy(name, deploymentData);
}
Also used : DeploymentConfigBuilder(io.fabric8.openshift.api.model.DeploymentConfigBuilder) ImageStream(io.fabric8.openshift.api.model.ImageStream) Quantity(io.fabric8.kubernetes.api.model.Quantity) EnvVarBuilder(io.fabric8.kubernetes.api.model.EnvVarBuilder) ImageStreamBuilder(io.fabric8.openshift.api.model.ImageStreamBuilder) Secret(io.fabric8.kubernetes.api.model.Secret) SecretBuilder(io.fabric8.kubernetes.api.model.SecretBuilder) DeploymentConfig(io.fabric8.openshift.api.model.DeploymentConfig) Test(org.junit.Test)

Example 64 with Client

use of io.fabric8.kubernetes.client.Client in project syndesis by syndesisio.

the class KubernetesSupport method watchLog.

/*
     * Feeds the controller of the given podName to the callback handler for processing.
     *
     * We do this instead of using the watchLog() feature of the k8s client lib because it really sucks due to:
     *  1. You can't configure the timestamps option or the sinceTime option.  Need to resume log downloads.
     *  2. It seems to need extra threads..
     *  3. It might be hiding some of the http failure conditions.
     *
     */
protected void watchLog(String podName, Consumer<InputStream> handler, String sinceTime, Executor executor) throws IOException {
    try {
        PodOperationsImpl pod = (PodOperationsImpl) client.pods().withName(podName);
        StringBuilder url = new StringBuilder().append(pod.getResourceUrl().toString()).append("/log?pretty=false&follow=true&timestamps=true");
        if (sinceTime != null) {
            url.append("&sinceTime=");
        }
        Request request = new Request.Builder().url(new URL(url.toString())).get().build();
        OkHttpClient clone = okHttpClient.newBuilder().readTimeout(0, TimeUnit.MILLISECONDS).build();
        clone.newCall(request).enqueue(new Callback() {

            @Override
            public void onFailure(Call call, IOException e) {
                LOG.info("Failure occurred getting  controller for pod: {},", podName, e);
                handler.accept(null);
            }

            @Override
            public void onResponse(final Call call, final Response response) throws IOException {
                executor.execute(() -> {
                    try {
                        if (response.code() == 200) {
                            handler.accept(response.body().byteStream());
                        } else {
                            LOG.info("Failure occurred while processing controller for pod: {}, http status: {}, details: {}", podName, response.code(), response.body().string());
                            handler.accept(null);
                        }
                    } catch (IOException e) {
                        LOG.error("Unexpected Error", e);
                    }
                });
            }
        });
    } catch (@SuppressWarnings("PMD.AvoidCatchingGenericException") RuntimeException t) {
        throw new IOException("Unexpected Error", t);
    }
}
Also used : Response(okhttp3.Response) Call(okhttp3.Call) OkHttpClient(okhttp3.OkHttpClient) Callback(okhttp3.Callback) Request(okhttp3.Request) IOException(java.io.IOException) PodOperationsImpl(io.fabric8.kubernetes.client.dsl.internal.PodOperationsImpl) URL(java.net.URL)

Example 65 with Client

use of io.fabric8.kubernetes.client.Client in project fabric8 by fabric8io.

the class OpenShiftAssert method builds.

public BuildsAssert builds() {
    BuildList listObject = client.builds().list();
    assertThat(listObject).describedAs("No BuildList found!").isNotNull();
    List<Build> list = listObject.getItems();
    assertThat(list).describedAs("No Build Items found!").isNotNull();
    return new BuildsAssert(list, client);
}
Also used : BuildList(io.fabric8.openshift.api.model.BuildList) Build(io.fabric8.openshift.api.model.Build)

Aggregations

KubernetesClient (io.fabric8.kubernetes.client.KubernetesClient)42 Test (org.junit.Test)34 DefaultKubernetesClient (io.fabric8.kubernetes.client.DefaultKubernetesClient)29 Service (io.fabric8.kubernetes.api.model.Service)24 OpenShiftClient (io.fabric8.openshift.client.OpenShiftClient)23 IOException (java.io.IOException)23 File (java.io.File)22 ArrayList (java.util.ArrayList)21 HashMap (java.util.HashMap)20 KubernetesClientException (io.fabric8.kubernetes.client.KubernetesClientException)18 Pod (io.fabric8.kubernetes.api.model.Pod)14 DefaultOpenShiftClient (io.fabric8.openshift.client.DefaultOpenShiftClient)14 ClientInvokerImpl (io.fabric8.dosgi.tcp.ClientInvokerImpl)8 ServerInvokerImpl (io.fabric8.dosgi.tcp.ServerInvokerImpl)8 URL (java.net.URL)8 Map (java.util.Map)8 ServerInvoker (io.fabric8.dosgi.io.ServerInvoker)7 DockerClient (io.fabric8.docker.client.DockerClient)6 MalformedURLException (java.net.MalformedURLException)6 Session (io.fabric8.arquillian.kubernetes.Session)5