use of org.eclipse.che.api.workspace.server.model.impl.devfile.ComponentImpl in project devspaces-images by redhat-developer.
the class KubernetesComponentToWorkspaceApplier method provisionVolumes.
private void provisionVolumes(ComponentImpl component, Container container, MachineConfigImpl config) throws DevfileException {
for (org.eclipse.che.api.workspace.server.model.impl.devfile.VolumeImpl componentVolume : component.getVolumes()) {
Optional<VolumeMount> sameNameMount = container.getVolumeMounts().stream().filter(vm -> vm.getName().equals(componentVolume.getName())).findFirst();
if (sameNameMount.isPresent() && sameNameMount.get().getMountPath().equals(componentVolume.getContainerPath())) {
continue;
} else if (sameNameMount.isPresent()) {
throw new DevfileException(format("Conflicting volume with same name ('%s') but different path ('%s') found for component '%s' and its container '%s'.", componentVolume.getName(), componentVolume.getContainerPath(), getIdentifiableComponentName(component), container.getName()));
}
if (container.getVolumeMounts().stream().anyMatch(vm -> vm.getMountPath().equals(componentVolume.getContainerPath()))) {
throw new DevfileException(format("Conflicting volume with same path ('%s') but different name ('%s') found for component '%s' and its container '%s'.", componentVolume.getContainerPath(), componentVolume.getName(), getIdentifiableComponentName(component), container.getName()));
}
config.getVolumes().put(componentVolume.getName(), new VolumeImpl().withPath(componentVolume.getContainerPath()));
}
}
use of org.eclipse.che.api.workspace.server.model.impl.devfile.ComponentImpl in project devspaces-images by redhat-developer.
the class DockerimageComponentToWorkspaceApplierTest method shouldProvisionSpecifiedEnvVars.
@Test
public void shouldProvisionSpecifiedEnvVars() throws Exception {
// given
ComponentImpl dockerimageComponent = new ComponentImpl();
dockerimageComponent.setAlias("jdk");
dockerimageComponent.setType(DOCKERIMAGE_COMPONENT_TYPE);
dockerimageComponent.setImage("eclipse/ubuntu_jdk8:latest");
dockerimageComponent.setMemoryLimit("1G");
dockerimageComponent.setEnv(singletonList(new EnvImpl("envName", "envValue")));
// when
dockerimageComponentApplier.apply(workspaceConfig, dockerimageComponent, null);
// then
verify(k8sEnvProvisioner).provision(eq(workspaceConfig), eq(KubernetesEnvironment.TYPE), objectsCaptor.capture(), machinesCaptor.capture());
List<HasMetadata> objects = objectsCaptor.getValue();
assertEquals(objects.size(), 1);
assertTrue(objects.get(0) instanceof Deployment);
Deployment deployment = (Deployment) objects.get(0);
PodTemplateSpec podTemplate = deployment.getSpec().getTemplate();
assertEquals(podTemplate.getSpec().getContainers().size(), 1);
Container container = podTemplate.getSpec().getContainers().get(0);
int env = container.getEnv().size();
assertEquals(env, 1);
EnvVar containerEnvVar = container.getEnv().get(0);
assertEquals(containerEnvVar.getName(), "envName");
assertEquals(containerEnvVar.getValue(), "envValue");
}
use of org.eclipse.che.api.workspace.server.model.impl.devfile.ComponentImpl in project devspaces-images by redhat-developer.
the class DockerimageComponentToWorkspaceApplierTest method shouldProvisionK8sEnvironmentWithMachineConfigAndGeneratedDeploymentForSpecifiedDockerimage.
@Test
public void shouldProvisionK8sEnvironmentWithMachineConfigAndGeneratedDeploymentForSpecifiedDockerimage() throws Exception {
// given
ComponentImpl dockerimageComponent = new ComponentImpl();
dockerimageComponent.setType(DOCKERIMAGE_COMPONENT_TYPE);
dockerimageComponent.setAlias("jdk");
dockerimageComponent.setImage("eclipse/ubuntu_jdk8:latest");
dockerimageComponent.setMemoryLimit("1G");
// when
dockerimageComponentApplier.apply(workspaceConfig, dockerimageComponent, null);
// then
verify(k8sEnvProvisioner).provision(eq(workspaceConfig), eq(KubernetesEnvironment.TYPE), objectsCaptor.capture(), machinesCaptor.capture());
MachineConfigImpl machineConfig = machinesCaptor.getValue().get("jdk");
assertNotNull(machineConfig);
List<HasMetadata> objects = objectsCaptor.getValue();
assertEquals(objects.size(), 1);
assertTrue(objects.get(0) instanceof Deployment);
Deployment deployment = (Deployment) objects.get(0);
PodTemplateSpec podTemplate = deployment.getSpec().getTemplate();
ObjectMeta podMeta = podTemplate.getMetadata();
assertEquals(podMeta.getName(), "jdk");
Map<String, String> deploymentSelector = deployment.getSpec().getSelector().getMatchLabels();
assertFalse(deploymentSelector.isEmpty());
assertTrue(podMeta.getLabels().entrySet().containsAll(deploymentSelector.entrySet()));
Container container = podTemplate.getSpec().getContainers().get(0);
assertEquals(container.getName(), "jdk");
assertEquals(container.getImage(), "eclipse/ubuntu_jdk8:latest");
assertEquals(container.getImagePullPolicy(), "Always");
assertEquals(Names.machineName(podMeta, container), "jdk");
}
use of org.eclipse.che.api.workspace.server.model.impl.devfile.ComponentImpl in project devspaces-images by redhat-developer.
the class DockerimageComponentToWorkspaceApplierTest method shouldBeAbleToSetupSpecificImagePullPolicy.
@Test
public void shouldBeAbleToSetupSpecificImagePullPolicy() throws DevfileException {
ComponentImpl dockerimageComponent = new ComponentImpl();
dockerimageComponent.setType(DOCKERIMAGE_COMPONENT_TYPE);
dockerimageComponent.setImage("eclipse/ubuntu_jdk8:latest");
dockerimageComponent.setMemoryLimit("1G");
dockerimageComponentApplier = new DockerimageComponentToWorkspaceApplier(PROJECTS_MOUNT_PATH, "Never", MULTI_HOST_STRATEGY, k8sEnvProvisioner);
// when
dockerimageComponentApplier.apply(workspaceConfig, dockerimageComponent, null);
// then
verify(k8sEnvProvisioner).provision(any(), eq(KubernetesEnvironment.TYPE), objectsCaptor.capture(), machinesCaptor.capture());
MachineConfigImpl machineConfig = machinesCaptor.getValue().get("eclipse-ubuntu_jdk8-latest");
assertNotNull(machineConfig);
List<HasMetadata> objects = objectsCaptor.getValue();
assertEquals(objects.size(), 1);
assertTrue(objects.get(0) instanceof Deployment);
Deployment deployment = (Deployment) objects.get(0);
PodTemplateSpec podTemplate = deployment.getSpec().getTemplate();
ObjectMeta podMeta = podTemplate.getMetadata();
assertEquals(podMeta.getName(), "eclipse-ubuntu_jdk8-latest");
Map<String, String> deploymentSelector = deployment.getSpec().getSelector().getMatchLabels();
assertFalse(deploymentSelector.isEmpty());
assertTrue(podMeta.getLabels().entrySet().containsAll(deploymentSelector.entrySet()));
Container container = podTemplate.getSpec().getContainers().get(0);
assertEquals(container.getName(), "eclipse-ubuntu_jdk8-latest");
assertEquals(container.getImagePullPolicy(), "Never");
}
use of org.eclipse.che.api.workspace.server.model.impl.devfile.ComponentImpl in project devspaces-images by redhat-developer.
the class DockerimageComponentToWorkspaceApplierTest method shouldProvisionServersWithHttpPortIsTheCorrespondingAttrIsMissing.
@Test
public void shouldProvisionServersWithHttpPortIsTheCorrespondingAttrIsMissing() throws Exception {
// given
EndpointImpl endpoint = new EndpointImpl("jdk-ls", 4923, emptyMap());
ComponentImpl dockerimageComponent = new ComponentImpl();
dockerimageComponent.setAlias("jdk");
dockerimageComponent.setType(DOCKERIMAGE_COMPONENT_TYPE);
dockerimageComponent.setImage("eclipse/ubuntu_jdk8:latest");
dockerimageComponent.setMemoryLimit("1G");
dockerimageComponent.setEndpoints(singletonList(endpoint));
// when
dockerimageComponentApplier.apply(workspaceConfig, dockerimageComponent, null);
// then
verify(k8sEnvProvisioner).provision(eq(workspaceConfig), eq(KubernetesEnvironment.TYPE), objectsCaptor.capture(), machinesCaptor.capture());
MachineConfigImpl machineConfig = machinesCaptor.getValue().get("jdk");
assertNotNull(machineConfig);
assertEquals(machineConfig.getServers().size(), 1);
ServerConfigImpl serverConfig = machineConfig.getServers().get("jdk-ls");
assertEquals(serverConfig.getProtocol(), "http");
}
Aggregations