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);
}
});
}
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();
}
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);
}
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×tamps=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);
}
}
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);
}
Aggregations