use of io.fabric8.openshift.client.OpenShiftClient in project carbon-apimgt by wso2.
the class ServiceDiscovererKubernetesTestCase method testListServices.
@Test(description = "Test .listServices() method")
public void testListServices() throws Exception {
OpenShiftClient openShiftClient = Mockito.mock(OpenShiftClient.class, Mockito.RETURNS_DEEP_STUBS);
ServiceDiscovererKubernetes sdKubernetes = new ServiceDiscovererKubernetes();
sdKubernetes.setClient(openShiftClient);
// Include ClusterIPs
sdKubernetes.setIncludeClusterIP(true);
// Include ExternalNames
sdKubernetes.setIncludeExternalNameTypeServices(true);
NonNamespaceOperation nonNamespaceOperation = Mockito.mock(NonNamespaceOperation.class);
Mockito.when(openShiftClient.services().inNamespace(null)).thenReturn(nonNamespaceOperation);
Mockito.when(nonNamespaceOperation.list()).thenReturn(createServiceList());
Mockito.when(openShiftClient.getMasterUrl()).thenReturn(new URL(MASTER_URL));
List<Endpoint> endpoints = sdKubernetes.listServices();
Assert.assertEquals(endpoints.size(), 10);
// 2 NodePort URL endpoints
Mockito.verify(openShiftClient, Mockito.times(2)).getMasterUrl();
}
use of io.fabric8.openshift.client.OpenShiftClient in project carbon-apimgt by wso2.
the class ServiceDiscovererKubernetesTestCase method testInitWhileExternalTokenFileNameGiven.
@Test(description = "Test init method with external service account token file name")
public void testInitWhileExternalTokenFileNameGiven() throws Exception {
OpenShiftClient openShiftClient = Mockito.mock(OpenShiftClient.class);
ServiceDiscovererKubernetes sdKubernetes = new ServiceDiscovererKubernetes();
sdKubernetes.setClient(openShiftClient);
try {
sdKubernetes.initImpl(createImplParametersMap("TestK8Token"));
} catch (ServiceDiscoveryException e) {
Assert.assertEquals(e.getCause().getMessage(), "File to decrypt does not exist");
}
}
use of io.fabric8.openshift.client.OpenShiftClient in project vertx-openshift-it by cescoffier.
the class Deployment method deployIfNeeded.
public static String deployIfNeeded(KubernetesClient client, File input) {
OpenShiftClient oc = oc(client);
assertThat(input).isFile();
try {
byte[] bytes = Files.readBytes(input);
try (ByteArrayInputStream bis = new ByteArrayInputStream(bytes)) {
DeploymentConfig deploymentConfig = oc.deploymentConfigs().load(bis).get();
assertThat(deploymentConfig).isNotNull();
if (oc.deploymentConfigs().withName(deploymentConfig.getMetadata().getName()).get() != null) {
System.out.println("Skipping the creation of dc/" + deploymentConfig.getMetadata().getName());
return deploymentConfig.getMetadata().getName();
}
oc.deploymentConfigs().create(deploymentConfig);
OC.execute("deploy", deploymentConfig.getMetadata().getName(), "--latest", "-n", oc.getNamespace());
return deploymentConfig.getMetadata().getName();
}
} catch (Exception e) {
throw new RuntimeException("Unable to deploy deployment config " + input.getAbsolutePath(), e);
}
}
use of io.fabric8.openshift.client.OpenShiftClient in project vertx-openshift-it by cescoffier.
the class Kube method setReplicasAndWait.
public static DeploymentConfig setReplicasAndWait(KubernetesClient client, String name, int number) {
OpenShiftClient oc = oc(client);
DeploymentConfig config = oc.deploymentConfigs().withName(name).get();
if (config == null) {
fail("Unable to find the deployment config " + name);
return null;
}
if (config.getSpec().getReplicas() == number) {
return config;
}
config = oc.deploymentConfigs().withName(name).edit().editSpec().withReplicas(number).endSpec().done();
if (number == 0) {
// Wait until no pods
await().atMost(duration()).until(() -> getPodsForDeploymentConfig(client, name).size() == 0);
} else {
// Wait until the right number of pods
await().atMost(duration()).until(() -> getPodsForDeploymentConfig(client, name).size() == number);
// Wait for readiness
await().atMost(duration()).until(() -> getPodsForDeploymentConfig(client, name).stream().filter(KubernetesHelper::isPodReady).count() == number);
}
return config;
}
use of io.fabric8.openshift.client.OpenShiftClient in project fabric8-maven-plugin by fabric8io.
the class AbstractFabric8Mojo method getOpenShiftClientOrJenkinsShift.
protected OpenShiftClient getOpenShiftClientOrJenkinsShift(KubernetesClient kubernetes, String namespace) throws MojoExecutionException {
OpenShiftClient openShiftClient = getOpenShiftClientOrNull(kubernetes);
if (openShiftClient == null) {
String jenkinshiftUrl = getJenkinShiftUrl(kubernetes, namespace);
log.debug("Using jenkinshift URL: " + jenkinshiftUrl);
if (jenkinshiftUrl == null) {
throw new MojoExecutionException("Could not find the service `" + ServiceNames.JENKINSHIFT + "` im namespace `" + namespace + "` on this kubernetes cluster " + kubernetes.getMasterUrl());
}
return KubernetesHelper.createJenkinshiftOpenShiftClient(jenkinshiftUrl);
}
return openShiftClient;
}
Aggregations