use of org.eclipse.che.workspace.infrastructure.kubernetes.environment.KubernetesEnvironment in project che-server by eclipse-che.
the class OpenShiftEnvironmentFactoryTest method shouldMergeDeploymentAndPodIntoOneDeployment.
@Test
public void shouldMergeDeploymentAndPodIntoOneDeployment() throws Exception {
// given
PodTemplateSpec podTemplate = new PodTemplateSpecBuilder().withNewMetadata().withName("deployment-pod").endMetadata().withNewSpec().endSpec().build();
Deployment deployment = new DeploymentBuilder().withNewMetadata().withName("deployment-test").endMetadata().withNewSpec().withTemplate(podTemplate).endSpec().build();
Pod pod = new PodBuilder().withNewMetadata().withName("bare-pod").endMetadata().withNewSpec().endSpec().build();
when(k8sRecipeParser.parse(any(InternalRecipe.class))).thenReturn(asList(deployment, pod));
Deployment merged = createEmptyDeployment("merged");
when(podMerger.merge(any())).thenReturn(merged);
// when
final KubernetesEnvironment k8sEnv = osEnvFactory.doCreate(internalRecipe, emptyMap(), emptyList());
// then
verify(podMerger).merge(asList(new PodData(pod), new PodData(deployment)));
assertEquals(k8sEnv.getPodsData().size(), 1);
assertTrue(k8sEnv.getPodsCopy().isEmpty());
assertEquals(k8sEnv.getDeploymentsCopy().size(), 1);
assertEquals(k8sEnv.getDeploymentsCopy().get("merged"), merged);
}
use of org.eclipse.che.workspace.infrastructure.kubernetes.environment.KubernetesEnvironment in project che-server by eclipse-che.
the class OpenShiftEnvironmentFactoryTest method shouldReconfigureServiceToMatchMergedDeployment.
@Test
public void shouldReconfigureServiceToMatchMergedDeployment() throws Exception {
// given
Pod pod1 = new PodBuilder().withNewMetadata().withName("bare-pod1").withLabels(ImmutableMap.of("name", "pod1")).endMetadata().withNewSpec().endSpec().build();
Pod pod2 = new PodBuilder().withNewMetadata().withName("bare-pod2").withLabels(ImmutableMap.of("name", "pod2")).endMetadata().withNewSpec().endSpec().build();
Service service1 = new ServiceBuilder().withNewMetadata().withName("pod1-service").endMetadata().withNewSpec().withSelector(ImmutableMap.of("name", "pod1")).endSpec().build();
Service service2 = new ServiceBuilder().withNewMetadata().withName("pod2-service").endMetadata().withNewSpec().withSelector(ImmutableMap.of("name", "pod2")).endSpec().build();
when(k8sRecipeParser.parse(any(InternalRecipe.class))).thenReturn(asList(pod1, pod2, service1, service2));
Deployment merged = createEmptyDeployment("merged");
when(podMerger.merge(any())).thenReturn(merged);
// when
final KubernetesEnvironment k8sEnv = osEnvFactory.doCreate(internalRecipe, emptyMap(), emptyList());
// then
verify(podMerger).merge(asList(new PodData(pod1), new PodData(pod2)));
PodData mergedPodData = k8sEnv.getPodsData().get("merged");
assertEquals(mergedPodData.getMetadata().getLabels().get(DEPLOYMENT_NAME_LABEL), "merged");
assertTrue(k8sEnv.getServices().values().stream().allMatch(s -> ImmutableMap.of(DEPLOYMENT_NAME_LABEL, "merged").equals(s.getSpec().getSelector())));
}
use of org.eclipse.che.workspace.infrastructure.kubernetes.environment.KubernetesEnvironment in project devspaces-images by redhat-developer.
the class KubernetesServerExposerTest method assertThatSecureServerIsExposed.
@SuppressWarnings("SameParameterValue")
private void assertThatSecureServerIsExposed(String machineName, String portProtocol, Integer port, String serverName, ServerConfig serverConfig) throws Exception {
// then
assertThatContainerPortIsExposed(portProtocol, port);
// ensure that service is created
Service service = findContainerRelatedService();
assertNotNull(service);
// ensure that no service port is exposed
assertTrue(service.getSpec().getPorts().stream().noneMatch(p -> p.getTargetPort().getIntVal().equals(port)));
ServicePort servicePort = new ServicePortBuilder().withName("server-" + port).withPort(port).withProtocol(portProtocol.toUpperCase()).withNewTargetPort(port).build();
verify(secureServerExposer).expose(eq(kubernetesEnvironment), any(), eq(machineName), // no service exists for the backed server
isNull(), // a non-unique server
isNull(), eq(servicePort), eq(ImmutableMap.of(serverName, serverConfig)));
}
use of org.eclipse.che.workspace.infrastructure.kubernetes.environment.KubernetesEnvironment in project devspaces-images by redhat-developer.
the class PerWorkspacePVCStrategyTest method shouldPreparePerWorkspacePVCWithSubPathsWhenWaitBoundIsDisabled.
@Test
public void shouldPreparePerWorkspacePVCWithSubPathsWhenWaitBoundIsDisabled() throws Exception {
// given
strategy = new PerWorkspacePVCStrategy(PVC_NAME_PREFIX, PVC_QUANTITY, PVC_ACCESS_MODE, true, PVC_STORAGE_CLASS_NAME, false, pvcSubPathHelper, factory, ephemeralWorkspaceAdapter, volumeConverter, podsVolumes, subpathPrefixes, workspaceManager);
final PersistentVolumeClaim pvc = newPVC(PVC_NAME_PREFIX + "-" + WORKSPACE_ID);
String perWorkspacePVCName = pvc.getMetadata().getName();
KubernetesEnvironment k8sEnv = KubernetesEnvironment.builder().build();
k8sEnv.getPersistentVolumeClaims().put(perWorkspacePVCName, pvc);
String[] subPaths = { "/projects", "/plugins" };
pvc.getAdditionalProperties().put(format(SUBPATHS_PROPERTY_FMT, WORKSPACE_ID), subPaths);
// when
strategy.prepare(k8sEnv, IDENTITY, 100, emptyMap());
// then
verify(pvcs).get();
verify(pvcs).create(pvc);
verify(pvcs, never()).waitBound(anyString(), anyLong());
verify(pvcSubPathHelper).createDirs(IDENTITY, WORKSPACE_ID, perWorkspacePVCName, emptyMap(), subPaths);
}
use of org.eclipse.che.workspace.infrastructure.kubernetes.environment.KubernetesEnvironment in project devspaces-images by redhat-developer.
the class KubernetesPreviewUrlCommandProvisionerTest method shouldDoNothingWhenCommandsWithoutPreviewUrlDefined.
@Test
public void shouldDoNothingWhenCommandsWithoutPreviewUrlDefined() throws InfrastructureException {
List<CommandImpl> commands = Arrays.asList(new CommandImpl("a", "a", "a"), new CommandImpl("b", "b", "b"));
KubernetesEnvironment env = KubernetesEnvironment.builder().setCommands(new ArrayList<>(commands)).build();
Mockito.when(mockNamespace.ingresses()).thenReturn(mockIngresses);
Mockito.when(mockNamespace.services()).thenReturn(mockServices);
previewUrlCommandProvisioner.provision(env, mockNamespace);
assertTrue(commands.containsAll(env.getCommands()));
assertTrue(env.getCommands().containsAll(commands));
assertTrue(env.getWarnings().isEmpty());
}
Aggregations