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