Search in sources :

Example 81 with Deployment

use of io.fabric8.kubernetes.api.model.extensions.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 82 with Deployment

use of io.fabric8.kubernetes.api.model.extensions.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 83 with Deployment

use of io.fabric8.kubernetes.api.model.extensions.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 84 with Deployment

use of io.fabric8.kubernetes.api.model.extensions.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 85 with Deployment

use of io.fabric8.kubernetes.api.model.extensions.Deployment in project iobserve-analysis by research-iobserve.

the class DeploymentExecutor method execute.

@Override
public void execute(final DeployComponentAction action) {
    // Can't be loaded earlier because it references the other models received via TCP
    final CorrespondenceModel correspondenceModel = new FileModelHandler<CorrespondenceModel>(this.resourceSet, CorrespondencePackage.eINSTANCE).load(URI.createFileURI(this.correspondenceModelFile.getAbsolutePath()));
    final KubernetesClient client = new DefaultKubernetesClient();
    final String rcName = this.normalizeComponentName(action.getTargetAllocationContext().getResourceContainer_AllocationContext().getEntityName());
    final Deployment deployment = client.extensions().deployments().inNamespace(this.namespace).withName(rcName).get();
    final AssemblyContext targetAssemblyContext = action.getTargetAllocationContext().getAssemblyContext_AllocationContext();
    final String imageName = this.getImageName(correspondenceModel, targetAssemblyContext);
    if (deployment != null) {
        // Increase number of replicas if pod is already deployed...
        final int replicas = deployment.getSpec().getReplicas();
        deployment.getSpec().setReplicas(replicas + 1);
        client.extensions().deployments().inNamespace(this.namespace).withName(rcName).replace(deployment);
        if (DeploymentExecutor.LOGGER.isDebugEnabled()) {
            DeploymentExecutor.LOGGER.debug("Scaled pod deployment of " + deployment.getMetadata().getName() + " to " + (replicas + 1));
        }
    } else {
        // ... deploy new pod if this is not the case
        final Deployment newDeployment = this.podsToDeploy.get(rcName);
        final String imageLocator = newDeployment.getSpec().getTemplate().getSpec().getContainers().get(0).getImage();
        newDeployment.getSpec().getTemplate().getSpec().getContainers().get(0).setImage(imageLocator + "/" + imageName);
        newDeployment.getSpec().getTemplate().getSpec().getContainers().get(0).setName(this.normalizeComponentName(targetAssemblyContext.getEntityName()));
        client.extensions().deployments().inNamespace(this.namespace).create(newDeployment);
        if (DeploymentExecutor.LOGGER.isDebugEnabled()) {
            DeploymentExecutor.LOGGER.debug("Image set to " + imageLocator + "/" + imageName);
            DeploymentExecutor.LOGGER.debug("Created new pod deployment " + newDeployment.getMetadata().getName());
        }
    }
    // Wait until deployed instance is ready
    while (!client.extensions().deployments().inNamespace(this.namespace).withName(rcName).isReady()) {
        if (DeploymentExecutor.LOGGER.isDebugEnabled()) {
            DeploymentExecutor.LOGGER.debug(rcName + " is not ready yet.");
        }
    }
    client.close();
}
Also used : KubernetesClient(io.fabric8.kubernetes.client.KubernetesClient) DefaultKubernetesClient(io.fabric8.kubernetes.client.DefaultKubernetesClient) CorrespondenceModel(org.iobserve.model.correspondence.CorrespondenceModel) Deployment(io.fabric8.kubernetes.api.model.extensions.Deployment) AssemblyContext(org.palladiosimulator.pcm.core.composition.AssemblyContext) DefaultKubernetesClient(io.fabric8.kubernetes.client.DefaultKubernetesClient)

Aggregations

Deployment (io.fabric8.kubernetes.api.model.extensions.Deployment)52 Test (org.junit.Test)28 DeploymentConfig (io.fabric8.openshift.api.model.DeploymentConfig)27 InputStream (java.io.InputStream)26 Service (io.fabric8.kubernetes.api.model.Service)24 HasMetadata (io.fabric8.kubernetes.api.model.HasMetadata)22 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 ServiceTracker (org.osgi.util.tracker.ServiceTracker)20 CommandSupport (io.fabric8.itests.support.CommandSupport)18 Logger (org.slf4j.Logger)18 Pod (io.fabric8.kubernetes.api.model.Pod)17 OpenShiftClient (io.fabric8.openshift.client.OpenShiftClient)17 IOException (java.io.IOException)17 FabricService (io.fabric8.api.FabricService)16 ServiceLocator (io.fabric8.api.gravia.ServiceLocator)16 ArrayList (java.util.ArrayList)16 StartLevelAware (org.jboss.arquillian.osgi.StartLevelAware)16