use of org.eclipse.che.workspace.infrastructure.kubernetes.environment.KubernetesEnvironment in project devspaces-images by redhat-developer.
the class KubernetesPreviewUrlCommandProvisionerTest method shouldDoNothingWhenCantFindIngressForPreviewUrl.
@Test
public void shouldDoNothingWhenCantFindIngressForPreviewUrl() throws InfrastructureException {
int port = 8080;
List<CommandImpl> commands = Collections.singletonList(new CommandImpl("a", "a", "a", new PreviewUrlImpl(port, null), Collections.emptyMap()));
KubernetesEnvironment env = KubernetesEnvironment.builder().setCommands(new ArrayList<>(commands)).build();
Mockito.when(mockNamespace.services()).thenReturn(mockServices);
Service service = new Service();
ServiceSpec spec = new ServiceSpec();
spec.setPorts(Collections.singletonList(new ServicePort(null, "a", null, port, "TCP", new IntOrString(port))));
service.setSpec(spec);
Mockito.when(mockServices.get()).thenReturn(Collections.singletonList(service));
Mockito.when(mockNamespace.ingresses()).thenReturn(mockIngresses);
Mockito.when(mockIngresses.get()).thenReturn(Collections.emptyList());
previewUrlCommandProvisioner.provision(env, mockNamespace);
assertTrue(commands.containsAll(env.getCommands()));
assertTrue(env.getCommands().containsAll(commands));
assertEquals(env.getWarnings().get(0).getCode(), Warnings.NOT_ABLE_TO_PROVISION_OBJECTS_FOR_PREVIEW_URL);
}
use of org.eclipse.che.workspace.infrastructure.kubernetes.environment.KubernetesEnvironment in project devspaces-images by redhat-developer.
the class KubernetesPreviewUrlCommandProvisionerTest method shouldUpdateCommandWhenServiceAndIngressFound.
@Test
public void shouldUpdateCommandWhenServiceAndIngressFound() throws InfrastructureException {
final int PORT = 8080;
final String SERVICE_PORT_NAME = "service-" + PORT;
List<CommandImpl> commands = Collections.singletonList(new CommandImpl("a", "a", "a", new PreviewUrlImpl(PORT, null), Collections.emptyMap()));
KubernetesEnvironment env = KubernetesEnvironment.builder().setCommands(new ArrayList<>(commands)).build();
Mockito.when(mockNamespace.services()).thenReturn(mockServices);
Service service = new Service();
ObjectMeta metadata = new ObjectMeta();
metadata.setName("servicename");
service.setMetadata(metadata);
ServiceSpec spec = new ServiceSpec();
spec.setPorts(Collections.singletonList(new ServicePort(null, SERVICE_PORT_NAME, null, PORT, "TCP", new IntOrString(PORT))));
service.setSpec(spec);
Mockito.when(mockServices.get()).thenReturn(Collections.singletonList(service));
Ingress ingress = new Ingress();
IngressSpec ingressSpec = new IngressSpec();
IngressRule rule = new IngressRule("testhost", new HTTPIngressRuleValue(Collections.singletonList(new HTTPIngressPath(new IngressBackend(null, new IngressServiceBackend("servicename", new ServiceBackendPort(SERVICE_PORT_NAME, PORT))), null, null))));
ingressSpec.setRules(Collections.singletonList(rule));
ingress.setSpec(ingressSpec);
Mockito.when(mockNamespace.ingresses()).thenReturn(mockIngresses);
Mockito.when(mockIngresses.get()).thenReturn(Collections.singletonList(ingress));
previewUrlCommandProvisioner.provision(env, mockNamespace);
assertTrue(env.getCommands().get(0).getAttributes().containsKey("previewUrl"));
assertEquals(env.getCommands().get(0).getAttributes().get("previewUrl"), "testhost");
assertTrue(env.getWarnings().isEmpty());
}
use of org.eclipse.che.workspace.infrastructure.kubernetes.environment.KubernetesEnvironment in project devspaces-images by redhat-developer.
the class KubernetesPreviewUrlCommandProvisionerTest method shouldDoNothingWhenCantFindServiceForPreviewurl.
@Test
public void shouldDoNothingWhenCantFindServiceForPreviewurl() throws InfrastructureException {
List<CommandImpl> commands = Collections.singletonList(new CommandImpl("a", "a", "a", new PreviewUrlImpl(8080, null), Collections.emptyMap()));
KubernetesEnvironment env = KubernetesEnvironment.builder().setCommands(new ArrayList<>(commands)).build();
Mockito.when(mockNamespace.ingresses()).thenReturn(mockIngresses);
Mockito.when(mockNamespace.services()).thenReturn(mockServices);
Mockito.when(mockServices.get()).thenReturn(Collections.emptyList());
previewUrlCommandProvisioner.provision(env, mockNamespace);
assertTrue(commands.containsAll(env.getCommands()));
assertTrue(env.getCommands().containsAll(commands));
assertEquals(env.getWarnings().get(0).getCode(), Warnings.NOT_ABLE_TO_PROVISION_OBJECTS_FOR_PREVIEW_URL);
}
use of org.eclipse.che.workspace.infrastructure.kubernetes.environment.KubernetesEnvironment in project devspaces-images by redhat-developer.
the class ProxySettingsProvisionerTest method shouldApplyProxySettingsToAllContainers.
@Test
public void shouldApplyProxySettingsToAllContainers() throws Exception {
Map<String, Pod> pods = new HashMap<>();
Pod pod1 = pods.put("pod1", buildPod("pod1", buildContainers(2)));
pods.put("pod2", buildPod("pod2", buildContainers(3)));
KubernetesEnvironment k8sEnv = KubernetesEnvironment.builder().setPods(pods).build();
provisioner.provision(k8sEnv, runtimeId);
assertTrue(k8sEnv.getPodsData().values().stream().flatMap(pod -> pod.getSpec().getContainers().stream()).allMatch(container -> container.getEnv().contains(new EnvVar(HTTP_PROXY, HTTP_PROXY_VALUE, null)) && container.getEnv().contains(new EnvVar(HTTPS_PROXY, HTTPS_PROXY_VALUE, null)) && container.getEnv().contains(new EnvVar(NO_PROXY, NO_PROXY_VALUE, null))));
}
use of org.eclipse.che.workspace.infrastructure.kubernetes.environment.KubernetesEnvironment in project devspaces-images by redhat-developer.
the class ProxySettingsProvisionerTest method shouldApplyProxySettingsToInitContainers.
@Test
public void shouldApplyProxySettingsToInitContainers() throws Exception {
Map<String, Pod> pods = new HashMap<>();
Pod pod1 = buildPod("pod1", buildContainers(3));
pod1.getSpec().setInitContainers(Arrays.asList(buildContainers(2)));
pods.put("pod1", pod1);
KubernetesEnvironment k8sEnv = KubernetesEnvironment.builder().setPods(pods).build();
provisioner.provision(k8sEnv, runtimeId);
assertTrue(k8sEnv.getPodsData().values().stream().flatMap(pod -> Stream.concat(pod.getSpec().getContainers().stream(), pod.getSpec().getInitContainers().stream())).allMatch(container -> container.getEnv().contains(new EnvVar(HTTP_PROXY, HTTP_PROXY_VALUE, null)) && container.getEnv().contains(new EnvVar(HTTPS_PROXY, HTTPS_PROXY_VALUE, null)) && container.getEnv().contains(new EnvVar(NO_PROXY, NO_PROXY_VALUE, null))));
}
Aggregations