Search in sources :

Example 41 with Deployment

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);
}
Also used : HasMetadata(io.fabric8.kubernetes.api.model.HasMetadata) ArrayList(java.util.ArrayList) IOException(java.io.IOException) Controller(io.fabric8.kubernetes.api.Controller) ReplicationController(io.fabric8.kubernetes.api.model.ReplicationController)

Example 42 with Deployment

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;
}
Also used : Watch(io.fabric8.kubernetes.client.Watch) PodWatcher(io.fabric8.kubernetes.assertions.support.PodWatcher)

Example 43 with Deployment

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);
}
Also used : Deployment(io.fabric8.kubernetes.api.model.extensions.Deployment) File(java.io.File) DeploymentBuilder(io.fabric8.kubernetes.api.model.extensions.DeploymentBuilder) Test(org.junit.Test)

Example 44 with Deployment

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));
    }
}
Also used : Pod(io.fabric8.kubernetes.api.model.Pod) OpenShiftClient(io.fabric8.openshift.client.OpenShiftClient) Deployment(io.fabric8.kubernetes.api.model.extensions.Deployment) Service(io.fabric8.kubernetes.api.model.Service) DeploymentConfig(io.fabric8.openshift.api.model.DeploymentConfig) MultiException(io.fabric8.utils.MultiException)

Example 45 with Deployment

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;
}
Also used : Container(io.fabric8.kubernetes.api.model.Container) ContainerBuilder(io.fabric8.kubernetes.api.model.ContainerBuilder) ArrayList(java.util.ArrayList) DeploymentBuilder(io.fabric8.kubernetes.api.model.extensions.DeploymentBuilder)

Aggregations

File (java.io.File)62 Deployment (io.fabric8.kubernetes.api.model.extensions.Deployment)52 Test (org.testng.annotations.Test)50 Deployment (io.fabric8.kubernetes.api.model.apps.Deployment)47 HasMetadata (io.fabric8.kubernetes.api.model.HasMetadata)43 Container (io.fabric8.kubernetes.api.model.Container)32 Service (io.fabric8.kubernetes.api.model.Service)28 Test (org.junit.Test)28 DeploymentConfig (io.fabric8.openshift.api.model.DeploymentConfig)27 InputStream (java.io.InputStream)26 DefaultKubernetesClient (io.fabric8.kubernetes.client.DefaultKubernetesClient)25 KubernetesClient (io.fabric8.kubernetes.client.KubernetesClient)25 Deployment (org.jboss.arquillian.container.test.api.Deployment)21 OSGiManifestBuilder (org.jboss.osgi.metadata.OSGiManifestBuilder)21 Asset (org.jboss.shrinkwrap.api.asset.Asset)21 JavaArchive (org.jboss.shrinkwrap.api.spec.JavaArchive)21 IOException (java.io.IOException)20 ServiceTracker (org.osgi.util.tracker.ServiceTracker)20 FileInputStream (java.io.FileInputStream)19 CommandSupport (io.fabric8.itests.support.CommandSupport)18