use of io.fabric8.kubernetes.api.model.apps.Deployment in project fabric8 by jboss-fuse.
the class KubernetesAssert method deployments.
/**
* Finds all the resources that create pod selections (Deployment, DeploymentConfig, ReplicaSet, ReplicationController)
* and create a {@link HasPodSelectionAssert} to make assertions on their pods that they startup etc.
*
* @return the assertion object for the deployment
*/
public HasPodSelectionAssert deployments() {
List<HasPodSelectionAssert> asserters = new ArrayList<>();
List<HasMetadata> resources = new ArrayList<>();
try {
resources = KubernetesHelper.findKubernetesResourcesOnClasspath(new Controller(client));
} catch (IOException e) {
fail("Failed to load kubernetes resources on the classpath: " + e, e);
}
for (HasMetadata resource : resources) {
HasPodSelectionAssert asserter = createPodSelectionAssert(resource);
if (asserter != null) {
asserters.add(asserter);
}
}
String message = "No pod selection kinds found on the classpath such as Deployment, DeploymentConfig, ReplicaSet, ReplicationController";
// TODO we don't yet support size > 1
assertThat(asserters).describedAs(message).isNotEmpty();
if (asserters.size() == 1) {
return asserters.get(0);
}
return new MultiHasPodSelectionAssert(asserters);
}
use of io.fabric8.kubernetes.api.model.apps.Deployment in project fabric8 by jboss-fuse.
the class PodSelectionAssert method isPodReadyForPeriod.
/**
* Asserts that a pod is ready for this deployment all become ready within the given time and that each one keeps being ready for the given time
*/
public PodSelectionAssert isPodReadyForPeriod(long notReadyTimeoutMS, long readyPeriodMS) {
if (replicas.intValue() <= 0) {
LOG.warn("Not that the pod selection for: " + description + " has no replicas defined so we cannot assert there is a pod ready");
return this;
}
try (PodWatcher podWatcher = new PodWatcher(this, notReadyTimeoutMS, readyPeriodMS);
Watch watch = client.pods().withLabels(matchLabels).watch(podWatcher)) {
podWatcher.loadCurrentPods();
podWatcher.waitForPodReady();
}
return this;
}
use of io.fabric8.kubernetes.api.model.apps.Deployment in project fabric8 by jboss-fuse.
the class YamlSerialiseTest method testSerialiseYaml.
@Test
public void testSerialiseYaml() throws Exception {
Deployment deployment = new DeploymentBuilder().withNewMetadata().withName("foo").endMetadata().withNewSpec().withReplicas(1).withNewTemplate().withNewSpec().addNewContainer().withImage("cheese").endContainer().endSpec().endTemplate().endSpec().build();
File outFile = new File(new File(basedir), "target/test-data/deployment.yml");
outFile.getParentFile().mkdirs();
KubernetesHelper.saveYamlNotEmpty(deployment, outFile);
String yaml = IOHelpers.readFully(outFile);
System.out.println("YAML: " + yaml);
}
use of io.fabric8.kubernetes.api.model.apps.Deployment in project fabric8 by jboss-fuse.
the class Util method displaySessionStatus.
public static void displaySessionStatus(KubernetesClient client, Session session) throws MultiException {
if (client == null) {
session.getLogger().warn("No KubernetesClient for session: " + session.getId());
return;
}
if (client.isAdaptable(OpenShiftClient.class)) {
OpenShiftClient oClient = client.adapt(OpenShiftClient.class);
List<DeploymentConfig> deploymentConfigs = oClient.deploymentConfigs().inNamespace(session.getNamespace()).list().getItems();
if (deploymentConfigs == null) {
throw new MultiException("No deployment configs found in namespace" + session.getNamespace());
}
for (DeploymentConfig deploymentConfig : deploymentConfigs) {
session.getLogger().info("Deployment config:" + KubernetesHelper.getName(deploymentConfig));
}
} else {
List<Deployment> deployments = client.extensions().deployments().inNamespace(session.getNamespace()).list().getItems();
if (deployments == null) {
throw new MultiException("No deployments found in namespace" + session.getNamespace());
}
for (Deployment deployment : deployments) {
session.getLogger().info("Deployment:" + KubernetesHelper.getName(deployment));
}
}
List<Pod> pods = client.pods().inNamespace(session.getNamespace()).list().getItems();
if (pods == null) {
throw new MultiException("No pods found in namespace" + session.getNamespace());
}
for (Pod pod : pods) {
session.getLogger().info("Pod:" + KubernetesHelper.getName(pod) + " Status:" + pod.getStatus());
}
List<Service> svcs = client.services().inNamespace(session.getNamespace()).list().getItems();
if (svcs == null) {
throw new MultiException("No services found in namespace" + session.getNamespace());
}
for (Service service : svcs) {
session.getLogger().info("Service:" + KubernetesHelper.getName(service) + " IP:" + getPortalIP(service) + " Port:" + getPorts(service));
}
}
use of io.fabric8.kubernetes.api.model.apps.Deployment in project TOSCAna by StuPro-TOSCAna.
the class ResourceDeployment method build.
@Override
public ResourceDeployment build() {
ArrayList<Container> containers = new ArrayList<>();
// Create the Container objects of the containers belonging in the Pod
pod.getContainers().forEach(e -> {
Container container = new ContainerBuilder().withImage(e.getDockerImageTag().get()).withName(e.getCleanStackName()).withImagePullPolicy("Always").addAllToPorts(e.getOpenPorts().stream().map(Port::toContainerPort).collect(Collectors.toList())).build();
containers.add(container);
});
deployment = new DeploymentBuilder().withNewMetadata().withName(pod.getDeploymentName()).addToLabels("app", name).endMetadata().withNewSpec().withReplicas(pod.getReplicaCount()).withNewSelector().addToMatchLabels("app", name).endSelector().withNewTemplate().withNewMetadata().withName(name).addToLabels("app", name).endMetadata().withNewSpec().addAllToContainers(containers).endSpec().endTemplate().endSpec().build();
return this;
}
Aggregations